clangd / coc-clangd

clangd extension for coc.nvim
Apache License 2.0
753 stars 34 forks source link

how to set coc config clangd.path to wsl clangd in windows , because win version clangd.exe always crash #484

Open WillDawnlll opened 2 years ago

WillDawnlll commented 2 years ago

i test these configs , and all not work : 1 . set "clangd.path" to "wsl clangd" ,

  1. set "clangd.path "\wsl$\Debian\usr\local\bin\calngd" ,
  2. or "d:/tool/wsl_clangd.bat" (just "wsl clangd")

i not familiar with js , but simply check the code , may be the reason is clangd execute bin path append ".exe" in windows ?

sim590 commented 2 years ago

I would like to do something similar. Except that my approach would be to make clangd.exe work since the code base I'm compiling has some windows exclusive instructions, therefore I need Windows' clangd to work. I can't use WSL's.

I get this log when I try to open some C++ file:

CocInfo output ``` ## versions vim version: VIM - Vi IMproved 8.2 8024793 node version: v16.15.1 coc.nvim version: 0.0.81-093e4300 2022-06-04 17:10:20 -0700 coc.nvim directory: /home/simon/.vim/plugged/coc.nvim term: dumb platform: linux ## Log of coc.nvim 2022-07-29T12:22:20.762 INFO (pid:4080) [configurations] - Add folder configuration from cwd: /home/simon/some/project/path/.vim/coc-settings.json 2022-07-29T12:22:20.763 INFO (pid:4080) [configurations] - Change folder configuration from cwd to: /home/simon/some/project/path/.vim/coc-settings.json 2022-07-29T12:22:20.895 INFO (pid:4080) [services] - registered service "languageserver.clangd" 2022-07-29T12:22:20.895 INFO (pid:4080) [services] - registered service "languageserver.haskell" 2022-07-29T12:22:20.896 INFO (pid:4080) [plugin] - coc.nvim initialized with node: v16.15.1 after 38ms 2022-07-29T12:22:24.947 INFO (pid:4080) [services] - clangd state change: stopped => starting 2022-07-29T12:22:25.013 INFO (pid:4080) [services] - clangd state change: starting => stopped 2022-07-29T12:22:25.021 ERROR (pid:4080) [services] - Server languageserver.clangd failed to start: Launching server "languageserver.clangd" using command /mnt/c/Program\ Files/LLVM/bin/clang.exe failed. 2022-07-29T12:22:25.022 ERROR (pid:4080) [language-client-index] - Error: spawn /mnt/c/Program\ Files/LLVM/bin/clang.exe ENOENT at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19) at onErrorNT (node:internal/child_process:478:16) at processTicksAndRejections (node:internal/process/task_queues:83:21) { errno: -2, code: 'ENOENT', syscall: 'spawn /mnt/c/Program\\ Files/LLVM/bin/clang.exe', path: '/mnt/c/Program\\ Files/LLVM/bin/clang.exe', spawnargs: [] } 2022-07-29T12:22:25.442 INFO (pid:4080) [attach] - receive notification: highlight [] 2022-07-29T12:22:33.732 INFO (pid:4080) [attach] - receive notification: highlight [] 2022-07-29T12:22:35.658 INFO (pid:4080) [attach] - receive notification: highlight [] 2022-07-29T12:22:41.064 INFO (pid:4080) [attach] - Request action: fillDiagnostics [ 1 ] 2022-07-29T12:22:41.385 INFO (pid:4080) [attach] - receive notification: highlight [] 2022-07-29T12:22:42.572 INFO (pid:4080) [attach] - receive notification: highlight [] 2022-07-29T12:22:42.939 INFO (pid:4080) [attach] - receive notification: highlight [] 2022-07-29T12:22:49.109 INFO (pid:4080) [attach] - receive notification: showInfo [] ```

with the following config:

CocLocalConfig ``` { "languageserver": { "clangd": { "command": "/mnt/c/Program\\ Files/LLVM/bin/clang.exe", "rootPatterns": ["compile_flags.txt", "compile_commands.json"], "filetypes": ["c", "cc", "cpp", "c++", "objc", "objcpp"] } } } ```
sim590 commented 2 years ago

I've just realized that my config did not make use of coc-clangd. However, I tried:

{
    "clangd": {
        "path": "clangd.exe"
    }
}

but I got the following message:

[coc.nvim] clangd was not found on your PATH. :CocCommand clangd.install will install 14.0.3.

I also tried with:

"path": "/mnt/c/Program\\ Files/LLVM/bin/clang.exe"

and it didn't change anything.

fannheyward commented 2 years ago

Sorry I don't have a Window env to test.

CoreyCole commented 2 years ago

@sim590 if you run nvim server on the wsl, then you can use msys clangd.exe on the windows side

which clangd
/mingw64/bin/clangd

^ On windows powershell shell on Windows Terminal