From 0a169785437bab8a4ad20b1891336fb831f11fa0 Mon Sep 17 00:00:00 2001 From: David Ibia Date: Sun, 14 Jan 2024 22:09:19 +0100 Subject: [PATCH] refactor(lsp-config.lua): clean up code formatting and improve readability feat(lsp-config.lua): add key mappings for LSP commands to improve productivity feat(lsp-config.lua): configure additional language servers for HTML, Emmet, Pylsp, Jedi, Docker, JSON, Vue, and Rust refactor(lsp-config.lua): remove unnecessary comments and blank lines --- lua/absolute/after/lsp-config.lua | 49 +++++++++++++------------------ 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/lua/absolute/after/lsp-config.lua b/lua/absolute/after/lsp-config.lua index 48b8b73..0bb74d0 100644 --- a/lua/absolute/after/lsp-config.lua +++ b/lua/absolute/after/lsp-config.lua @@ -1,29 +1,28 @@ -- Setup language servers. -local lspconfig = require('lspconfig') +local lspconfig = require("lspconfig") local cmp_nvim_lsp = require("cmp_nvim_lsp") -local opts = { noremap = true, silent = true } -local on_attach = function(client, bufnr) +local opts = { noremap = true, silent = true } +local on_attach = function(_client, bufnr) opts.buffer = bufnr -- Enable completion triggered by -- vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' - opts.desc = "Go to declaration" - vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) opts.desc = "Go to definitions" - vim.keymap.set('n', 'gd', "Telescope lsp_definitions", opts) + vim.keymap.set("n", "gd", "Telescope lsp_definitions", opts) opts.desc = "Show documentation for what is under cursor" - vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) opts.desc = "Show LSP Implementation" - vim.keymap.set('n', 'gi', "Telescope lsp_implementations", opts) + vim.keymap.set("n", "gi", "Telescope lsp_implementations", opts) opts.desc = "Get Help" - vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) + vim.keymap.set("n", "", vim.lsp.buf.signature_help, opts) -- vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) -- vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts) @@ -32,20 +31,20 @@ local on_attach = function(client, bufnr) -- end, opts) opts.desc = "Show LSP type definitions" - vim.keymap.set('n', 'gt', "Telescope lsp_type_definitions", opts) + vim.keymap.set("n", "gt", "Telescope lsp_type_definitions", opts) opts.desc = "Smart rename" - vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) + vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) opts.desc = "See available code actions" - vim.keymap.set({ 'n', 'v' }, 'vca', vim.lsp.buf.code_action, opts) + vim.keymap.set({ "n", "v" }, "vca", vim.lsp.buf.code_action, opts) opts.desc = "Show LSP references" - vim.keymap.set('n', 'vrr', "Telescope lsp_references", opts) + vim.keymap.set("n", "vrr", "Telescope lsp_references", opts) opts.desc = "Format File" - vim.keymap.set('n', 'f', function() - vim.lsp.buf.format { async = true } + vim.keymap.set("n", "f", function() + vim.lsp.buf.format({ async = true }) end, opts) opts.desc = "Restart LSP" @@ -55,13 +54,12 @@ end local capabilities = cmp_nvim_lsp.default_capabilities() -- Change the Diagnostic symbols in the sign column (gutter) -local signs = { Error = " ", Warn = " ", Hint = "󰠠 ", Info = " " } +local signs = { Error = " ", Warn = " ", Hint = "󰠠 ", Info = " " } for type, icon in pairs(signs) do local hl = "DiagnosticSign" .. type vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) end - -- configure html server lspconfig["html"].setup({ capabilities = capabilities, @@ -103,7 +101,6 @@ lspconfig["svelte"].setup({ end, }) - -- configure emmet language server lspconfig["emmet_ls"].setup({ capabilities = capabilities, @@ -118,11 +115,10 @@ lspconfig["pylsp"].setup({ pylsp = { plugins = { jedi_completion = { - include_params = true - } - } - - } + include_params = true, + }, + }, + }, }) -- configure jedi language server @@ -131,7 +127,6 @@ lspconfig["jedi_language_server"].setup({ on_attach = on_attach, }) - -- configure docker server lspconfig["dockerls"].setup({ capabilities = capabilities, @@ -144,7 +139,6 @@ lspconfig["jsonls"].setup({ on_attach = on_attach, }) - -- configure vue server lspconfig["volar"].setup({ capabilities = capabilities, @@ -158,12 +152,10 @@ lspconfig.rust_analyzer.setup({ on_attach = on_attach, capabilities = capabilities, settings = { - ['rust-analyzer'] = {}, + ["rust-analyzer"] = {}, }, }) - - -- configure lua server (with special settings) lspconfig["lua_ls"].setup({ capabilities = capabilities, @@ -185,7 +177,6 @@ lspconfig["lua_ls"].setup({ }, }) - -- configure css server lspconfig["cssls"].setup({ capabilities = capabilities,