C++ Autocompletion does not show full list

Hi.

I am using neovim for C++, Cmake, and some Lua files. But in C++, some functions does not show in the autocomplete list, at least I press Ctrl + Space.

Is there a way to solve this?

Maybe you have not specify a include directory.

Thanks for replying, but everything is in order.

This “bug” persist.

Are you using clangd? or ccls?
Do you the compile_commands.json file in the root directory of the project?

nvim_lsp.clangd.setup{
on_attach = on_attach,
cmd = {
“clangd”,
“–background-index”,
“–pch-storage=memory”,
“–clang-tidy”,
“–suggest-missing-includes”,
“–all-scopes-completion”,
“–log=verbose”,
“–pretty”,
“–header-insertion=never”
},
filetypes = {“c”, “cpp”, “objc”, “objcpp”},
– root_dir = utils.root_pattern(“compile_commands.json”, “compile_flags.txt”, “.git”)
init_option = { fallbackFlags = { “-std=c++2a” } }
}

Take some time to look at the lsp.log. The log gets pretty massive so I recommend deleting the log file and then restarting nvim and opening a single file that you know has the issue.
In the log will be the exact command clangd uses to compile the file. Inspect it carefully. It might be missing an -I flag to a path where a file exists that defines the function you’re missing. Or maybe some other compilation flag is wrong. In any case you may need to add/remove flags to a .clangd file. The clangd documentation explains the format of the .clangd file

I’ve checked the lsp.log and have many errors, but with VS Code I have the same config, with Code I do not have this problem.

Those errors on the lsp.log are worth looking into, it could be that clangd is trying to tell you what’s wrong, which will be helpful to know, in order to fix it.

Good luck. I can say that clangd with neovim works very well with c++ (both gcc and clang++, and even with complex cases like cross-compilation, multiple target architectures, etc). I use it constantly, daily, and it’s excellent. Of course, it took a while to fine-tune my settings, and you should expect to spend time doing the same. Keep in mind that you have to configure your auto-completion settings separately from the nvim-lsp settings (you probably are using nvim-cmp?).

For me, when I have to use VS Code with clangd (or built-in Intellisense), many things don’t work the way I want them to. I get all kinds of false errors and red-squiggles in VS Code, and it can’t find certain files and sometimes GoTo Definitions don’t work. I’m sure if I tweaked my VS code settings long enough, I could get things to work the way it works on neovim. It’s probably just a matter of you figuring out the exact settings to use for nvim+clangd, which is not necessarily the same as for VS Code + clangd.

Thank you.
Could you share your config in nvim. The fun thing is, in NeoVim and in Emacs I have the same “problem”, but with VS Code, Clion, QtCreator, Eclipse works fine.
This is my config in VS Code with no problems:

// C++ //
// /// //
//
“C_Cpp.intelliSenseEngine”: “Disabled”,
“C_Cpp.autocomplete”: “Disabled”,
“C_Cpp.errorSquiggles”: “Disabled”,
// “C_Cpp.intelliSenseEngine”: “Default”,
// “C_Cpp.autocomplete”: “Default”,
// “C_Cpp.errorSquiggles”: “Enabled”,
//
// // Clangd
//
“clangd.arguments”: [
“–all-scopes-completion”,
“–clang-tidy”,
“–completion-style=detailed”,
“-log=verbose”,
“-pretty”,
“–cross-file-rename”,
“–header-insertion=never”,
“–background-index”,
],
“clangd.onConfigChanged”: “restart”,
“clangd.restartAfterCrash”: true,
“clangd.semanticHighlighting”: true,
“clangd.serverCompletionRanking”: true,

With nvim I have this:

nvim_lsp.clangd.setup{
on_attach = on_attach,
cmd = {
“clangd”
– “clangd”,
– “–background-index”,
– – “–pch-storage=memory”,
– “–clang-tidy”,
– “–completion-style=detailed”,
– – “–suggest-missing-includes”,
– “–all-scopes-completion”,
– “–log=verbose”,
– “–pretty”,
– “–header-insertion=never”
},
filetypes = {“c”, “cpp”, “objc”, “objcpp”},
– root_dir = utils.root_pattern(“compile_commands.json”, “compile_flags.txt”, “.git”)
– init_option = { fallbackFlags = { “-std=c++2a” } }
}

Also I have installed “Navigator”, in the config of servers I have:

  clangd = {
		on_attach = function(client, bufnr) end,
		cmd = {
			"clangd"
			-- "clangd",
			-- "--background-index",
			-- "--pch-storage=memory",
			-- "--clang-tidy",
			-- "--suggest-missing-includes",
			-- "--all-scopes-completion",
			-- "--log=verbose",
			-- "--pretty",
			-- "--header-insertion=never"
		},
		filetypes = {"c", "cpp", "objc", "objcpp"},
		-- root_dir = utils.root_pattern("compile_commands.json", "compile_flags.txt", ".git")
		-- init_option = { fallbackFlags = {  "-std=c++2a"  } }
	},  -- clang

Here’s my configs for nvim:

I still think you should take the errors in the log file seriously and look carefully at them.

Sorry for the late answer.
Yesterday I was researching about this, and the continues “error” that shows in lsp.log is: rpc with clangd.
Besides that, there are no errors.
Also, in Emacs, I have the same “issue”. If I type: SDL_GetT, does not shows SDL_GetTicks(). I need to press: Ctrl + Spacebar, then show up.
The only Editors that, shows the complete list are VSCode and Clion.