From f53082a62d01b2c1837418a7b5db1a63141f82f3 Mon Sep 17 00:00:00 2001 From: aleidk Date: Wed, 25 Oct 2023 16:53:57 -0300 Subject: [PATCH] update lsp setup for nvim --- config/alacritty/alacritty.yml | 2 +- .../nvim/lua/aleidk/plugins/colorscheme.lua | 2 +- config/nvim/lua/aleidk/plugins/lsp.lua | 85 ++++++++++++------- .../nvim/lua/aleidk/plugins/lsp_signature.lua | 4 +- config/nvim/lua/aleidk/plugins/nvim-tree.lua | 7 +- config/nvim/lua/aleidk/plugins/treesitter.lua | 11 +-- 6 files changed, 68 insertions(+), 43 deletions(-) diff --git a/config/alacritty/alacritty.yml b/config/alacritty/alacritty.yml index 4ff033b..532e9a3 100644 --- a/config/alacritty/alacritty.yml +++ b/config/alacritty/alacritty.yml @@ -65,7 +65,7 @@ window: # # Window opacity as a floating point number from `0.0` to `1.0`. # The value `0.0` is completely transparent and `1.0` is opaque. - opacity: 0.92 + opacity: 1 # Startup Mode (changes require restart) # diff --git a/config/nvim/lua/aleidk/plugins/colorscheme.lua b/config/nvim/lua/aleidk/plugins/colorscheme.lua index 412d3c8..945f3ab 100644 --- a/config/nvim/lua/aleidk/plugins/colorscheme.lua +++ b/config/nvim/lua/aleidk/plugins/colorscheme.lua @@ -4,7 +4,7 @@ return { -- Change colors.none if not using a transparent background lazy = false, opts = { flavour = "macchiato", - transparent_background = true, + transparent_background = false, integrations = { fidget = true, cmp = true, diff --git a/config/nvim/lua/aleidk/plugins/lsp.lua b/config/nvim/lua/aleidk/plugins/lsp.lua index 855c58f..f9e063d 100644 --- a/config/nvim/lua/aleidk/plugins/lsp.lua +++ b/config/nvim/lua/aleidk/plugins/lsp.lua @@ -24,14 +24,7 @@ return { config = function() -- LSP settings. - -- This function gets run when an LSP connects to a particular buffer. local on_attach = function(_, bufnr) - -- NOTE: Remember that lua is a real programming language, and as such it is possible - -- to define small helper and utility functions so you don't have to repeat yourself - -- many times. - -- - -- In this case, we create a function that lets us more easily define mappings specific - -- for LSP related items. It sets the mode, buffer and description for us each time. local nmap = function(keys, func, desc) if desc then desc = "LSP: " .. desc @@ -40,11 +33,14 @@ return { vim.keymap.set("n", keys, func, { buffer = bufnr, desc = desc }) end - nmap("lr", vim.lsp.buf.rename, "[R]e[n]ame") - nmap("la", vim.lsp.buf.code_action, "[C]ode [A]ction") + nmap("lr", vim.lsp.buf.rename, "Rename") + nmap("la", vim.lsp.buf.code_action, "Code Action") + nmap("lf", function() + vim.lsp.buf.format() + end, "Format") nmap("gd", vim.lsp.buf.definition, "Go to definition") - nmap("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences") + nmap("gr", require("telescope.builtin").lsp_references, "Goto References") nmap("gI", vim.lsp.buf.implementation, "Go to Implementation") -- See `:help K` for why this keymap @@ -52,12 +48,12 @@ return { nmap("", vim.lsp.buf.signature_help, "Signature Documentation") -- Lesser used LSP functionality - nmap("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") - nmap("wa", vim.lsp.buf.add_workspace_folder, "[W]orkspace [A]dd Folder") - nmap("wr", vim.lsp.buf.remove_workspace_folder, "[W]orkspace [R]emove Folder") + nmap("gD", vim.lsp.buf.declaration, "Goto Declaration") + nmap("wa", vim.lsp.buf.add_workspace_folder, "Workspace Add Folder") + nmap("wr", vim.lsp.buf.remove_workspace_folder, "Workspace Remove Folder") nmap("wl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, "[W]orkspace [L]ist Folders") + end, "Workspace List Folders") -- Create a command `:Format` local to the LSP buffer vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_) @@ -66,10 +62,6 @@ return { end -- Enable the following language servers - -- Feel free to add/remove any LSPs that you want here. They will automatically be installed. - -- - -- Add any additional override configuration in the following tables. They will be passed to - -- the `settings` field of the server config. You must look up that documentation yourself. local servers = { bashls = {}, cssls = {}, @@ -79,22 +71,24 @@ return { pyright = {}, rust_analyzer = {}, sqlls = {}, - tsserver = {}, + tsserver = { + init_options = { + preferences = { + disableSuggestions = true, + }, + }, + }, yamlls = {}, lua_ls = { - Lua = { - workspace = { checkThirdParty = false }, - telemetry = { enable = false }, + settigns = { + Lua = { + workspace = { checkThirdParty = false }, + telemetry = { enable = false }, + }, }, }, } - -- Diagnostic keymaps - -- vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { desc = "Go to previous diagnostic message" }) - -- vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { desc = "Go to next diagnostic message" }) - -- vim.keymap.set("n", "e", vim.diagnostic.open_float, { desc = "Open floating diagnostic message" }) - -- vim.keymap.set("n", "q", vim.diagnostic.setloclist, { desc = "Open diagnostics list" }) - -- nvim-cmp supports additional completion capabilities, so broadcast that to servers local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) @@ -108,12 +102,41 @@ return { mason_lspconfig.setup_handlers({ function(server_name) - require("lspconfig")[server_name].setup({ + local _border = "single" + + local default_config = { capabilities = capabilities, on_attach = on_attach, - settings = servers[server_name], - }) + handlers = { + ["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { + border = _border, + }), + ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { + border = _border, + }), + }, + } + + require("lspconfig")[server_name].setup( + vim.tbl_deep_extend("force", default_config, servers[server_name] or {}) + ) end, }) + + vim.diagnostic.config({ + underline = true, + update_in_insert = false, + virtual_text = false, + -- virtual_text = { + -- spacing = 1, + -- source = "if_many", + -- prefix = " ●", + -- suffix = " ", + -- -- this will set set the prefix to a function that returns the diagnostics icon based on the severity + -- -- this only works on a recent 0.10.0 build. Will be set to "●" when not supported + -- -- prefix = "icons", + -- }, + severity_sort = true, + }) end, } diff --git a/config/nvim/lua/aleidk/plugins/lsp_signature.lua b/config/nvim/lua/aleidk/plugins/lsp_signature.lua index dc2e03a..aef9c1b 100644 --- a/config/nvim/lua/aleidk/plugins/lsp_signature.lua +++ b/config/nvim/lua/aleidk/plugins/lsp_signature.lua @@ -1,12 +1,12 @@ return { "ray-x/lsp_signature.nvim", - lazy = false, -- Doesn't work if lazy loaded + event = "VeryLazy", opts = { hint_enable = false, }, keys = { { - "lk", + "lK", vim.lsp.buf.signature_help, desc = "Toggle signature", }, diff --git a/config/nvim/lua/aleidk/plugins/nvim-tree.lua b/config/nvim/lua/aleidk/plugins/nvim-tree.lua index 24dbf4e..a9118ae 100644 --- a/config/nvim/lua/aleidk/plugins/nvim-tree.lua +++ b/config/nvim/lua/aleidk/plugins/nvim-tree.lua @@ -1,6 +1,6 @@ return { "nvim-tree/nvim-tree.lua", - enabled = false, + -- enabled = false, version = "*", dependencies = { "nvim-tree/nvim-web-devicons", @@ -81,7 +81,8 @@ return { vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree }) -- bindings - vim.keymap.set("n", "e", ":NvimTreeToggle", { desc = "Toggle file tree", silent = true }) - vim.keymap.set("n", "", ":NvimTreeToggle", { desc = "Toggle file tree", silent = true }) + -- disabled to discourage the use of this plugin without disabling it + -- vim.keymap.set("n", "e", ":NvimTreeToggle", { desc = "Toggle file tree", silent = true }) + -- vim.keymap.set("n", "", ":NvimTreeToggle", { desc = "Toggle file tree", silent = true }) end, } diff --git a/config/nvim/lua/aleidk/plugins/treesitter.lua b/config/nvim/lua/aleidk/plugins/treesitter.lua index 2c81784..c706927 100644 --- a/config/nvim/lua/aleidk/plugins/treesitter.lua +++ b/config/nvim/lua/aleidk/plugins/treesitter.lua @@ -72,10 +72,11 @@ return { }, config = function(_, opts) require("nvim-treesitter.configs").setup(opts) - vim.cmd([[ - set foldmethod=expr - set foldexpr=nvim_treesitter#foldexpr() - set nofoldenable - ]]) + + vim.opt.foldmethod = "expr" + vim.opt.foldexpr = "nvim_treesitter#foldexpr()" + + -- Uncoment this line to disable auto folding on file open + -- vim.cmd("set nofoldenable") end, }