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

Config to require servers

Open famiu opened this issue 3 years ago • 12 comments

Instead of having to manually install servers, include a config option where you can basically provide a list of language servers you need, so that lspinstall can automatically install them if they aren't already installed.

famiu avatar Apr 05 '21 04:04 famiu

Good idea. You can already do that, by adding this to your lua config:

-- Install missing servers
local required_servers = { "lua", "tailwindcss", "bash" }
local installed_servers = require'lspinstall'.installed_servers()
for _, server in pairs(required_servers) do
  if not vim.tbl_contains(installed_servers, server) then
    require'lspinstall'.install_server(server)
  end
end

Will probably add this to the README :)

kabouzeid avatar Apr 05 '21 11:04 kabouzeid

Strange, first time I wanted it I actually wrote a similar piece of code but it showed some errors. This seems to work though

famiu avatar Apr 05 '21 15:04 famiu

Maybe also add a way to update them automatically?

famiu avatar Apr 05 '21 16:04 famiu

auto update won't work, see https://github.com/kabouzeid/nvim-lspinstall/issues/8

kabouzeid avatar Apr 05 '21 17:04 kabouzeid

Ah alright, I'll close the issue then

famiu avatar Apr 09 '21 05:04 famiu

I'll leave it open until I added this to the README

kabouzeid avatar Apr 09 '21 08:04 kabouzeid

also how can I have custom configurations to extend the default configurations you provide?

Imagine I want to setup prettier/eslint using efm/diagnosticls how would I go about doing that while still respecting the default configs that come from this?

dagadbm avatar Apr 12 '21 12:04 dagadbm

I'm doing this in my personal config: https://github.com/kabouzeid/nvim-lspinstall/wiki

Relevant part:

-- lsp-install
local function setup_servers()
  require'lspinstall'.setup()

  -- get all installed servers
  local servers = require'lspinstall'.installed_servers()
  -- ... and add manually installed servers
  table.insert(servers, "clangd")
  table.insert(servers, "sourcekit")

  for _, server in pairs(servers) do
    local config = make_config()

    -- language specific config
    if server == "lua" then
      config.settings = lua_settings
    end
    if server == "sourcekit" then
      config.filetypes = {"swift", "objective-c", "objective-cpp"}; -- we don't want c and cpp!
    end
    if server == "clangd" then
      config.filetypes = {"c", "cpp"}; -- we don't want objective-c and objective-cpp!
    end

    require'lspconfig'[server].setup(config)
  end
end

Does this work for you?

kabouzeid avatar Apr 12 '21 13:04 kabouzeid

Basically as usual, you can use config in require'lspconfig'[server].setup(config) to override any config options. See: https://github.com/neovim/nvim-lspconfig#example-override-some-defaults

eg

local lspconfig = require'lspconfig'
lspconfig.latex.setup {
  name = 'latex_fancy';
  settings = {
    latex = {
      build = {
        onSave = true;
      }
    }
  }
}

kabouzeid avatar Apr 12 '21 13:04 kabouzeid

alright. so its just a matter of creating some object where the key matches your language server name in the LspInstall then do a table deep extend. something like that.

dagadbm avatar Apr 12 '21 14:04 dagadbm

What's the proper way of modifying the settings for tailwindcss. This is what I'm trying to get working, but so far no luck!?

local tailwindcss = function(config)
    local opts = {
        settings = {
            includeLanguages = { typescript = 'javascript', typescriptreact = 'javascript' },
            tailwindCSS = {
                experimental = {
                    classRegex = {
                        'tw`([^`]*)',
                        'tw="([^"]*)',
                        'tw={"([^"}]*)',
                        'tw\\.\\w+`([^`]*)',
                        'tw\\(.*?\\)`([^`]*)'
                    }
                }
            }
        }
    }
    for k, v in pairs(config) do opts[k] = v end
    return opts
end

return tailwindcss

pedropmedina avatar Apr 12 '21 16:04 pedropmedina

@pedropmedina should work now, I fixed it 22 days ago.

https://github.com/kabouzeid/nvim-lspinstall/issues/45#issuecomment-826902941

kabouzeid avatar May 18 '21 10:05 kabouzeid