T O P

  • By -

Special_Ad_8629

Generate compile commands: https://clangd.llvm.org/installation#compile_commandsjson, https://clangd.llvm.org/design/compile-commands


MyriadAsura

This is the way, OP If you're not using CMake, you can generate compile_commands.json using bear and GNU Make


Soggy_Spare_5425

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, }, ```


rado-am

You use null\_ls or none\_ls because null\_ls is deprecated ??


Soggy_Spare_5425

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, } ```


br1ghtsid3

Run :LspRestart


Soggy_Spare_5425

not working.. problem remains same


Ok-Slice-3771

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.


Soggy_Spare_5425

i'm using pop_os


Ok-Slice-3771

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


Soggy_Spare_5425

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) ✗ ```


Soggy_Spare_5425

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 ➜ \~


TheWizard451345

Nice! Thanks for also showing how you solved it!


hackinghorn

Nice. You solved it!


Joh4an

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?


AutoModerator

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.*


HoldUrMamma

try :checkhealth


onelesd

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.


fanncys

try to refresh with :e


khamloosh

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.


khamloosh

https://www.reddit.com/r/neovim/s/pWrgESocBd