diff --git a/nvim/lua/blakeridgway/plugins/lsp/lspconfig.lua b/nvim/lua/blakeridgway/plugins/lsp/lspconfig.lua index 78b94a3..e5a29a5 100644 --- a/nvim/lua/blakeridgway/plugins/lsp/lspconfig.lua +++ b/nvim/lua/blakeridgway/plugins/lsp/lspconfig.lua @@ -1,48 +1,48 @@ -- import lspconfig plugin safely local lspconfig_status, lspconfig = pcall(require, "lspconfig") if not lspconfig_status then - return + return end -- import cmp-nvim-lsp plugin safely local cmp_nvim_lsp_status, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") if not cmp_nvim_lsp_status then - return + return end -- import typescript plugin safely local typescript_setup, typescript = pcall(require, "typescript") if not typescript_setup then - return + return end local keymap = vim.keymap -- for conciseness -- enable keybinds only for when lsp server available local on_attach = function(client, bufnr) - -- keybind options - local opts = { noremap = true, silent = true, buffer = bufnr } + -- keybind options + local opts = { noremap = true, silent = true, buffer = bufnr } - -- set keybinds - keymap.set("n", "gf", "Lspsaga lsp_finder", opts) -- show definition, references - keymap.set("n", "gD", "lua vim.lsp.buf.declaration()", opts) -- got to declaration - keymap.set("n", "gd", "Lspsaga peek_definition", opts) -- see definition and make edits in window - keymap.set("n", "gi", "lua vim.lsp.buf.implementation()", opts) -- go to implementation - keymap.set("n", "ca", "Lspsaga code_action", opts) -- see available code actions - keymap.set("n", "rn", "Lspsaga rename", opts) -- smart rename - keymap.set("n", "D", "Lspsaga show_line_diagnostics", opts) -- show diagnostics for line - keymap.set("n", "d", "Lspsaga show_cursor_diagnostics", opts) -- show diagnostics for cursor - keymap.set("n", "[d", "Lspsaga diagnostic_jump_prev", opts) -- jump to previous diagnostic in buffer - keymap.set("n", "]d", "Lspsaga diagnostic_jump_next", opts) -- jump to next diagnostic in buffer - keymap.set("n", "K", "Lspsaga hover_doc", opts) -- show documentation for what is under cursor - keymap.set("n", "o", "LSoutlineToggle", opts) -- see outline on right hand side + -- set keybinds + keymap.set("n", "gf", "Lspsaga lsp_finder", opts) -- show definition, references + keymap.set("n", "gD", "lua vim.lsp.buf.declaration()", opts) -- got to declaration + keymap.set("n", "gd", "Lspsaga peek_definition", opts) -- see definition and make edits in window + keymap.set("n", "gi", "lua vim.lsp.buf.implementation()", opts) -- go to implementation + keymap.set("n", "ca", "Lspsaga code_action", opts) -- see available code actions + keymap.set("n", "rn", "Lspsaga rename", opts) -- smart rename + keymap.set("n", "D", "Lspsaga show_line_diagnostics", opts) -- show diagnostics for line + keymap.set("n", "d", "Lspsaga show_cursor_diagnostics", opts) -- show diagnostics for cursor + keymap.set("n", "[d", "Lspsaga diagnostic_jump_prev", opts) -- jump to previous diagnostic in buffer + keymap.set("n", "]d", "Lspsaga diagnostic_jump_next", opts) -- jump to next diagnostic in buffer + keymap.set("n", "K", "Lspsaga hover_doc", opts) -- show documentation for what is under cursor + keymap.set("n", "o", "LSoutlineToggle", opts) -- see outline on right hand side - -- typescript specific keymaps (e.g. rename file and update imports) - if client.name == "tsserver" then - keymap.set("n", "rf", ":TypescriptRenameFile") -- rename file and update imports - keymap.set("n", "oi", ":TypescriptOrganizeImports") -- organize imports (not in youtube nvim video) - keymap.set("n", "ru", ":TypescriptRemoveUnused") -- remove unused variables (not in youtube nvim video) - end + -- typescript specific keymaps (e.g. rename file and update imports) + if client.name == "tsserver" then + keymap.set("n", "rf", ":TypescriptRenameFile") -- rename file and update imports + keymap.set("n", "oi", ":TypescriptOrganizeImports") -- organize imports (not in youtube nvim video) + keymap.set("n", "ru", ":TypescriptRemoveUnused") -- remove unused variables (not in youtube nvim video) + end end -- used to enable autocompletion (assign to every lsp server config) @@ -52,60 +52,60 @@ local capabilities = cmp_nvim_lsp.default_capabilities() -- (not in youtube nvim video) 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 = "" }) + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) end -- configure html server lspconfig["html"].setup({ - capabilities = capabilities, - on_attach = on_attach, + capabilities = capabilities, + on_attach = on_attach, }) -- configure typescript server with plugin typescript.setup({ - server = { - capabilities = capabilities, - on_attach = on_attach, - }, + server = { + capabilities = capabilities, + on_attach = on_attach, + }, }) -- configure css server lspconfig["cssls"].setup({ - capabilities = capabilities, - on_attach = on_attach, + capabilities = capabilities, + on_attach = on_attach, }) -- configure tailwindcss server lspconfig["tailwindcss"].setup({ - capabilities = capabilities, - on_attach = on_attach, + capabilities = capabilities, + on_attach = on_attach, }) -- configure emmet language server lspconfig["emmet_ls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" }, + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" }, }) -- configure lua server (with special settings) -lspconfig["sumneko_lua"].setup({ - capabilities = capabilities, - on_attach = on_attach, - settings = { -- custom settings for lua - Lua = { - -- make the language server recognize "vim" global - diagnostics = { - globals = { "vim" }, - }, - workspace = { - -- make language server aware of runtime files - library = { - [vim.fn.expand("$VIMRUNTIME/lua")] = true, - [vim.fn.stdpath("config") .. "/lua"] = true, - }, - }, - }, - }, +lspconfig["lua_ls"].setup({ + capabilities = capabilities, + on_attach = on_attach, + settings = { -- custom settings for lua + Lua = { + -- make the language server recognize "vim" global + diagnostics = { + globals = { "vim" }, + }, + workspace = { + -- make language server aware of runtime files + library = { + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.stdpath("config") .. "/lua"] = true, + }, + }, + }, + }, })