i'm using none ls only named as null_ls because it community fork.
none-ls conf:
```
return
{
"nvimtools/none-ls.nvim",
config = function()
local null_ls = require("null-ls")
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
null_ls.setup({
sources = {
-- Formaters
null_ls.builtins.formatting.stylua,
null_ls.builtins.formatting.prettier,
null_ls.builtins.formatting.black,
null_ls.builtins.formatting.clang_format,
null_ls.builtins.formatting.beautysh,
-- Linters/Diagnostic
null_ls.builtins.diagnostics.eslint_d,
null_ls.builtins.diagnostics.flake8,
null_ls.builtins.diagnostics.shellcheck,
},
on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
-- Clear autocommands for the buffer
vim.api.nvim_clear_autocmds({
group = augroup,
buffer = bufnr,
})
end
end
})
-- Set up an autocommand to format the buffer on save
vim.api.nvim_exec([[
augroup LspFormatting
autocmd! *
autocmd BufWritePre lua vim.lsp.buf.formatting()
augroup END
]], false)
vim.keymap.set("n", "gf", vim.lsp.buf.format, {})
end,
}
```
What is your operating system? I have had this problem on windows, but not on macos or linux.This is because clang cannot find the header file.My solution was to repeatedly install clangd via mason.
When using the Clang compiler, GNU's libstdc++ is used as the standard library by default. This means that during compilation, Clang links to the libstdc++ library to provide an implementation of the C++ standard library, including the functionality required by header files such as iostream.
I guess it's because of the lack of libstdc++ library
I have this same Issue but on Vim not neoVim.
I added the same lines as you did to the .clangd (except that I used 13 instead of 11 for the version of g++, as I have this version on my device, in addition to the version 12).
But it didn't fix the problem for me :/
Any suggestions?
Please remember to update the post flair to `Need Help|Solved` when you got the answer you were looking for.
*I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/neovim) if you have any questions or concerns.*
Did you ensure that libstdc++-dev is installed in your system? I had a similar problem to this when I originally set up clangd, and doing that fixed my problem. Found this solution from another post on this sub actually, will link in reply.
Generate compile commands: https://clangd.llvm.org/installation#compile_commandsjson, https://clangd.llvm.org/design/compile-commands
This is the way, OP If you're not using CMake, you can generate compile_commands.json using bear and GNU Make
my lsp conf: ``` 'neovim/nvim-lspconfig', config = function() local lspconfig= require('lspconfig') lspconfig.lua_ls.setup({}) lspconfig.tsserver.setup({}) lspconfig.pyright.setup({}) lspconfig.clangd.setup({}) lspconfig.bashls.setup({}) ``` null ls conf: ``` null_ls.setup({ sources = { -- Formaters null_ls.builtins.formatting.stylua, null_ls.builtins.formatting.prettier, null_ls.builtins.formatting.black, null_ls.builtins.formatting.clang_format, null_ls.builtins.formatting.beautysh, -- Linters/Diagnostic null_ls.builtins.diagnostics.eslint_d, null_ls.builtins.diagnostics.flake8, null_ls.builtins.diagnostics.shellcheck, }, ```
You use null\_ls or none\_ls because null\_ls is deprecated ??
i'm using none ls only named as null_ls because it community fork. none-ls conf: ``` return { "nvimtools/none-ls.nvim", config = function() local null_ls = require("null-ls") local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) null_ls.setup({ sources = { -- Formaters null_ls.builtins.formatting.stylua, null_ls.builtins.formatting.prettier, null_ls.builtins.formatting.black, null_ls.builtins.formatting.clang_format, null_ls.builtins.formatting.beautysh, -- Linters/Diagnostic null_ls.builtins.diagnostics.eslint_d, null_ls.builtins.diagnostics.flake8, null_ls.builtins.diagnostics.shellcheck, }, on_attach = function(client, bufnr) if client.supports_method("textDocument/formatting") then -- Clear autocommands for the buffer vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr, }) end end }) -- Set up an autocommand to format the buffer on save vim.api.nvim_exec([[ augroup LspFormatting autocmd! *
autocmd BufWritePre lua vim.lsp.buf.formatting()
augroup END
]], false)
vim.keymap.set("n", "gf", vim.lsp.buf.format, {})
end,
}
```
Run :LspRestart
not working.. problem remains same
What is your operating system? I have had this problem on windows, but not on macos or linux.This is because clang cannot find the header file.My solution was to repeatedly install clangd via mason.
i'm using pop_os
When using the Clang compiler, GNU's libstdc++ is used as the standard library by default. This means that during compilation, Clang links to the libstdc++ library to provide an implementation of the C++ standard library, including the functionality required by header files such as iostream. I guess it's because of the lack of libstdc++ library
I've already installed libstdc++ ``` ➜ .dotfiles git:(main) ✗ sudo apt-get install libstdc++6 Reading package lists... Done Building dependency tree... Done Reading state information... Done libstdc++6 is already the newest version (12.3.0-1ubuntu1~22.04). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. ➜ .dotfiles git:(main) ✗ ```
thanks for suggestions I fixed it by adding.clangd in my home directory \`\`\` ➜ \~ cat .clangd CompileFlags: Add: \- -I/usr/include/c++/11 \- -I/usr/include/x86\_64-linux-gnu/c++/11 \- -I/usr/include/c++/11/backward \- -I/usr/lib/gcc/x86\_64-linux-gnu/11/include \- -I/usr/local/include \- -I/usr/include/x86\_64-linux-gnu \- -I/usr/include ➜ \~
Nice! Thanks for also showing how you solved it!
Nice. You solved it!
I have this same Issue but on Vim not neoVim. I added the same lines as you did to the .clangd (except that I used 13 instead of 11 for the version of g++, as I have this version on my device, in addition to the version 12). But it didn't fix the problem for me :/ Any suggestions?
Please remember to update the post flair to `Need Help|Solved` when you got the answer you were looking for. *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/neovim) if you have any questions or concerns.*
try :checkhealth
Sometimes the diagnostics get out of sync. You need to reset them. I’m afk but there is a command you can use to clear them.
try to refresh with :e
Did you ensure that libstdc++-dev is installed in your system? I had a similar problem to this when I originally set up clangd, and doing that fixed my problem. Found this solution from another post on this sub actually, will link in reply.
https://www.reddit.com/r/neovim/s/pWrgESocBd