feat(nvim): v0.11: Use native LSP, Completion, Diagnostics

- Move all language LSP configurations to `nvim/lsp`
- Move nvim LSP configurations to `nvim/lua/core`
- Remove LSP attach keymaps where default ones exists and are usable
- Reorged LSP attach keymaps per plugin
- Move Lazy.nvim configurations to `nvim/lua/core`
- `nvim/init.lua` cleaned to only load other files
- Uniform diagnostics symbols across lualine & gutter
This commit is contained in:
Pratik Tripathy
2025-07-25 21:57:45 +05:30
parent 3bea86537a
commit 1e5509daaa
20 changed files with 305 additions and 307 deletions

View File

@@ -0,0 +1,37 @@
-- `:help lazy.nvim.txt` for more info
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"--branch=stable",
lazyrepo,
lazypath,
})
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
---@diagnostic disable-next-line: undefined-field
vim.opt.rtp:prepend(lazypath)
-- You can also configure plugins after the setup call,
-- as they will be available in your neovim runtime.
require("lazy").setup({
change_detection = {
notify = false,
},
build = {
warn_on_override = true,
},
spec = { { import = "plugins" } },
})

View File

@@ -0,0 +1,134 @@
vim.lsp.enable({
"bashls",
"cssls",
"docker_compose_language_service",
"dockerls",
"html",
"jsonls",
"lua_ls",
"omnisharp",
"pylsp",
"rust_analyzer",
"sqlls",
"ts_ls",
-- TODO: Enable inlay_hints for all of them
})
-- TIP: On new systems, install these through Mason
---@diagnostic disable-next-line: unused-local
local to_installed = vim.tbl_keys({
"black", -- Python formatter
"csharpier", -- C# formatter
"djlint", -- Handlebar Formatter
"markdown-toc",
"markdownlint",
"netcoredbg", -- C# Debugger
"prettier",
"prettierd",
"shellharden",
"shfmt",
"stylua",
"trivy", -- Vulnerability Linter
"yamlfmt",
})
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)
-- Setup LSP completion
-- This is already done by blink, but better prefer the builtin one
if client:supports_method("textDocument/completion") then
vim.opt.completeopt = { "menu", "menuone", "noinsert", "fuzzy", "popup" }
vim.lsp.completion.enable(true, client.id, event.buf, { autotrigger = true })
vim.keymap.set("i", "<C-Space>", function()
vim.lsp.completion.get()
end)
end
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("<F2>", vim.lsp.buf.rename, "Rename Symbol")
map("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration")
map("<leader>nf", function()
vim.fn.setreg("+", vim.fn.expand("%:p"))
print("Copied: " .. vim.fn.expand("%:p") .. " to + register")
end, "Copy current [F]ile path to register")
-- LspSaga
map("<C-.>", "<cmd>Lspsaga code_action<cr>", "Code Actions")
map("<leader>cr", "<cmd>Lspsaga finder<cr>", "Goto References")
map("<leader>cpf", "<cmd>Lspsaga peek_definition<cr>", "Peek definition: Function")
map("<leader>cpt", "<cmd>Lspsaga peek_type_definition<cr>", "Peek definition: Class")
map("<leader>cpi", "<cmd>Lspsaga finder imp<cr>", "Peek: Implementations")
-- e to jump to the symbol under cursor; q to quit
map("<leader>co", "<cmd>Lspsaga outline<cr>", "Outline Panel on Left")
-- Telescope
map("gI", require("telescope.builtin").lsp_implementations, "[G]oto [I]mplementation")
map("<leader>cs", require("telescope.builtin").lsp_document_symbols, "Search Document Symbols")
map("<leader>cS", require("telescope.builtin").lsp_dynamic_workspace_symbols, "Search Workspace Symbols")
map("<leader>ct", require("telescope.builtin").lsp_type_definitions, "Goto Type Definition")
map("<leader>cd", require("telescope.builtin").diagnostics, "List Diagnostics")
-- The following two autocommands are used to highlight references of the
-- word under cursor when cursor rests there for a little while.
if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then
local highlight_augroup = vim.api.nvim_create_augroup("kickstart-lsp-highlight", { clear = false })
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
buffer = event.buf,
group = highlight_augroup,
callback = vim.lsp.buf.document_highlight,
})
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
buffer = event.buf,
group = highlight_augroup,
callback = vim.lsp.buf.clear_references,
})
vim.api.nvim_create_autocmd("LspDetach", {
group = vim.api.nvim_create_augroup("kickstart-lsp-detach", { clear = true }),
callback = function(event2)
vim.lsp.buf.clear_references()
vim.api.nvim_clear_autocmds({ group = "kickstart-lsp-highlight", buffer = event2.buf })
end,
})
end
-- 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() -- enabled by default
map("<leader>cI", function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf }))
end, "Toggle Inlay Hints")
end
end,
})
-- 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.diagnostic.config({
virtual_text = {
enabled = true,
spacing = 5,
severity = { min = vim.diagnostic.severity.ERROR },
},
virtual_lines = {
current_line = true,
severity = { min = vim.diagnostic.severity.INFO },
},
})