-- TIP: Setup a new LSP: -- Step 1: Install the LSP through: -- OS Installer > Brew-linux > :MasonInstall -- Step 2: Append the LSP server name in the below array ("newlsp") -- Step 3: Create file ("newlsp.lua") in ../../lsp/ -- Step 4: Return a lua table containing required lsp config in it -- NOTE: Only LSPs here, NOT linters or formatter vim.lsp.enable({ "awk_ls", "basedpyright", "bashls", "cssls", "docker_compose_language_service", "dockerls", "html", "jsonls", "lua_ls", "marksman", "taplo", "trivy", "ts_ls", "yamlls", }) -- Setup native diagnostic vim.diagnostic.config({ underline = false, update_in_insert = false, severity_sort = true, float = { border = "rounded", source = true, }, virtual_text = { enabled = true, severity = { min = vim.diagnostic.severity.ERROR }, }, }) -- Change diagnostic symbols in the sign column (gutter) if vim.g.have_nerd_font then local signs = require("config.util").icons.diagnostics local diagnostic_signs = {} for type, icon in pairs(signs) do diagnostic_signs[vim.diagnostic.severity[type]] = icon end vim.diagnostic.config({ signs = { text = diagnostic_signs } }) end vim.api.nvim_create_autocmd("LspAttach", { group = vim.api.nvim_create_augroup("lsp-attach", { clear = true }), callback = function(event) local client = vim.lsp.get_client_by_id(event.data.client_id) -- Generic Keymaps local map = function(keys, func, desc, mode) mode = mode or "n" vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = "LSP: " .. desc }) end map("", vim.lsp.buf.rename, "Rename Symbol") map("cR", vim.lsp.buf.rename, "Rename Symbol") map("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") -- LspSaga map("", "Lspsaga code_action", "Code Actions") map("K", "Lspsaga hover_doc", "Hover Documentation") map("cr", "Lspsaga finder", "Goto References") map("cF", "Lspsaga peek_definition", "Peek definition: Function") map("cT", "Lspsaga peek_type_definition", "Peek definition: Type") map("cI", "Lspsaga finder imp", "Peek: Implementations") -- e to jump to the symbol under cursor; q to quit map("co", "Lspsaga outline", "Outline Panel on Left") -- Telescope map("gI", require("telescope.builtin").lsp_implementations, "[G]oto [I]mplementation") map("cs", require("telescope.builtin").lsp_document_symbols, "Search Document Symbols") map("cS", require("telescope.builtin").lsp_workspace_symbols, "Search Workspace Symbols") map("ct", require("telescope.builtin").lsp_type_definitions, "Goto Type Definition") Snacks.toggle({ name = "Diagnostics Virtual Text", get = function() return vim.diagnostic.config().virtual_text ~= false end, set = function(state) vim.diagnostic.config({ virtual_text = state }) end, }):map("dx") -- Native lsp inline virtual text / inlay hints if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then vim.lsp.inlay_hint.enable(true) vim.api.nvim_set_hl(0, "LspInlayHint", { fg = "#5c7086", bg = "NONE" }) map("ch", function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf })) end, "Toggle Inlay Hints") end end, })