diff --git a/modules/home/nvim/lazy-lock.json b/modules/home/nvim/lazy-lock.json index dc399d7..a31e00e 100644 --- a/modules/home/nvim/lazy-lock.json +++ b/modules/home/nvim/lazy-lock.json @@ -10,6 +10,8 @@ "leap.nvim": { "branch": "main", "commit": "9a69febb2e5a4f5f5a55dd2d7173098fde917bc5" }, "lualine.nvim": { "branch": "master", "commit": "e99d733e0213ceb8f548ae6551b04ae32e590c80" }, "neo-tree.nvim": { "branch": "v2.x", "commit": "74040b34278910d9b467fd914862e2a9a1ebacaa" }, + "neodev.nvim": { "branch": "main", "commit": "6d362921d772963e5a5e5ed0fcf82153defaf206" }, + "neodim": { "branch": "master", "commit": "c346344ade2ce709e6bd282f10e43778672b861e" }, "noice.nvim": { "branch": "main", "commit": "d8a1f3056ad713b5d471048f8d029264828e22c0" }, "nui.nvim": { "branch": "main", "commit": "d147222a1300901656f3ebd5b95f91732785a329" }, "nvim-colorizer.lua": { "branch": "master", "commit": "550332c5791c6cad6fc7a80c26104de1d00b4692" }, diff --git a/modules/home/nvim/lua/plugins/lsp.lua b/modules/home/nvim/lua/plugins/lsp.lua index 337b8fb..3b7ebc9 100644 --- a/modules/home/nvim/lua/plugins/lsp.lua +++ b/modules/home/nvim/lua/plugins/lsp.lua @@ -1,209 +1,131 @@ -local old = { - { - "neovim/nvim-lspconfig", - event = { "BufReadPre", "BufNewFile" }, - dependencies = { - { "folke/neodev.nvim", opts = { experimental = { pathStrict = true } } }, - "mason.nvim", - "williamboman/mason-lspconfig.nvim", - "hrsh7th/cmp-nvim-lsp", - }, - ---@class PluginLspOpts - opts = { - -- options for vim.diagnostic.config() - diagnostics = { - underline = true, - update_in_insert = true, - virtual_text = false, - severity_sort = true, - }, - -- Automatically format on save - autoformat = false, - -- options for vim.lsp.buf.format - -- `bufnr` and `filter` is handled by the LazyVim formatter, - -- but can be also overridden when specified - format = { - formatting_options = nil, - timeout_ms = nil, - }, - -- LSP Server Settings - ---@type lspconfig.options - servers = { - jsonls = {}, - - lua_ls = { - -- mason = false, -- set to false if you don't want this server to be installed with mason - settings = { - Lua = { - workspace = { - checkThirdParty = false, - }, - completion = { - callSnippet = "Replace", - }, - }, - }, - }, - - -- omnisharp = { - -- handlers = { - -- ["textDocument/definition"] = require('omnisharp_extended').handler, - -- }, - -- cmd_env = { - -- ["OMNISHARP_FormattingOptions:EnableEditorConfigSupport"] = true, - -- ["OMNISHARP_RoslynExtensionsOptions:enableAnalyzersSupport"] = true, - -- ["OMNISHARP_RoslynExtensionsOptions:enableImportCompletion"] = true, - -- ["OMNISHARP_RoslynExtensionsOptions:enableDecompilationSupport"] = true, - -- ["OMNISHARP_msbuild:EnablePackageAutoRestore"] = true, - -- }, - -- }, - - robotframework_ls = { - settings = { - robot = { - codeFormatter = "robotidy", - variables = { - RESOURCES = vim.fn.getcwd() .. "/tests/robot/", - }, - }, - } - }, - }, - -- you can do any additional lsp server setup here - -- return true if you don't want this server to be setup with lspconfig - ---@type table - setup = { - -- example to setup with typescript.nvim - -- tsserver = function(_, opts) - -- require("typescript").setup({ server = opts }) - -- return true - -- end, - -- Specify * to use this function as a fallback for any server - -- ["*"] = function(server, opts) end, - }, - }, - ---@param opts PluginLspOpts - config = function(plugin, opts) - -- setup formatting and keymaps - require("lazyvim.util").on_attach(function(client, buffer) - require("lazyvim.plugins.lsp.format").on_attach(client, buffer) - require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer) - end) - - -- diagnostics - for name, icon in pairs(require("lazyvim.config").icons.diagnostics) do - name = "DiagnosticSign" .. name - vim.fn.sign_define(name, { text = icon, texthl = name, numhl = "" }) - end - vim.diagnostic.config(opts.diagnostics) - - local servers = opts.servers - local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) - - local function setup(server) - local server_opts = vim.tbl_deep_extend("force", { - capabilities = vim.deepcopy(capabilities), - }, servers[server] or {}) - - if opts.setup[server] then - if opts.setup[server](server, server_opts) then - return - end - elseif opts.setup["*"] then - if opts.setup["*"](server, server_opts) then - return - end - end - require("lspconfig")[server].setup(server_opts) - end - - -- temp fix for lspconfig rename - -- https://github.com/neovim/nvim-lspconfig/pull/2439 - local mappings = require("mason-lspconfig.mappings.server") - if not mappings.lspconfig_to_package.lua_ls then - mappings.lspconfig_to_package.lua_ls = "lua-language-server" - mappings.package_to_lspconfig["lua-language-server"] = "lua_ls" - end - - local mlsp = require("mason-lspconfig") - local available = mlsp.get_available_servers() - - local ensure_installed = {} ---@type string[] - for server, server_opts in pairs(servers) do - if server_opts then - server_opts = server_opts == true and {} or server_opts - -- run manual setup if mason=false or if this is a server that cannot be installed with mason-lspconfig - if server_opts.mason == false or not vim.tbl_contains(available, server) then - setup(server) - else - ensure_installed[#ensure_installed + 1] = server - end - end - end - - require("mason-lspconfig").setup({ ensure_installed = ensure_installed }) - require("mason-lspconfig").setup_handlers({ setup }) - end, - }, - - { - "jose-elias-alvarez/null-ls.nvim", - event = { "BufReadPre", "BufNewFile" }, - dependencies = { "mason.nvim" }, - opts = function() - local nls = require("null-ls") - local sources = { - nl.builtins.code_actions.eslint_d, - nl.builtins.diagnostics.eslint_d, - nl.builtins.formatting.eslint_d, - nl.builtins.formatting.prettierd, - nl.builtins.formatting.black, - } - return { - sources = vim.tbl_map(function(source) - return source.with({ - diagnostics_postprocess = function(diagnostic) - diagnostic.severity = vim.diagnostic.severity.HINT - end, - }) - end, sources), - } - end, - }, - - { - - "williamboman/mason.nvim", - cmd = "Mason", - keys = { { "li", "Mason", desc = "Mason" } }, - opts = { - ensure_installed = { }, - }, - ---@param opts MasonSettings | {ensure_installed: string[]} - config = function(plugin, opts) - require("mason").setup(opts) - local mr = require("mason-registry") - for _, tool in ipairs(opts.ensure_installed) do - local p = mr.get_package(tool) - if not p:is_installed() then - p:install() - end - end - end, - }, +local nullls = { + "jose-elias-alvarez/null-ls.nvim", + event = { "BufReadPre", "BufNewFile" }, + dependencies = { "mason.nvim" }, + opts = function() + local nls = require("null-ls") + local sources = { + nl.builtins.code_actions.eslint_d, + nl.builtins.diagnostics.eslint_d, + nl.builtins.formatting.eslint_d, + nl.builtins.formatting.prettierd, + nl.builtins.formatting.black, + } + return { + sources = vim.tbl_map(function(source) + return source.with({ + diagnostics_postprocess = function(diagnostic) + diagnostic.severity = vim.diagnostic.severity.HINT + end, + }) + end, sources), + } + end, } +local lsp_keymaps = function(buffer) + local function map(mode, l, r, desc) + vim.keymap.set(mode, l, r, { buffer = buffer, desc = desc }) + end + + map("n", "K", 'lua vim.lsp.buf.hover()', "See informations") + map("n", "", 'lua vim.lsp.buf.signature_help()', "See signature help") + + map("n", "gD", 'lua vim.lsp.buf.declaration()', "Go to declaration") + map("n", "gd", 'lua vim.lsp.buf.definition()', "Go to definition") + map("n", "gI", 'lua vim.lsp.buf.implementation()', "Go to implementation") + map("n", "gr", 'lua vim.lsp.buf.references()', "Go to reference(s)") + map("n", "gs", 'lua vim.lsp.buf.type_definition()', "Type definition") + + map("n", "lr", 'lua vim.lsp.buf.rename()', "Rename") + map("n", "la", 'lua vim.lsp.buf.code_action()', "Code action") + map("n", "ll", 'lua vim.lsp.codelens.run()', "Run code lens") + map("n", "lg", 'Telescope lsp_document_symbols', "Go to symbol") + map("n", "lf", 'lua vim.lsp.buf.format({async=true})', "Format") + + map("v", "lf", 'lua vim.lsp.buf.format({async=true})', "Range Format") +end + return { { "dundalek/lazy-lsp.nvim", event = { "BufReadPre", "BufNewFile" }, dependencies = { - "neovim/nvim-lspconfig" + { + "neovim/nvim-lspconfig", + dependencies = { + { "folke/neodev.nvim", opts = { experimental = { pathStrict = true } } }, + }, + }, }, opts = { - excluded_servers = { "efm", "diagnosticls" }, + excluded_servers = { + -- Disable generic purpose LSP that I don't care about. + "efm", + "diagnosticls" + }, + default_config = { + on_attach = function(client, buffer) + lsp_keymaps(buffer) + + local ok, navic = pcall(require, "nvim-navic") + if ok then + navic.attach(client, buffer) + end + end, + }, }, + init = function() + local signs = { + { name = "DiagnosticSignError", text = "" }, + { name = "DiagnosticSignWarn", text = "" }, + { name = "DiagnosticSignHint", text = "" }, + { name = "DiagnosticSignInfo", text = "" }, + } + for _, sign in ipairs(signs) do + vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) + end + + local function map(l, r, desc) + vim.keymap.set("n", l, r, { desc = desc }) + end + map("[d", 'lua vim.diagnostic.goto_prev()', "Prev diagnostic") + map("]d", 'lua vim.diagnostic.goto_next()', "Next diagnostic") + map("gl", "lua vim.diagnostic.open_float()", "See diagnostics") + map("li", "LspInfo", "Info") + + + vim.diagnostic.config({ + virtual_text = false, + update_in_insert = true, + float = { + border = "rounded", + source = "always", + }, + }) + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { + border = "rounded", + }) + end, + }, + + { + "zbirenbaum/neodim", + event = "LspAttach", + opts = { + alpha = 0.75, + blend_color = "#000000", + update_in_insert = { + enable = true, + delay = 100, + }, + hide = { + virtual_text = true, + signs = false, + underline = true, + } + } }, } diff --git a/modules/home/nvim/lua/plugins/ui.lua b/modules/home/nvim/lua/plugins/ui.lua index 81e3895..fa53cf1 100644 --- a/modules/home/nvim/lua/plugins/ui.lua +++ b/modules/home/nvim/lua/plugins/ui.lua @@ -93,6 +93,7 @@ return { noremap = false, }) + -- TODO: Moves this to the settinsg.lua file and use the standard way wk.register({ y = { "Yank to system clipboard" }, Y = { "Yank line to system clipboard" }, @@ -102,16 +103,13 @@ return { prefix = "", }) - wk.register({ - ["w"] = { "ASToggle", "Toggle autosave" }, - }) - wk.register({ mode = { "n", "v" }, ["g"] = { name = "+goto" }, ["]"] = { name = "+next" }, ["["] = { name = "+prev" }, ["g"] = { name = "+git" }, + ["l"] = { name = "+lsp" }, }) local uwk = require("unimpaired-which-key")