kabouzeid / nvim-lspinstall

Provides the missing :LspInstall for nvim-lspconfig
MIT License
526 stars 66 forks source link

Config to require servers #26

Open famiu opened 3 years ago

famiu commented 3 years ago

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.

kabouzeid commented 3 years ago

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 :)

famiu commented 3 years ago

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 commented 3 years ago

Maybe also add a way to update them automatically?

kabouzeid commented 3 years ago

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

famiu commented 3 years ago

Ah alright, I'll close the issue then

kabouzeid commented 3 years ago

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

dagadbm commented 3 years ago

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?

kabouzeid commented 3 years ago

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 commented 3 years ago

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;
      }
    }
  }
}
dagadbm commented 3 years ago

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.

pedropmedina commented 3 years ago

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
kabouzeid commented 3 years ago

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

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