chipsenkbeil / distant.nvim

🚧 (Alpha stage software) Edit files, run programs, and work with LSP on a remote machine from the comfort of your local environment 🚧
https://distant.dev
Apache License 2.0
1.18k stars 11 forks source link

Cannot use LSP client from nvim #137

Open RCX777 opened 3 months ago

RCX777 commented 3 months ago

While trying to open a source file with a file type matching the one set in my config, I get the following stack trace:

E5108: Error executing lua: C:/Program Files/Neovim/share/nvim/runtime/lua/vim/lsp.lua:598: client_id: expected number, got nil
stack traceback:
        [C]: in function 'error'
        vim/shared.lua:936: in function 'validate'
        C:/Program Files/Neovim/share/nvim/runtime/lua/vim/lsp.lua:598: in function 'buf_attach_client'
        .../nvim-data/lazy/distant.nvim/lua/distant-core/client.lua:223: in function 'do_connect_client'
        .../nvim-data/lazy/distant.nvim/lua/distant-core/client.lua:235: in function 'connect_lsp_clients'
        ...zy/distant.nvim/lua/distant/editor/open/configurator.lua:177: in function 'configure'
        .../nvim-data/lazy/distant.nvim/lua/distant/editor/open.lua:246: in function 'open'
        .../nvim-data/lazy/distant.nvim/lua/distant/nav/actions.lua:47: in function <.../nvim-data/lazy/distant.nvim/lua/distant/nav/actions.lua:41>

I first tried checking my configuration for anything wrong on my part, and couldn't find anything. After that I tried printing the config table in ../distant-core/client.lua before the do_connect_client call, and the data within seemed OK. I also found out that the cmd field was set to the following:

"distant.exe spawn --lsp distant://1658010143 --connection 1658010143 -- /usr/bin/clangd"

All of the arguments seemed fine, so I did the natural thing, and tried to run the same command in the terminal, and got no errors. On a separate terminal, I was checking the server log, and found out that when the command was sent from the terminal, the server correctly spawned a clangd process, and the request was visible from the log. When instead trying to open the source file from neovim, only 2 requests were logged: one for the file's metadata, and one for the actual data, but nothing LSP-related.

I tried connecting using an ssh scheme, or running neovim from a Linux machine, but nothing seems to work.

Concerning my current setup on windows, here is some additional info:

PS C:\Users\robecons\AppData\Local\nvim-data\lazy\distant.nvim> nvim --version
NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1713484068
Lazy output:
        dir    C:/Users/robecons/AppData/Local/nvim-data/lazy/distant.nvim
        url    https://github.com/chipsenkbeil/distant.nvim
        branch v0.3
        commit 823267c

I'm also using a configuration based on nvchad, and I disabled nvim-lspconfig, as some people pointed out that it causes some issues when paired with distant.nvim.

I would really to find out a way to fix this, as the single way to work remote without latency AND with LSP support is running vscode, which I just can't switch back to. (I already fell off the deep end 😄)

chipsenkbeil commented 3 months ago

@RCX777 I haven't tested this on newer versions of neovim beyond 0.8; so, I'm wondering if something changed in the LSP API that has broken the LSP integration. It's been awhile since I tried on Windows - was using a Windows VM to test - so I can't remember if there's anything different than expected from what you shared in terms of the command or other output.

I looked up on neovim 0.10 the current documentation for vim.lsp.start_client, which is what we invoke to get the client id that appears to be nil. I can't remember what the old signature was, but it appears now that it can return nil for the id and include an error message if something went wrong. So I'm going to create a branch to explicitly check for this.

Can you try out this branch and see what error you get? https://github.com/chipsenkbeil/distant.nvim/tree/fix/AddCheckForFailingToStartLspClient

RCX777 commented 3 months ago

@chipsenkbeil thanks for the prompt answer! I'm not very familiar with Lua or the Neovim API in general, so I bet it would've taken me some time. Looks like they changed the cmd from a string to a table, probably because they wanted to handle the arguments separately from the program name or something. Now it works properly and I didn't expected it to be so fast, nice job! I'm leaving a PR, have fun with it :)))))