nvim-lspconfig
nvim-lspconfig copied to clipboard
append ".cmd" to command arg0 if it fails on Windows
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 respectPATHEXT. null-ls uses it and mason-lspconfig.nvim successfully patches cmds with it. I'd be happy to open a PR that patches commands withexepath()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)
I don't check the system c code but can we do it like system{fast=true} a little change ?
possibly.
Probably the reason is: that doesn't work in Lua "fast" callbacks
yup it not work in event loop unless we set {fast=true} .
What is the current state? On windows, mason download LSP is completely unavailable at all.
Or is there a reason why we don't use
vim.fn.system()(which should do this automatically) instead ofuv_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
cmdwas executable viavim.fn.executable. This ignoresPATHinjected viacmd_env. Instead, we now start the client viauv.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
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.
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.