1

I use nvim-cmp. I have installed the clangd with Mason, and configured it with `lsp-config.nvim as:

local capabilities = require('cmp_nvim_lsp').default_capabilities()

lspconfig.clangd.setup {
    capabilities = capabilities,
    cmd = {vim.fn.stdpath("data") .. "/mason/bin/clangd"},
    filetypes = { "c", "cpp", "h", "hpp", "objc", "objcpp", "cuda", "proto" }
}

When I open Qt program, I get errors that there are no Qt modules found:

enter image description here

This may be happening because of Qt location which is at ~/Qt/. Its contents are:

➜  ~ ls ~/Qt
 5.15.2
 6.6.0
 Docs
 Examples
 InstallationLog.txt
 Licenses
 MaintenanceTool.app
 MaintenanceTool.dat
 MaintenanceTool.ini
'Qt Creator.app'
 QtDesignStudio
 README.txt
 Tools
 build-charts-Desktop_arm_darwin_generic_mach_o_64bit-Debug
 build-login_page-Qt_6_5_2_6_5_2-Debug
 build-msgtest-Qt_6_5_2_6_5_2-Debug
 components.xml
 dist
 installerResources
 licenseInfo.txt
 network.xml

I am on arm macOS and installed Qt with Qt maintance tool (brew install is broken). How to make clangd work with Qt in nvim? My current Neovim config is here.

3
  • 1
    Do you have a compile_commands.json file in the root of your project that describes how each compilation unit should be compiled (in particular setting the /I flag for each)? Jan 24 at 18:53
  • 1
    @VivianDeSmedt No, i have no compile_commands.json file. Jan 24 at 20:30
  • 1
    Edits explaining how an answer worked are not appropriate for a question. Feel free to suggest edits on answers or to post your own answer.
    – D. Ben Knoble
    Jan 25 at 16:01

1 Answer 1

1

The clangd LSP server use the compile_commands.json to know what are the compile flags used for each compilation units.

compile_commands.json:

[
  {
    "directory": path/to/project/root,
    "command": "/usr/bin/clang++ -x c++ main.cpp -Ipath/to/QT",
    "file": "main.cpp"
  },
]

The compile_commands.json can be generated from the compilation command using Bear.

6
  • 1
    It seems that Bear is a tool that generate the compile_commands.json from the build command (On Windows I'm using a Visual Studio plugin to do the same). Jan 24 at 20:03
  • 1
    If the solution address your problem maybe could you accept the solution using the v button next to the arrow voting buttons. It allow the question to rest :-) Jan 24 at 20:04
  • 1
    Thank You for details! Jan 24 at 20:31
  • 1
    Thanks for the feedback :-) I'm glad we could solve your problem ;-) Jan 24 at 20:40
  • 1
    I updated the post, and found out amazing thing about bear and cmake! Hope You will find it interesting. Jan 24 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.