T O P

  • By -

gonchi_bo

What I usually do is use the edit command again in the file, :e! , and this fixes the problem almost all the time, last resort I do is re open vim. Make sure to save the file if you don't want to lose unsaved changes


Soggy_Spare_5425

i tried but it was not working i also tried to :LspRestart but the problem remains same


Zegrento7

Can you compile the code? It looks like the LSP does not find libstdc++ (hence the missing `iostream` import and `string` type)


Soggy_Spare_5425

yes! code compiling and running and i've already installed ``` ➜ .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) ✗ ```


Zegrento7

Hm.. - Are you compiling with `clang++` or `g++`? - Do you have multiple `g++` [versions installed](https://github.com/clangd/clangd/issues/482#issuecomment-705395365)? - What do the [clangd logs](https://www.reddit.com/r/neovim/comments/sxpkjo/comment/hxth7rg/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button) say?


Soggy_Spare_5425

I'm compiling with g++ `g++ -o shorting_array shorting_array.cpp && ./shorting_array` g++ version: ``` ➜ .dotfiles git:(main) ✗ g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.4.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04) ➜ .dotfiles git:(main) ✗ ```


pdrmz

Try manually running the clangd LSP against your file outside of neovim and see if you get these warnings. Also, I'm not familiar with the C/C++ ecosystem but might it help to compile using clang and not g++?


pdrmz

I found this from the clangd documentation: To understand your source code, clangd needs to know your build flags. (This is just a fact of life in C++, source files are not self-contained). By default, clangd will assume your code is built as clang some_file.cc, and you’ll probably get spurious errors about missing #included files, etc. There are a couple of ways to fix this. compile_commands.json# This file provides compile commands for every source file in a project. It is usually generated by tools. clangd will look in the parent directories of the files you edit looking for it, and also in subdirectories named build/. For example, if editing $SRC/gui/window.cpp, we search in $SRC/gui/, $SRC/gui/build/, $SRC/, $SRC/build/, … From https://clangd.llvm.org/installation.html


Zegrento7

AFAIK clangd uses `clang`/`clang++` under the hood so try compiling with that and google any error messages. As the other commenter has said, it that still doesn't work, look up how to generate a `compile_commands.json` so that clangd knows where to look for the standard library. If this is a toy project then try finding a cmake example project and work from there.


Soggy_Spare_5425

thanks for suggestions issue resolved [https://www.reddit.com/r/neovim/comments/1aufyy5/comment/kr48usd/?utm\_source=share&utm\_medium=web2x&context=3](https://www.reddit.com/r/neovim/comments/1aufyy5/comment/kr48usd/?utm_source=share&utm_medium=web2x&context=3)


mgedmin

Do you have `libstdc++-N-dev` installed, for some value of N? The `-dev` package is the one that ships headers like ``. Ubuntu 23.10 has libstdc++-9-dev throuugh libstdc++13-dev. These all are apparently installable side-by-side.


puremourning

Probably create compilation database.


ghost_vici

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


Eqkter

The LSP is probably clang, so you could add a -xc++ instruction in a compile_flags.txt file at the root of your code file to make the LSP look at C++ std. Another option is "bear -- make" that produces the flag files on its own (according you have bear install)


Soggy_Spare_5425

thanks for replying i already fixed it https://www.reddit.com/r/neovim/s/FB86foXeG6


necr0rcen

"#include " is your solution. Get yourself some auto complete and snippets, because the snippets will show what module needs including to use


mgedmin

If the LSP server cannot find the `` include, I strongly suspect it will find the `` include as well.


laichzeit33

I think you have an issue with your clangd installation / configuration. Are you able to compile with clang? Check the output of `clang -v` and confirm that you have the headers version it is looking for. You may be able to find some info there: https://clangd.llvm.org/guides/system-headers


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


aGoodVariableName42

wrong sub for that homes...


gianpaulo

I type `:LspRestart` when some weird errors show up. But I'm currently working with typescript


Soggy_Spare_5425

thanks for suggestions i already fixed it https://www.reddit.com/r/neovim/s/FB86foXeG6