Wondering if anyone else has got this setup to work with c/c++.
I have nvim installed on WSL2 (ubuntu 20.04) and use it to edit my c++ files, but for compilation/debugging I use msvc2019 with clang10.
The windowsclang spits out a compile_commands.json, but it wont be understood by the linuxclang language server being used by nvim.
what are my options to address this? is it possible to point nvim to the windowsclang language server?
vscode has a nvim plugin and you can tell it to use your wsl2nvim. having tried it out, the autocomplete and symbol lookup seem to work flawlessly (and makes me cry thinking about what my experience COULD be) (atm, i use ctags/cscope and they are far from flawless). how can i emulate whatever its doing in my nvimwsl2 setup?
going a full windows route is the last option i would consider since windows and its various terminals have always been awful in my experience. I’ve also never been able to compile nvimmaster on windows.
You should use your build system to generate the compile_commands.json. I had only bad experience on not doing so. For cmake I do use use { 'cdelledonne/vim-cmake', requires = { 'antoinemadec/FixCursorHold.nvim' } } --console window: cg,cb,ci,cq,<C-C>, xor <l>cmg/cmb.
The alternative is to emulate the build system by figuring out all the paths yourself and add them to the compile_commands.json.
use your build system to generate the compile_commands.json
Sry if it wasn’t clear. my project is in fact a cmake project. msvc2019 uses cmake if you have it setup.
The core issue is my nvim is in linux land via WLS2 but the compile_commands.json is generated via a windows version of clang in msvc.
unless you mean using the linuxmake system to just generate the compile_commands.json for the repo that sits on the /mnt/c/ side. I wanted to try that but was unsure how sustainable that is from a workflow standpoint. double compiling everytime might get old fast. there’s probably a slick way to do a post build thing that calls a script to do the linux compile that trys to only generate a compile_commands.json so that it’s fast and not a noticable overhead (if that’s possible, i dont know cmake enough to know).
msvc has a cross compile feature but im not sure if it uses wsllinux distro to build it, i could try that too i guess.
the other thing i was thinking was to point the nvim linux language server for clang at the windows clang, but i doubt it works even if you (could?) do that?
i managed to build the /mnt/c/ windows repo with linux using clang10. so now i have a compile_commands.json that my linux clangd server can understand.
it looks like my diagnostics went away but it seems most features arent supported or something else is wrong. I can’t jump to definition or autocomplete. for example, if i do this->m_ it will just be a bunch of matches in the file and not any actual members informed by the server.
:lua print(vim.inspect(vim.lsp.buf_get_clients())) does return a big json for clangd so its showing some of life.
In the lspconfig repo it mentions checking the logs so when i call this for the buffer im in (Renderer.cpp) :lua vim.cmd('e'..vim.lsp.get_log_path())
There are some interesting errors in the log:
/usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:458 Updating file /mnt/c/Users/lol/clones/GraphicsSelfStudy/src/Renderer.cpp with command \n[/mnt/c/Users/lol/clones/GraphicsSelfStudy/buildTest]\n/usr/bin/clang -I/mnt/c/Users/lol/clones/GraphicsSelfStudy/glad -I/mnt/c/Users/lol/clones/GraphicsSelfStudy/glfw -I/mnt/c/Users/lol/clones/GraphicsSelfStudy/glm -I/mnt/c/Users/lol/clones/GraphicsSelfStudy/buildTest/dependencies/glad/include -I/mnt/c/Users/lol/clones/GraphicsSelfStudy/buildTest/generated -I/mnt/c/Users/lol/clones/GraphicsSelfStudy/dependencies/glad -I/mnt/c/Users/lol/clones/GraphicsSelfStudy/dependencies/glfw -I/mnt/c/Users/lol/clones/GraphicsSelfStudy/dependencies/glm -I/mnt/c/Users/lol/clones/GraphicsSelfStudy/dependencies/imgui-files -I/mnt/c/Users/lol/clones/GraphicsSelfStudy/dependencies/stb -I/mnt/c/Users/lol/clones/GraphicsSelfStudy/dependencies/soil2 -I/mnt/c/Users/lol/clones/GraphicsSelfStudy/dependencies/glfw/include -I/mnt/c/Users/lol/clones/GraphicsSelfStudy/dependencies/glm/glm/.. -I/mnt/c/Users/lol/clones/GraphicsSelfStudy/dependencies/soil2/src/SOIL2 -isystem /mnt/c/Users/lol/clones/GraphicsSelfStudy/dependencies -isystem /mnt/c/Users/lol/clones/GraphicsSelfStudy/dependencies/assimp -Wno-error -O3 -DNDEBUG -std=gnu++2a -Winvalid-pch -Xclang -include-pch -Xclang /mnt/c/Users/lol/clones/GraphicsSelfStudy/buildTest/CMakeFiles/GraphicsSelfStudy.dir/cmake_pch.hxx.pch -Xclang -include -Xclang /mnt/c/Users/lol/clones/GraphicsSelfStudy/buildTest/CMakeFiles/GraphicsSelfStudy.dir/cmake_pch.hxx -o CMakeFiles/GraphicsSelfStudy.dir/src/Renderer.cpp.o -c /mnt/c/Users/lol/clones/GraphicsSelfStudy/src/Renderer.cpp -fsyntax-only -resource-dir=/usr/lib/llvm-10/lib/clang/10.0.0\n"
/usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:458 Could not build a preamble for file /mnt/c/Users/lol/clones/GraphicsSelfStudy/src/Renderer.cpp\n"
/usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:458 BeginSourceFile() failed when building AST for /mnt/c/Users/lol/clones/GraphicsSelfStudy/src/Renderer.cpp\n"
Not sure what the next step would be. on the linux side i was able to compile but not link. not sure if i need to clean that pipe first before i move onto fixing these nvim lsp errors?
doing this the log spits out the fact that when its trying to build the “preamble” it cannot load the include files, at least that’s how i interpret these lines (when it mentions “failed to load shard”)