clangd / vscode-clangd

Visual Studio Code extension for clangd
https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd
MIT License
639 stars 113 forks source link

Restarting language server gives ENOENT error #454

Open clavey13 opened 1 year ago

clavey13 commented 1 year ago

I'm working with clangd in VS Code, inside a Docker container. At one point, Intellisense was working, but now is not. I made sure MS C/C++ has been uninstalled. I've attempted restarting the language server, which gives me an ENOENT error on the clangd executable (see below). I've exited and restarted Code several times, as well as the Docker container. I've listed the details below, but am new to Code and clangd; bear with me if there are things I've missed. My project lead is also out of ideas on things to check. I'm sure there's something we're missing, but no idea what. Any help is appreciated.

Thanks, -- Cathy

Linux 5.15.0-58-generic #64~20.04.1-Ubuntu SMP Fri Jan 6 16:42:31 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux Docker version 20.10.17, build 100c701

Version: 1.75.1 Commit: 441438abd1ac652551dbe4d408dfcec8a499b8bf Date: 2023-02-08T21:35:30.018Z Electron: 19.1.9 Chromium: 102.0.5005.194 Node.js: 16.14.2 V8: 10.2.154.23-electron.0 OS: Linux x64 5.15.0-58-generic snap Sandboxed: No

clangd v0.1.23

Trying to restart the language server gives the following, with uncaught errors (see image also):

[Error - 5:37:53 PM] Clang Language Server client: couldn't create connection to server.
Launching server using command /home/raptor/.vscode-server/data/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/15.0.6/clangd_15.0.6/bin/clangd failed. Error: spawn /home/raptor/.vscode-server/data/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/15.0.6/clangd_15.0.6/bin/clangd ENOENT

The clangd binary is here:

$ ls -alh /home/raptor/.vscode-server/data/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/15.0.6/clangd_15.0.6/bin/clangd
-rwxr-xr-x 1 raptor raptor 105M Feb 15 10:18 /home/raptor/.vscode-server/data/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/15.0.6/clangd_15.0.6/bin/clangd*

Trying to run clangd on the command line of my container gives the following, so the binary seems to work OK.

$ /home/raptor/.vscode-server/data/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/15.0.6/clangd_15.0.6/bin/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://clangd.llvm.org/
        https://microsoft.github.io/language-server-protocol/

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

I[17:39:05.283] clangd version 15.0.6 (https://github.com/llvm/llvm-project 088f33605d8a61ff519c580a71b1dd57d16a03f8)
I[17:39:05.283] Features: linux+grpc
I[17:39:05.283] PID: 274829
I[17:39:05.283] Working directory: /workspaces/raptor/raptor_plugins
I[17:39:05.283] argv[0]: /home/raptor/.vscode-server/data/User/globalStorage/llvm-vs-code-extensions.vscode-clangd/install/15.0.6/clangd_15.0.6/bin/clangd
I[17:39:05.283] Starting LSP over stdin/stdout
^CE[17:39:25.760] Transport error: Got signal, shutting down
I[17:39:25.760] LSP finished, exiting with status 1

2023-02-15 17-clangd-uncaughterrs

dfyz commented 1 year ago

I also stumbled upon this weird error. It turns out that child_process.spawn() returns ENOENT if the current working directory of the process doesn't exist, even if the process binary itself can be executed just fine. In my case, this happened because I had some non-existent directories in my workspace JSON. After I removed them, the error went away.

I'm not sure the root cause is the same in your case, but you can try removing invalid/non-existent paths from your workspace file, if you have any.

j-lakeman commented 1 year ago

THX @dfyz for the workaround! I believe this is still a bug. Personally, I need a multi root workspace to be able to work with Mac and Linux, which looks something like that:

"folders": [
        // Linux 🐧
        // { //bug
        //  "path": "/home/XXX"
        // },
        // {
        //  "path": "/home/XXX"
        // },
        // macOS 🍎
        {
            "path": "/Users/XXX"
        },
        {
            "path": "/Users/XXX"
        },
    ],

As you can see, I had to comment out the Linux section, so that clangd would work under macOS. Otherwise, I get the following output:

[Error - 8:54:19 AM] Clang Language Server client: couldn't create connection to server. Launching server using command /usr/local/opt/llvm/bin/clangd failed. Error: spawn /usr/local/opt/llvm/bin/clangd ENOENT

Basically, I'm including the same paths, but I haven't found a way yet to use ~ or $HOME in jsonc. I believe clangd should just ignore the unfound directories instead of crashing. Any thoughts on this?

j-lakeman commented 1 year ago

Probably related to #352, #38 and https://github.com/clangd/clangd/issues/1549