diff --git a/lua/config/lspconfig.lua b/lua/config/lspconfig.lua index 7ad3f47..657d866 100644 --- a/lua/config/lspconfig.lua +++ b/lua/config/lspconfig.lua @@ -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,19 +84,19 @@ 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) - -- Mappings. - local opts = { noremap = true, silent = true, buffer = bufnr} +function cfg.on_attach(client, bufnr) + -- Mappings. + local opts = { noremap = true, silent = true, buffer = bufnr} - -- local function keymap(mode, lhs, rhs) vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts) end - local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + -- local function keymap(mode, lhs, rhs) vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts) end + local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end require("legendary").keymaps{ { @@ -114,22 +114,22 @@ function M.on_attach(client, bufnr) } } - -- Enable completion triggered by - buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + -- Enable completion triggered by + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') - -- See `:help vim.lsp.*` for documentation on any of the below functions + -- See `:help vim.lsp.*` for documentation on any of the below functions -- Conflicts with movement between panes - -- buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()') + -- buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()') - -- buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()') - -- buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()') - -- buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))') - -- buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()') - -- buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()') - -- buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()') - -- buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()') - -- buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()') + -- buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()') + -- buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()') + -- buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))') + -- buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()') + -- buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()') + -- buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()') + -- buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()') + -- buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()') -- " auto-format -- autocmd BufWritePre *.js lua vim.lsp.buf.formatting_sync(nil, 100) @@ -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 diff --git a/lua/config/lspinstaller.lua b/lua/config/lspinstaller.lua deleted file mode 100644 index 4d4292a..0000000 --- a/lua/config/lspinstaller.lua +++ /dev/null @@ -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 diff --git a/lua/config/lspsignature.lua b/lua/config/lspsignature.lua index 46599c7..36c18a4 100644 --- a/lua/config/lspsignature.lua +++ b/lua/config/lspsignature.lua @@ -11,8 +11,8 @@ return { } } - require("legendary").keymap{ - "x", lsp_signature.toggle_float_win, description="Toggle signature float" - } + -- require("legendary").keymap{ + -- "x", lsp_signature.toggle_float_win, description="Toggle signature float" + -- } end } diff --git a/lua/config/mason-lspconfig.lua b/lua/config/mason-lspconfig.lua new file mode 100644 index 0000000..9397d2f --- /dev/null +++ b/lua/config/mason-lspconfig.lua @@ -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 +} diff --git a/lua/config/mason.lua b/lua/config/mason.lua new file mode 100644 index 0000000..ac26661 --- /dev/null +++ b/lua/config/mason.lua @@ -0,0 +1 @@ +require("mason").setup() diff --git a/lua/plugins.lua b/lua/plugins.lua index 492c63e..1750be0 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -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 {