Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clangd not found in coc-clangd but found in $PATH #32

Closed
karb94 opened this issue Apr 23, 2020 · 8 comments
Closed

Clangd not found in coc-clangd but found in $PATH #32

karb94 opened this issue Apr 23, 2020 · 8 comments

Comments

@karb94
Copy link

karb94 commented Apr 23, 2020

Coc-clangd doesn't detect my clangd binary installed with homebrew at /usr/local/Cellar/llvm/10.0.0_3/bin/clangd that I symlinked to ~/.local/bin/clangd and I added ~/.local/bin/ to my $PATH. I can run clangd from inside neovim as :!clangd without a problem but coc-clangd can't detect it without hardcoding the path in coc-settings.json with "clangd.path": "/usr/local/opt/llvm/10.0.0_3/bin/clangd". If I symlink the binary to /usr/local/bin instead it just works.

I would like to avoid hardcoding the path to coc-settings.json since it wouldn't be portable to my Linux computer. So my question is: where does coc-clangd search for clangd and why is it not using my $PATH?

@fannheyward
Copy link
Member

What's the output which clangd?

@karb94
Copy link
Author

karb94 commented Apr 23, 2020

So which clangd doesn't output anything which I find strange. Could this be related? I am definitely accessing clangd through the symlink at ~/.local/bin/clangd because when I change its name I get a No such file or directory.

@fannheyward
Copy link
Member

which clangd will find clangd from your $PATH, no output means we can't find it from $PATH. How do you add ~/.local/bin/ to your $PATH?

@karb94
Copy link
Author

karb94 commented Apr 23, 2020

echo $PATH contains ~/.local/bin/. I added it with [[ ":$PATH:" != *":~/.local/bin/:"* ]] && PATH="~/.local/bin/:${PATH}" in my .bashrc.

When I run ~/.local/bin/clangd it works as normal. Does which work with symlinks? I am very confused... Thank you for your help

@fannheyward
Copy link
Member

fannheyward commented Apr 23, 2020

What's the output do you run clangd directly? Without ~/.local/bin/.

@karb94
Copy link
Author

karb94 commented Apr 23, 2020

Maybe this series of commands will be of help. This was done in a fresh new terminal.

$ hash
hash: hash table empty
$ type clangd
clangd is /Users/<MY_USERNAME>/.local/bin/clangd
$ which clangd
$ clangd
clangd is a language server that provides IDE-like features to editors.

It should be used via an editor plugin rather than invoked directly. For more information, see:
	https://clang.llvm.org/extra/clangd/
	https://microsoft.github.io/language-server-protocol/

clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment variable.

I[12:13:51.794] clangd version 10.0.0 
I[12:13:51.794] PID: 37985
I[12:13:51.795] Working directory: /Users/<MY_USERNAME>
I[12:13:51.795] argv[0]: clangd
I[12:13:51.795] Starting LSP over stdin/stdout
**I pressed Ctrl-C to kill it**
^CE[12:13:54.356] Transport error: Got signal, shutting down
I[12:13:54.356] LSP finished, exiting with status 1
$ type clangd
clangd is hashed (/Users/<MY_USERNAME>/.local/bin/clangd)
$ hash
hits	command
   1	/usr/bin/which
   1	/Users/<MY_USERNAME>/.local/bin/clangd
$ readlink -f /Users/<MY_USERNAME>/.local/bin/clangd
/usr/local/Cellar/llvm/10.0.0_3/bin/clangd

I understand this may not be coc-clangd's problem and I appreciate the help.

@sam-mccall
Copy link
Member

You've put "~/.local/bin" on your path instead of "/Users/<MY_USERNAME>/.local/bin".
This is nonstandard - PATH should contain real paths. Bash supports it as an extension (on my system, when invoked as bash but not when invoked as sh) but not all tools do. In particular the npm-which library used by coc to find the binary doesn't support this.

You can fix this by unquoting the ~ so the shell will expand it:

 [[ ":$PATH:" != *:~/.local/bin/:* ]] && PATH=~/.local/bin/:"${PATH}"

@renyddd
Copy link

renyddd commented Sep 21, 2020

ln -s /usr/local/bin/clangd /$HOME/.config/coc/extensions/coc-clangd-data/install/10.0.0/clangd_10.0.0/bin/clangd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants