-- import lspconfig plugin safely local lspconfig_status, lspconfig = pcall(require, "lspconfig") if not lspconfig_status then 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 end -- import typescript plugin safely local typescript_setup, typescript = pcall(require, "typescript") if not typescript_setup then return end local keymap = vim.keymap -- enable keybinds only for when lsp server available local on_attach = function(client, bufnr) -- keybind options local opts = { noremap = true, silent = true, buffer = bufnr } -- set keybinds keymap.set("n", "gf", "lua vim.lsp.buf.hover()", opts) -- show definition -- 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", "b", "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", "y", "Lspsaga finder", opts) -- find refs elsewhere in project end -- used to enable autocompletion (assign to every lsp server config) local capabilities = cmp_nvim_lsp.default_capabilities() -- Change the Diagnostic symbols in the sign column (gutter) -- 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 -- Hide diagnostic virtual text by default, but toggle visibility with `lead:lh` command vim.diagnostic.config({ virtual_text = false, }) vim.keymap.set("n", "lh", function() local config = vim.diagnostic.config() vim.diagnostic.config({ virtual_text = not config.virtual_text }) print("Toggling LSP diagnostics") end) -- configure html server lspconfig["html"].setup({ capabilities = capabilities, on_attach = on_attach, }) --configure typescript server with plugin lspconfig["ts_ls"].setup({ server = { capabilities = capabilities, on_attach = on_attach, }, }) -- configure css server lspconfig["cssls"].setup({ capabilities = capabilities, on_attach = on_attach, }) -- configure tailwindcss server lspconfig["tailwindcss"].setup({ capabilities = capabilities, on_attach = on_attach, }) -- configure python server lspconfig["pyright"].setup({ capabilities = capabilities, on_attach = on_attach, })