nvim-lspconfig icon indicating copy to clipboard operation
nvim-lspconfig copied to clipboard

append ".cmd" to command arg0 if it fails on Windows

Open justinmk opened this issue 3 years ago • 6 comments

Problem

Commonly on Windows, some commands require the .cmd suffix. This is often missed, leading to issues like https://github.com/neovim/nvim-lspconfig/issues/2032 , and the solution is copy-pasted into configs: https://github.com/neovim/nvim-lspconfig/pull/2039

Proposal

@williamboman https://github.com/neovim/nvim-lspconfig/issues/2032#issuecomment-1200413852 :

exepath() seems to solve this pretty nicely, as Neovim does respect PATHEXT. null-ls uses it and mason-lspconfig.nvim successfully patches cmds with it. I'd be happy to open a PR that patches commands with exepath() on Windows + normalizes all commands in server configs.

Or is there a reason why we don't use vim.fn.system() (which should do this automatically) instead of uv_spawn (vim.loop.spawn))? (Probably the reason is: that doesn't work in Lua "fast" callbacks)

justinmk avatar Sep 11 '22 18:09 justinmk

I don't check the system c code but can we do it like system{fast=true} a little change ?

glepnir avatar Sep 11 '22 22:09 glepnir

possibly.

justinmk avatar Sep 11 '22 23:09 justinmk

Probably the reason is: that doesn't work in Lua "fast" callbacks

yup it not work in event loop unless we set {fast=true} .

glepnir avatar Sep 11 '22 23:09 glepnir

What is the current state? On windows, mason download LSP is completely unavailable at all.

acfuns avatar Oct 21 '22 08:10 acfuns

Or is there a reason why we don't use vim.fn.system() (which should do this automatically) instead of uv_spawn (vim.loop.spawn))?

the reason is explained in the original change, see https://github.com/neovim/neovim/pull/16430

Previously, the built-in language server client checked if the first argument of cmd was executable via vim.fn.executable. This ignores PATH injected via cmd_env. Instead, we now start the client via uv.spawn, and handle the failure mode, reporting the error back to the user.

I'm not sure there's an easy way to handle this, whilst respecting cmd_env, outside of writing some is_executable() wrapper using libuv, e.g. https://github.com/npm/node-which

kylo252 avatar Oct 21 '22 10:10 kylo252

What is the current state? On windows, mason download LSP is completely unavailable at all.

I'd recommend using https://github.com/williamboman/mason-lspconfig.nvim if you're on Windows. It patches the commands for you automatically.

williamboman avatar Oct 23 '22 15:10 williamboman

This would be such a terrific addition! I just tore my hair out with this error! An lsp was erroring out because the language server command did not exist, I make sure to add it to the path, and still no dice. Once I added the .cmd to the end of the lsp start command it magically worked. Thank you so much for noticing! It makes me incredibly happy that I was not the only one with this issue.

GersiD avatar Dec 21 '22 02:12 GersiD