nvim-lsp-installer icon indicating copy to clipboard operation
nvim-lsp-installer copied to clipboard

demo: migrate to new way of setting up LSP servers

Open williamboman opened this issue 2 years ago • 6 comments

This is a demo of how a migration to the new setup structure could look like. This example will set up the following servers:

  • sumneko_lua
  • tsserver (+ integrate with nvim-lsp-ts-utils)
  • graphql
  • jsonls
  • cssls

williamboman avatar Apr 28 '22 12:04 williamboman

Just a heads up for anyone still using nvim-lsp-ts-utils: it has been put into maintenance mode and the replacement is typescript.nvim

vuki656 avatar Apr 28 '22 14:04 vuki656

Feel free to update https://github.com/neovim/nvim-lspconfig/wiki/Installing-language-servers#automatically, I just threw some stuff down. Thanks, these changes are great.

mjlbach avatar Apr 28 '22 15:04 mjlbach

The function .get_installed_servers() will still be supported in the future?

VonHeikemen avatar Apr 28 '22 16:04 VonHeikemen

The function .get_installed_servers() will still be supported in the future?

That function will remain!

williamboman avatar Apr 28 '22 21:04 williamboman

The function .get_installed_servers() will still be supported in the future?

That function will remain!

Does that include server:on_ready(function() ... end) as in:

local servers = {
  ['tsserver'] = {
    on_attach = function() ... end,
    root_dir = ...,
    settings = ...
  },
}

-- Loop through the servers listed above.
-- installing each, then if install succeeded,
-- setup the server with the options specified in server_opts,
-- or just use the default options
--
for name, opts in ipairs(servers) do
  opts = opts or {}
  opts.on_attach = opts.on_attach or default_on_attach
  local available, server = lsp_installer_servers.get_server(name)
  if available then
    server:on_ready(function ()
      server:setup(opts)
    end)
    -- Queue the server to be installed.
    if not server:is_installed() then
      server:install()
    end
  end
end

bennypowers avatar Apr 29 '22 10:04 bennypowers

Does that include server:on_ready(function() ... end) as in:

The on_ready() function is deprecated as well! Note that you can now remove that snippet of code in your example that loops through your desired server and replace it with the new ensure_installed feature:

require("nvim-lsp-installer").setup {
  ensure_installed = { "tsserver", "graphql" }
}

Once #638 lands you can also configure nvim-lsp-installer to automatically do this for every server that you set up.

williamboman avatar Apr 29 '22 11:04 williamboman