Navigation Menu

Skip to content
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

Closed
strayer opened this issue Oct 14, 2021 · 9 comments
Closed

Ability to easily load default config of an LSP #1302

strayer opened this issue Oct 14, 2021 · 9 comments
Labels
enhancement New feature or request

Comments

@strayer
Copy link

strayer commented Oct 14, 2021

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

@strayer strayer added the enhancement New feature or request label Oct 14, 2021
@mjlbach
Copy link
Contributor

mjlbach commented Oct 14, 2021

@strayer
Copy link
Author

strayer commented Oct 14, 2021

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.

@mjlbach
Copy link
Contributor

mjlbach commented Oct 14, 2021

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)

@strayer
Copy link
Author

strayer commented Oct 14, 2021

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.

@mjlbach
Copy link
Contributor

mjlbach commented Oct 14, 2021

Just to clarify, you can just call setup{} individually per server with the modified cmd as this selectively overrides the default config. All of the other entries in the table (settings, root_dir, on_new_config) etc. will follow along as neovim updates.

@polyzen
Copy link
Contributor

polyzen commented Oct 14, 2021

Another option is to add them to your PATH using symlinks.

@strayer
Copy link
Author

strayer commented Oct 14, 2021

@mjlbach I know, but I don't think I can only override the first entry in the cmd set. I'd like to do something like this (pseudocode):

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.

@strayer
Copy link
Author

strayer commented Oct 20, 2021

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.

@mjlbach
Copy link
Contributor

mjlbach commented Nov 9, 2021

I'm going to close this in favor of the roadmap, which lists exposing configurations in this way (and so does #1331)

@mjlbach mjlbach closed this as completed Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants