New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to easily load default config of an LSP #1302
Comments
You can override the default like so: https://github.com/neovim/nvim-lspconfig/blob/master/ADVANCED_README.md#example-override-default-config-for-all-servers |
But isn't that only for overriding ALL configs? What I need to do is GET the default cmd of a config to alter it. |
Hmm, I see. I'm not sure I see why you can't just override cmd individually for all the servers you use? I think historically I've changed cmd for a server once (omnisharp) |
That's what I'm currently doing, but for this I need to have an actual mapping to executable name and parameters: (excuse my noobish lua 👼🏻) local function yarn_custom_install_path(install_dir)
return vim.env.HOME .. "/.config/nvim/lsp-servers/" .. install_dir .. "/node_modules/.bin/"
end
local function server_custom_cmd(server_name)
if server_name == "bashls" then
return {yarn_custom_install_path(server_name) .. "bash-language-server", "start"}
elseif server_name == "diagnosticls" then
return {yarn_custom_install_path(server_name) .. "diagnostic-languageserver", "--stdio"}
elseif server_name == "dockerls" then
return {yarn_custom_install_path(server_name) .. "docker-langserver", "--stdio"}
elseif server_name == "pyright" then
return {yarn_custom_install_path(server_name) .. "pyright-langserver", "--stdio"}
elseif server_name == "tsserver" then
return {yarn_custom_install_path(server_name) .. "typescript-language-server", "--stdio"}
elseif server_name == "cssls" then
return {yarn_custom_install_path("vscode-extracted") .. "vscode-css-language-server", "--stdio"}
elseif server_name == "html" then
return {
yarn_custom_install_path("vscode-extracted") .. "vscode-html-language-server", "--stdio"
}
elseif server_name == "yamlls" then
return {yarn_custom_install_path(server_name) .. "yaml-language-server", "--stdio"}
elseif server_name == "vuels" then
return {yarn_custom_install_path(server_name) .. "vls"}
else
return nil
end
end
[...]
local function setup_servers()
local tablex = require("pl.tablex")
local servers = {
"bashls", "diagnosticls", "dockerls", "sumneko_lua", "pyright", "tsserver", "cssls", "jsonls",
"html", "vuels", "yamlls", "solargraph", "efm", "terraformls"
}
for _, server in ipairs(servers) do
local config = make_config()
local custom_cmd = server_custom_cmd(server)
-- install path overrides
if custom_cmd then
config = tablex.merge(config, {
cmd = custom_cmd
}, true)
end
-- language specific config
if server == "diagnosticls" then config = tablex.merge(config, diagnosticls_config, true) end
if server == "efm" then config = tablex.merge(config, efm_config, true) end
if server == "typescript" then
config.on_attach = function(client)
on_attach(client)
-- formatting handled by prettier
client.resolved_capabilities.document_formatting = false
end
end
require"lspconfig"[server].setup(config)
end
end I'd like to get the executable name and (especially) the parameters from the default config and only prepend the command with my custom path. This would allow me to benefit from potential parameter changes in the default lspconfig. |
Just to clarify, you can just call |
Another option is to add them to your |
@mjlbach I know, but I don't think I can only override the first entry in the local tablex = require("pl.tablex")
local bashls = require'lspconfig'.bashls
local cmd = tablex.copy(bashls.default_config.cmd)
cmd[1] = vim.env.HOME .. "/.config/nvim/lsp-servers/bashls/node_modules/.bin/" .. cmd[1]
bashls.setup({ cmd = cmd }) This way I can easily prepend the cmd path and can fully rely on lspconfig to manage parameters for me. |
Update: I recently stopped doing this myself and instead use the excellent https://github.com/williamboman/nvim-lsp-installer, so from my perspective this issue could be closed. Then again, someone else might find it helpful. |
I'm going to close this in favor of the roadmap, which lists exposing configurations in this way (and so does #1331) |
Language server
No response
Requested feature
I install JS-based LSPs in specific subdirectories, not globally, so they are not in the PATH of the nvim process. To allow nvim to find those executables I need to override the first entry of
cmd
, just like nvim-lspinstall does. It seems pretty complicated to load and modify the default config (see here).My current workaround is to duplicate the default cmd set in my config, but this means I'll always have to check if the parameters besides the executable path may have changed when updating lspconfig.
I'd like to be able to easily require/get the LSP default config to modify the LSP cmd to have the correct path prefixed.
Note: I tried setting
cmd_env = { PATH = "...:" .. vim.env.PATH }
but as far as I can see this won't be utilized when neovim tries to find the cmd executable, only when launching the actual process later.Other clients which have this feature
No response
The text was updated successfully, but these errors were encountered: