Skip to content

Commit

Permalink
Switch from nvim-lsp-installer to mason.nvim and mason-lspconfig.nvim
Browse files Browse the repository at this point in the history
  • Loading branch information
chancez committed Oct 25, 2022
1 parent 4e5e5bc commit 8257f38
Showing 1 changed file with 38 additions and 26 deletions.
64 changes: 38 additions & 26 deletions neovim/.config/nvim/init.lua
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ packer.startup(function(use)
use 'ray-x/lsp_signature.nvim' use 'ray-x/lsp_signature.nvim'
use 'onsails/lspkind-nvim' use 'onsails/lspkind-nvim'
use 'simrat39/symbols-outline.nvim' use 'simrat39/symbols-outline.nvim'
use 'williamboman/nvim-lsp-installer'
use 'j-hui/fidget.nvim' use 'j-hui/fidget.nvim'
use { 'williamboman/mason.nvim' }
use { 'williamboman/mason-lspconfig.nvim' , requires = { 'williamboman/mason.nvim' }}


-- debug adapter protocol -- debug adapter protocol
use 'mfussenegger/nvim-dap' use 'mfussenegger/nvim-dap'
Expand Down Expand Up @@ -320,8 +321,6 @@ local default_on_attach = function(client, bufnr)
end) end)
end end


local lsp_installer_servers = require('nvim-lsp-installer.servers')

-- Insert runtime_path of neovim lua files for LSP -- Insert runtime_path of neovim lua files for LSP
local runtime_path = vim.split(package.path, ';') local runtime_path = vim.split(package.path, ';')
table.insert(runtime_path, 'lua/?.lua') table.insert(runtime_path, 'lua/?.lua')
Expand Down Expand Up @@ -428,35 +427,48 @@ local servers = {
}, },
} }


-- Loop through the servers listed above and set them up. If a server is
-- not already installed, install it. require("mason").setup({
for server_name, server_specific_opts in pairs(servers) do ui = {
local capabilities = cmp_lsp.default_capabilities() icons = {
local server_opts = { package_installed = "",
on_attach = default_on_attach, package_pending = "",
capabilities = capabilities, package_uninstalled = ""
flags = { }
debounce_text_changes = 150,
},
} }
})


for k,v in pairs(server_specific_opts) do local function get_keys(t)
server_opts[k] = v local keys={}
for key,_ in pairs(t) do
table.insert(keys, key)
end end
return keys
end


require("mason-lspconfig").setup({
ensure_installed = get_keys(servers),
})


local server_available, server = lsp_installer_servers.get_server(server_name) require("mason-lspconfig").setup_handlers({
if server_available then -- The first entry (without a key) will be the default handler
if not server:is_installed() then function (server_name)
print("Installing " .. server_name) local capabilities = cmp_lsp.default_capabilities()
-- Queue the server to be installed. local server_opts = {
server:install() on_attach = default_on_attach,
capabilities = capabilities,
flags = {
debounce_text_changes = 150,
},
}
local server_specific_opts = servers[server_name]
for k,v in pairs(server_specific_opts) do
server_opts[k] = v
end end
server:on_ready(function ()
server:setup(server_opts) require("lspconfig")[server_name].setup(server_opts)
end) end,
end })
end


-- lsp signature -- lsp signature
require('lsp_signature').setup { require('lsp_signature').setup {
Expand Down

0 comments on commit 8257f38

Please sign in to comment.