junnplus / lsp-setup.nvim

A simple wrapper for nvim-lspconfig and mason-lspconfig to easily setup LSP servers.
Apache License 2.0
225 stars 12 forks source link

rust-analyzer not attached to buffer on windows #37

Closed TisnKu closed 2 years ago

TisnKu commented 2 years ago

Hi there, thanks for the plugin. I found the bug that rust lsp cannot load. If I do a fresh reinstall using :MasonInstall rust-analyzer, it can be loaded immediately. If I quit nvim and reopen the project, it will not load.

Another workaround is to do a manual setup of rust-analyzer using require('lsp-config').rust_analyzer.setup() and remove rust from lsp-setup.nvim.

Open the main.rs in the project, rust lsp cannot load.

image image

Reinstall rust-analyzer using mason, lsp can be loaded.

image

TisnKu commented 2 years ago

Seems that using lsp-setup, the cmd for rust lsp is not correct.

junnplus commented 2 years ago

Can you provide a reproducible minimal configuration?

TisnKu commented 2 years ago

Sure. https://github.com/TisnKu/rust-lsp-setup-repro Plugins are in init.lua and lsp configs are in https://github.com/TisnKu/rust-lsp-setup-repro/blob/304929bb9a657e3af4688c5a13d406792429fb6d/after/plugin/lsp.lua.

junnplus commented 2 years ago

If I do a fresh reinstall using :MasonInstall rust-analyzer, it can be loaded immediately. If I quit nvim and reopen the project, it will not load.

It seems that mason doesn't install rust-analyzer automatically, or the installation fails.

You need to check if rust-analyzer is installed successfully. The following two commands may help you:

junnplus commented 2 years ago

Sure. https://github.com/TisnKu/rust-lsp-setup-repro Plugins are in init.lua and lsp configs are in https://github.com/TisnKu/rust-lsp-setup-repro/blob/304929bb9a657e3af4688c5a13d406792429fb6d/after/plugin/lsp.lua.

I am not sure if we need to specify bundle_path

TisnKu commented 2 years ago

It is installed, just not attached to the buffer. Bundle_path is my random trial to fix the bug, the bug is the same with or without it. image image

TisnKu commented 2 years ago

The installation path of rust-analyzer. image

junnplus commented 2 years ago

Can you delete the rust-analyzer(:LspUninstall rust-analyzer) and restart neovim? Then check if mason will automatically install rust-analyzer.

TisnKu commented 2 years ago

Yes, mason will install rust-analyzer automatically.

TisnKu commented 2 years ago

BTW, on my mac, the same configuration works.

TisnKu commented 2 years ago

I did some tests for other lsps as well, taplo and rust-analyzer have the same issue, tsserver and jsonls does not.

junnplus commented 2 years ago

Sorry, I can't see that this is a problem with lsp-setup, lsp-setup just wraps mason, as you said, it is working on mac.

TisnKu commented 2 years ago

If I replace lsp-setup with require('lspconfig').rust_analyzer.setup {}, it works. Maybe it's a problem of mason-lspconfig

TisnKu commented 2 years ago

After some testing, I found that with only mason-lspconfig, it still works. So I modified the code of lsp-setup just like the example of mason-lspconfig, and it works: image

It's kind of weird why order matters on windows. Any particular reason to put setup_handler before setup?

TisnKu commented 2 years ago

I opened an issue for mason-lspconfig and owner confirmed that setup should be placed before setup_handler. Do you mind fixing it or accept PR?

https://github.com/williamboman/mason-lspconfig.nvim/issues/78

junnplus commented 2 years ago

I opened an issue for mason-lspconfig and owner confirmed that setup should be placed before setup_handler. Do you mind fixing it or accept PR?

Thanks, PRs are doubly welcome!