Skip to content

Commit

Permalink
refactor!: switch lsp config to Mason
Browse files Browse the repository at this point in the history
Mason is the successor to nvim-lsp-installer see
williamboman/nvim-lsp-installer#879. While
everything should work as it used to I marked it as breaking because the
user commands to access the LSP installer have changed. (Try :Mason)
  • Loading branch information
dkarter committed Aug 7, 2022
1 parent 243646d commit 7202090
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 107 deletions.
19 changes: 8 additions & 11 deletions config/nvim/lua/plugins/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,21 @@ return packer.startup(function(use)
end,
}

-- installs and sets up lsps for you
-- installs/updates LSPs, linters and DAPs
use {
'junnplus/nvim-lsp-setup',
'williamboman/mason.nvim',
requires = {
-- just installs/updates LSPs
'williamboman/nvim-lsp-installer',

-- LSP driven completions
'hrsh7th/cmp-nvim-lsp',
-- handles connection of LSP Configs and Mason
'williamboman/mason-lspconfig.nvim',

-- Collection of configurations for the built-in LSP client
'neovim/nvim-lspconfig',

-- elixir commands from elixirls
'mhanberg/elixir.nvim',

-- required by elixir plugin
'nvim-lua/plenary.nvim',
{
'mhanberg/elixir.nvim',
requires = { 'nvim-lua/plenary.nvim' },
},
},
config = function()
require('plugins.lsp').setup()
Expand Down
162 changes: 66 additions & 96 deletions config/nvim/lua/plugins/lsp.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
local present, lspsetup = pcall(require, 'nvim-lsp-setup')
local utils = require 'core.utils'

if not present then
local mason_present, mason = pcall(require, 'mason')
local mason_lspconfig_present, mason_lspconfig = pcall(require, 'mason-lspconfig')
local lspconfig_present, lspconfig = pcall(require, 'lspconfig')

if utils.contains({ mason_present, mason_lspconfig_present, lspconfig_present }, nil) then
vim.notify 'Failed to load dependencies in plugins/lsp.lua'
return
end

Expand Down Expand Up @@ -35,96 +40,59 @@ M.setup = function()
-- set up global mappings for diagnostics
require('core.mappings').lsp_diagnostic_mappings()

lspsetup.setup {
-- I'll use my own mappings
default_mappings = false,

-- Global on_attach
on_attach = on_attach,

-- Global capabilities (cmp_nvim_lsp will automatically advertise
-- capabilities) as per https://github.com/junnplus/nvim-lsp-setup#cmp-nvim-lsp
-- capabilities = not necessary...

-- Configuration of LSP servers
servers = {
-- Install LSP servers automatically
-- LSP server configuration please see: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md

-- zig
zls = {},

-- Arduino
arduino_language_server = {},

-- cmake
cmake = {},

-- Elm
elmls = {},

-- Markdown
prosemd_lsp = {},

-- SQL
sqlls = {},

-- Erlang
erlangls = {},

-- HTML snippets
emmet_ls = {},

-- TOML
taplo = {},

-- C, CPP
clangd = {},

-- C, CPP, Arduino
ccls = {},

-- Rust
rust_analyzer = {},

-- TypeScript and JavaScript
tsserver = {},

-- Ruby
solargraph = {},

-- Dockerfile
dockerls = {},

-- Terraform
terraformls = {},

-- Ansible
ansiblels = {},

-- JSON
jsonls = require 'plugins.lsp.jsonls',

-- YAML
yamlls = require('plugins.lsp.yamlls').setup(on_attach),

-- CSS
cssls = {},

-- HTML
html = {},

-- Golang
gopls = {},

-- Bash
bashls = {},

-- VimScript
vimls = {},
mason.setup()
mason_lspconfig.setup {
ensure_installed = {
'ansible-language-server',
'arduino-language-server',
'bash-language-server',
'clangd',
'cmake-language-server',
'css-lsp',
'dockerfile-language-server',
'elixirls',
'elm-language-server',
'emmet-ls',
'eslint-lsp',
'erlang-ls',
'gopls',
'html-lsp',
'json-lsp',
'prosemd-lsp',
'rust-analyzer',
'solargraph',
'sqlls',
'lua-language-server',
'tailwindcss-language-server',
'taplo',
'terraform-ls',
'typescript-language-server',
'vim-language-server',
'yaml-language-server',
'zls',
},
}

-- Lua
sumneko_lua = {
mason_lspconfig.setup_handlers {
function(server_name)
lspconfig[server_name].setup { on_attach = on_attach }
end,

-- JSON
jsonls = function()
local overrides = require 'plugins.lsp.jsonls'
lspconfig.jsonls.setup(overrides)
end,

-- YAML
yamlls = function()
local overrides = require('plugins.lsp.yamlls').setup(on_attach)
lspconfig.yamlls.setup(overrides)
end,

-- Lua
sumneko_lua = function()
lspconfig.sumneko_lua.setup {
settings = {
Lua = {
runtime = {
Expand All @@ -147,17 +115,19 @@ M.setup = function()
},
},
},
},
}
end,

-- Elixir
elixirls = {
-- Elixir
elixirls = function()
lspconfig.elixirls.setup {
on_attach = function(client, bufnr)
-- regular on_attach for lsp
on_attach(client, bufnr)
require('elixir').on_attach(client, bufnr)
end,
},
},
}
end,
}

appearance_mods()
Expand Down

0 comments on commit 7202090

Please sign in to comment.