1

I'm using LazyVim as a bootstrap config.

On top of that I have very few changes. However, I'm not able to get lsp working for c++. LSP is working fine because it is working for Lua files. So, that leaves me suspecting my LSP config.

The behavior is that Neovim is using Visual Studio headers when I do go to definition. Whereas the project was compiled using mingw.

My init file:

-- init.lua
-- bootstrap lazy.nvim, LazyVim and your plugins
require("config.lazy")

local nvim_lsp = require('lspconfig')

nvim_lsp.clangd.setup {
    cmd = {'clangd', '--background-index', '--compile-commands-dir', 'D:/systemc/excersies/build'},
    init_options = {
        clangdFileStatus = true,
        clangdSemanticHighlighting = true
    },
    filetypes = {'c', 'cpp', 'cxx', 'cc'},
    root_dir = function() vim.fn.getcwd() end,
    settings = {
        ['clangd'] = {
            ['compilationDatabasePath'] = 'build',
            ['fallbackFlags'] = {'-std=c++17'}
        }
    }
}
Monsieur Merso
  • 1,459
  • 1
  • 15
  • 18
thumala manish
  • 198
  • 1
  • 10

1 Answers1

-1

However, I'm not able to get lsp working for c++.

What exactly do you mean with "(...) not able to get lsp working for c++."? Is there an error message?

I assume, that it works, but not fully, because maybe you cannot make use of goto definition and stuff like that.

Bear

In this case, install bear and run it in your project directory (as the README says):

bear -- make # if you'd simply invoke `make` to build your project

this should create a json file for you and clangd should fully work then.

TornaxO7
  • 1,150
  • 9
  • 24
  • I have a json file in the build fold and I'm specifying the path to the folder in cli args. That being there lsp is picking up definitions from msvc where the project was compiled with mingw. – thumala manish Jun 29 '23 at 13:02
  • May I ask, what you're trying to tell me with you comment? – TornaxO7 Jun 29 '23 at 14:43
  • Hi @Tornax07, I have a c++ project(for which cmake used and compile_commands.json is generated) that uses mingw64. If I open this project and do a "go-to-definition" on "std::cout" clangd should take me to the Mingw headers but it is taking me to MSVC headers. -- Hope this is clear atleast!!! – thumala manish Jun 30 '23 at 10:22