1
0

switch to mason.nvim

This commit is contained in:
Rokas Puzonas 2023-05-11 17:31:02 +03:00
parent 31cdc5d052
commit d1074eeca2
6 changed files with 78 additions and 85 deletions

View File

@ -1,16 +1,16 @@
local M = {}
local cfg = {}
-- debounce_text_changes = delay, between changing something and lsp updating
M.flags = { debounce_text_changes = 150 }
cfg.flags = { debounce_text_changes = 150 }
local general_settings = { }
M.server_init_options = {
cfg.server_init_options = {
efm = {
documentFormatting = true
}
}
M.server_settings = {
cfg.server_settings = {
efm = {
rootMarkers = {".git/"},
languages = {
@ -84,14 +84,14 @@ M.server_settings = {
}
-- Apply general settings for each server
for _, settings in ipairs(M.server_settings) do
M.server_settings = vim.tbl_deep_extend("keep", settings, general_settings)
for _, settings in ipairs(cfg.server_settings) do
cfg.server_settings = vim.tbl_deep_extend("keep", settings, general_settings)
end
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
---@diagnostic disable-next-line: unused-local
function M.on_attach(client, bufnr)
function cfg.on_attach(client, bufnr)
-- Mappings.
local opts = { noremap = true, silent = true, buffer = bufnr}
@ -137,7 +137,7 @@ function M.on_attach(client, bufnr)
-- autocmd BufWritePre *.py lua vim.lsp.buf.formatting_sync(nil, 100)
end
function M.get_capabilities()
function cfg.get_capabilities()
local capabilities = vim.lsp.protocol.make_client_capabilities()
if packer_plugins['cmp-nvim-lsp'] and packer_plugins['cmp-nvim-lsp'].loaded then
@ -147,7 +147,7 @@ function M.get_capabilities()
return capabilities
end
function M.on_init(initialize_params, config)
function cfg.on_init(initialize_params, config)
-- print("lsp init")
-- TODO: Load settings from ".lspconfig.json" for each projects settings
@ -155,18 +155,12 @@ function M.on_init(initialize_params, config)
-- https://github.com/neovim/nvim-lspconfig/wiki/Project-local-settings
end
function M.get_server_settings(name)
return M.server_settings[name]
function cfg.get_server_settings(name)
return cfg.server_settings[name]
end
function M.get_server_init_options(name)
return M.server_init_options[name]
function cfg.get_server_init_options(name)
return cfg.server_init_options[name]
end
---@diagnostic disable-next-line: empty-block
if packer_plugins['nvim-lsp-installer'] and packer_plugins['nvim-lsp-installer'].loaded then
-- local lspconfig = require('lspconfig')
-- TODO: Manually do "server:setup{}" if lspinstaller is not loaded
end
return M
return cfg

View File

@ -1,39 +0,0 @@
local lspconfig_config = require('config.lspconfig')
local lsp_installer = require('nvim-lsp-installer')
local lsp_installer_servers = require('nvim-lsp-installer.servers')
-- local autoinstall_servers = {"sumneko_lua", "efm"}
local autoinstall_servers = {"sumneko_lua"}
for _, name in ipairs(autoinstall_servers) do
local ok, server = lsp_installer_servers.get_server(name)
if ok and not server:is_installed() then
server:install()
end
end
local capabilities = lspconfig_config.get_capabilities()
for _, server in ipairs(lsp_installer.get_installed_servers()) do
local opts = {
root_dir = function()
return vim.fn.getcwd()
end,
init_options = lspconfig_config.get_server_init_options(server.name),
on_attach = lspconfig_config.on_attach,
on_init = lspconfig_config.on_init,
flags = lspconfig_config.flags,
capabilities = capabilities,
settings = lspconfig_config.get_server_settings(server.name)
}
if server.name == "rust_analyzer" then
local has_rust_tools, rust_tools = pcall(require, "rust-tools")
if has_rust_tools then
rust_tools.setup({ server = opts })
goto continue
end
end
server:setup(opts)
::continue::
end

View File

@ -11,8 +11,8 @@ return {
}
}
require("legendary").keymap{
"<super>x", lsp_signature.toggle_float_win, description="Toggle signature float"
}
-- require("legendary").keymap{
-- "<super>x", lsp_signature.toggle_float_win, description="Toggle signature float"
-- }
end
}

View File

@ -0,0 +1,32 @@
local lspconfig_config = require('config.lspconfig')
local function get_options(server_name)
return {
root_dir = function()
return vim.fn.getcwd()
end,
init_options = lspconfig_config.get_server_init_options(server_name),
on_attach = lspconfig_config.on_attach,
on_init = lspconfig_config.on_init,
flags = lspconfig_config.flags,
capabilities = capabilities,
settings = lspconfig_config.get_server_settings(server_name)
}
end
require("mason-lspconfig").setup()
require("mason-lspconfig").setup_handlers{
function (server_name) -- default handler (optional)
require("lspconfig")[server_name].setup(get_options(server_name))
end,
["rust_analyzer"] = function ()
local opts = get_options(server_name)
local has_rust_tools, rust_tools = pcall(require, "rust-tools")
if has_rust_tools then
rust_tools.setup({ server = opts })
else
require("lspconfig")[server_name].setup(opts)
end
end
}

1
lua/config/mason.lua Normal file
View File

@ -0,0 +1 @@
require("mason").setup()

View File

@ -45,14 +45,19 @@ return function(use)
}
use {
"neovim/nvim-lspconfig",
config_name = "lspconfig"
}
use {
'williamboman/nvim-lsp-installer',
"williamboman/mason.nvim",
requires = 'neovim/nvim-lspconfig',
config_name = "lspinstaller"
config_name = "mason"
}
use {
"williamboman/mason-lspconfig.nvim",
requires = "williamboman/mason.nvim",
config_name = "mason-lspconfig"
}
use {
"neovim/nvim-lspconfig",
requires = "williamboman/mason-lspconfig.nvim",
--config_name = "lspconfig"
}
use {