mirror of
https://github.com/pratiktri/dotfiles.git
synced 2026-02-04 16:41:43 +05:30
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:
@@ -9,42 +9,10 @@
|
|||||||
-- Copy visual section to a line number -> :'<,'>t15 (copies To line 15)
|
-- Copy visual section to a line number -> :'<,'>t15 (copies To line 15)
|
||||||
|
|
||||||
-- Load keymaps & options
|
-- Load keymaps & options
|
||||||
require("config")
|
-- Order matters
|
||||||
|
require("config.options")
|
||||||
-- `:help lazy.nvim.txt` for more info
|
require("config.keymaps")
|
||||||
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
require("core.lazy")
|
||||||
if not (vim.uv or vim.loop).fs_stat(lazypath) then
|
require("core.lsp")
|
||||||
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
|
require("config.filetype-based-keymaps")
|
||||||
local out = vim.fn.system({
|
require("config.autocmd")
|
||||||
"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" } },
|
|
||||||
})
|
|
||||||
|
|||||||
3
common/.config/nvim/lsp/bashls.lua
Normal file
3
common/.config/nvim/lsp/bashls.lua
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
return {
|
||||||
|
filetypes = { "sh", "bash", "zsh" },
|
||||||
|
}
|
||||||
1
common/.config/nvim/lsp/cssls.lua
Normal file
1
common/.config/nvim/lsp/cssls.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
return {}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
return {}
|
||||||
1
common/.config/nvim/lsp/dockerls.lua
Normal file
1
common/.config/nvim/lsp/dockerls.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
return {}
|
||||||
6
common/.config/nvim/lsp/html.lua
Normal file
6
common/.config/nvim/lsp/html.lua
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
return {
|
||||||
|
-- cmd = { ... },
|
||||||
|
-- filetypes = { ... },
|
||||||
|
-- capabilities = {},
|
||||||
|
filetypes = { "html", "twig", "hbs" },
|
||||||
|
}
|
||||||
15
common/.config/nvim/lsp/jsonls.lua
Normal file
15
common/.config/nvim/lsp/jsonls.lua
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
return {
|
||||||
|
-- lazy-load schemastore when needed
|
||||||
|
on_new_config = function(new_config)
|
||||||
|
new_config.settings.json.schemas = new_config.settings.json.schemas or {}
|
||||||
|
vim.list_extend(new_config.settings.json.schemas, require("schemastore").json.schemas())
|
||||||
|
end,
|
||||||
|
settings = {
|
||||||
|
json = {
|
||||||
|
format = {
|
||||||
|
enable = true,
|
||||||
|
},
|
||||||
|
validate = { enable = true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
28
common/.config/nvim/lsp/lua_ls.lua
Normal file
28
common/.config/nvim/lsp/lua_ls.lua
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
return {
|
||||||
|
settings = {
|
||||||
|
typescript = {
|
||||||
|
updateImportOnFileMove = { enabled = "always" },
|
||||||
|
suggest = { completeFunctionCalls = true },
|
||||||
|
inlayHints = {
|
||||||
|
includeInlayParameterNameHints = "all",
|
||||||
|
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
|
||||||
|
includeInlayFunctionParameterTypeHints = true,
|
||||||
|
includeInlayVariableTypeHints = true,
|
||||||
|
includeInlayPropertyDeclarationTypeHints = true,
|
||||||
|
includeInlayFunctionLikeReturnTypeHints = true,
|
||||||
|
includeInlayEnumMemberValueHints = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
javascript = {
|
||||||
|
inlayHints = {
|
||||||
|
includeInlayParameterNameHints = "all",
|
||||||
|
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
|
||||||
|
includeInlayFunctionParameterTypeHints = true,
|
||||||
|
includeInlayVariableTypeHints = true,
|
||||||
|
includeInlayPropertyDeclarationTypeHints = true,
|
||||||
|
includeInlayFunctionLikeReturnTypeHints = true,
|
||||||
|
includeInlayEnumMemberValueHints = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
32
common/.config/nvim/lsp/omnisharp.lua
Normal file
32
common/.config/nvim/lsp/omnisharp.lua
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
return {
|
||||||
|
cmd = { "omnisharp" },
|
||||||
|
handlers = {
|
||||||
|
["textDocument/definition"] = function(...)
|
||||||
|
return require("omnisharp_extended").handler(...)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
enable_roslyn_analyzers = true,
|
||||||
|
organize_imports_on_format = true,
|
||||||
|
enable_import_completion = true,
|
||||||
|
enable_editorconfig_support = true,
|
||||||
|
enable_ms_build_load_projects_on_demand = false,
|
||||||
|
analyze_open_documents_only = false,
|
||||||
|
settings = {
|
||||||
|
dotnet = {
|
||||||
|
server = {
|
||||||
|
useOmnisharpServer = true,
|
||||||
|
useModernNet = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
csharp = {
|
||||||
|
inlayHints = {
|
||||||
|
parameters = {
|
||||||
|
enabled = true,
|
||||||
|
},
|
||||||
|
types = {
|
||||||
|
enabled = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
1
common/.config/nvim/lsp/pylsp.lua
Normal file
1
common/.config/nvim/lsp/pylsp.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
return {}
|
||||||
1
common/.config/nvim/lsp/rust_analyzer.lua
Normal file
1
common/.config/nvim/lsp/rust_analyzer.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
return {}
|
||||||
1
common/.config/nvim/lsp/sqlls.lua
Normal file
1
common/.config/nvim/lsp/sqlls.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
return {}
|
||||||
28
common/.config/nvim/lsp/ts_ls.lua
Normal file
28
common/.config/nvim/lsp/ts_ls.lua
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
return {
|
||||||
|
settings = {
|
||||||
|
typescript = {
|
||||||
|
updateImportOnFileMove = { enabled = "always" },
|
||||||
|
suggest = { completeFunctionCalls = true },
|
||||||
|
inlayHints = {
|
||||||
|
includeInlayParameterNameHints = "all",
|
||||||
|
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
|
||||||
|
includeInlayFunctionParameterTypeHints = true,
|
||||||
|
includeInlayVariableTypeHints = true,
|
||||||
|
includeInlayPropertyDeclarationTypeHints = true,
|
||||||
|
includeInlayFunctionLikeReturnTypeHints = true,
|
||||||
|
includeInlayEnumMemberValueHints = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
javascript = {
|
||||||
|
inlayHints = {
|
||||||
|
includeInlayParameterNameHints = "all",
|
||||||
|
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
|
||||||
|
includeInlayFunctionParameterTypeHints = true,
|
||||||
|
includeInlayVariableTypeHints = true,
|
||||||
|
includeInlayPropertyDeclarationTypeHints = true,
|
||||||
|
includeInlayFunctionLikeReturnTypeHints = true,
|
||||||
|
includeInlayEnumMemberValueHints = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
require("config.keymaps")
|
|
||||||
require("config.options")
|
|
||||||
require("config.autocmd")
|
|
||||||
require("config.filetype-based-keymaps")
|
|
||||||
require("config.vim_plugin_config")
|
|
||||||
@@ -12,7 +12,7 @@ local M = {
|
|||||||
BreakpointRejected = { " ", "DiagnosticError" },
|
BreakpointRejected = { " ", "DiagnosticError" },
|
||||||
LogPoint = ".>",
|
LogPoint = ".>",
|
||||||
},
|
},
|
||||||
diagnostics = { Error = " ", Warn = " ", Hint = " ", Info = " " },
|
diagnostics = { ERROR = " ", WARN = " ", HINT = " ", INFO = " " },
|
||||||
git = { added = " ", modified = " ", removed = " " },
|
git = { added = " ", modified = " ", removed = " " },
|
||||||
kinds = {
|
kinds = {
|
||||||
Array = " ",
|
Array = " ",
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
-- Load Plugin configs from VIM
|
|
||||||
local vim_plugin_config = os.getenv("HOME") .. "/.vim/plugin_config.vim"
|
|
||||||
if vim.loop.fs_stat(vim_plugin_config) then
|
|
||||||
vim.cmd("source " .. vim_plugin_config)
|
|
||||||
end
|
|
||||||
37
common/.config/nvim/lua/core/lazy.lua
Normal file
37
common/.config/nvim/lua/core/lazy.lua
Normal 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" } },
|
||||||
|
})
|
||||||
134
common/.config/nvim/lua/core/lsp.lua
Normal file
134
common/.config/nvim/lua/core/lsp.lua
Normal 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 },
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -1,278 +1,29 @@
|
|||||||
return {
|
return {
|
||||||
{
|
{
|
||||||
-- Main LSP Configuration
|
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
cond = require("config.util").is_not_vscode(),
|
cond = require("config.util").is_not_vscode(),
|
||||||
dependencies = {
|
dependencies = {
|
||||||
{ "williamboman/mason.nvim", config = true }, -- NOTE: Must be loaded before dependants
|
{ "williamboman/mason.nvim", config = true }, -- NOTE: Must be loaded before dependants
|
||||||
"williamboman/mason-lspconfig.nvim",
|
"williamboman/mason-lspconfig.nvim",
|
||||||
"WhoIsSethDaniel/mason-tool-installer.nvim",
|
"WhoIsSethDaniel/mason-tool-installer.nvim",
|
||||||
|
|
||||||
-- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
|
|
||||||
{ "j-hui/fidget.nvim", opts = {} },
|
|
||||||
|
|
||||||
"saghen/blink.cmp",
|
"saghen/blink.cmp",
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
-- Every time a new file is opened that is associated with
|
local servers = {}
|
||||||
-- an lsp this function will be executed to configure the current buffer
|
|
||||||
vim.api.nvim_create_autocmd("LspAttach", {
|
|
||||||
group = vim.api.nvim_create_augroup("lsp-attach", { clear = true }),
|
|
||||||
callback = function(event)
|
|
||||||
local map = function(keys, func, desc, mode)
|
|
||||||
mode = mode or "n"
|
|
||||||
vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = "LSP: " .. desc })
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Lspsaga Keymaps
|
|
||||||
-- Hover Documentation
|
|
||||||
-- Press K 2 times to jump into the hover window
|
|
||||||
-- Place cursor on "View Documentation" gx -> Open the docs on browser
|
|
||||||
map("K", "<cmd>Lspsaga hover_doc<cr>", "Hover Documentation")
|
|
||||||
map("<F2>", vim.lsp.buf.rename, "Rename Symbol")
|
|
||||||
|
|
||||||
map("<C-.>", "<cmd>Lspsaga code_action<cr>", "Code Actions")
|
|
||||||
map("<leader>ca", "<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")
|
|
||||||
|
|
||||||
-- Jump to the definition of the word under your cursor.
|
|
||||||
-- This is where a variable was first declared, or where a function is defined, etc.
|
|
||||||
-- To jump back, press <C-t>.
|
|
||||||
map("gd", require("telescope.builtin").lsp_definitions, "[G]oto [D]efinition")
|
|
||||||
map("<F12>", require("telescope.builtin").lsp_definitions, "[G]oto [D]efinition")
|
|
||||||
|
|
||||||
map("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration")
|
|
||||||
|
|
||||||
map("gI", require("telescope.builtin").lsp_implementations, "[G]oto [I]mplementation")
|
|
||||||
map("<leader>ci", require("telescope.builtin").lsp_implementations, "Goto Implementation")
|
|
||||||
|
|
||||||
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")
|
|
||||||
-- e to jump to the symbol under cursor; q to quit
|
|
||||||
map("<leader>co", "<cmd>Lspsaga outline<cr>", "Outline Panel on Left")
|
|
||||||
|
|
||||||
map("<leader>cd", require("telescope.builtin").diagnostics, "List Diagnostics")
|
|
||||||
|
|
||||||
map("<leader>nf", function()
|
|
||||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
|
||||||
end, "Workspace Folders on Notification")
|
|
||||||
|
|
||||||
-- The following two autocommands are used to highlight references of the
|
|
||||||
-- word under your cursor when your cursor rests there for a little while.
|
|
||||||
-- When you move your cursor, the highlights will be cleared
|
|
||||||
local client = vim.lsp.get_client_by_id(event.data.client_id)
|
|
||||||
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 = { ERROR = "", WARN = "", INFO = "", HINT = "" }
|
|
||||||
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
|
|
||||||
|
|
||||||
-- Enable the following language servers
|
|
||||||
-- Available keys are:
|
|
||||||
-- - cmd (table): Override the default command used to start the server
|
|
||||||
-- - filetypes (table): Override the default list of associated filetypes for the server
|
|
||||||
-- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features.
|
|
||||||
-- - settings (table): Override the default settings passed when initializing the server.
|
|
||||||
local servers = {
|
|
||||||
html = {
|
|
||||||
-- cmd = { ... },
|
|
||||||
-- filetypes = { ... },
|
|
||||||
-- capabilities = {},
|
|
||||||
filetypes = { "html", "twig", "hbs" },
|
|
||||||
},
|
|
||||||
cssls = {},
|
|
||||||
jsonls = {
|
|
||||||
-- lazy-load schemastore when needed
|
|
||||||
on_new_config = function(new_config)
|
|
||||||
new_config.settings.json.schemas = new_config.settings.json.schemas or {}
|
|
||||||
vim.list_extend(new_config.settings.json.schemas, require("schemastore").json.schemas())
|
|
||||||
end,
|
|
||||||
settings = {
|
|
||||||
json = {
|
|
||||||
format = {
|
|
||||||
enable = true,
|
|
||||||
},
|
|
||||||
validate = { enable = true },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
bashls = { filetypes = { "sh", "bash", "zsh" } },
|
|
||||||
pylsp = {},
|
|
||||||
lua_ls = {
|
|
||||||
settings = {
|
|
||||||
Lua = {
|
|
||||||
workspace = { checkThirdParty = false },
|
|
||||||
telemetry = { enable = false },
|
|
||||||
completion = { callSnippet = "Replace" },
|
|
||||||
hint = { enable = true },
|
|
||||||
diagnostics = { disable = { "missing-fields" } },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
omnisharp = {
|
|
||||||
cmd = { "omnisharp" },
|
|
||||||
handlers = {
|
|
||||||
["textDocument/definition"] = function(...)
|
|
||||||
return require("omnisharp_extended").handler(...)
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
enable_roslyn_analyzers = true,
|
|
||||||
organize_imports_on_format = true,
|
|
||||||
enable_import_completion = true,
|
|
||||||
enable_editorconfig_support = true,
|
|
||||||
enable_ms_build_load_projects_on_demand = false,
|
|
||||||
analyze_open_documents_only = false,
|
|
||||||
settings = {
|
|
||||||
dotnet = {
|
|
||||||
server = {
|
|
||||||
useOmnisharpServer = true,
|
|
||||||
useModernNet = true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
csharp = {
|
|
||||||
inlayHints = {
|
|
||||||
parameters = {
|
|
||||||
enabled = true,
|
|
||||||
},
|
|
||||||
types = {
|
|
||||||
enabled = true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
ts_ls = {
|
|
||||||
settings = {
|
|
||||||
typescript = {
|
|
||||||
updateImportOnFileMove = { enabled = "always" },
|
|
||||||
suggest = { completeFunctionCalls = true },
|
|
||||||
inlayHints = {
|
|
||||||
includeInlayParameterNameHints = "all",
|
|
||||||
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
|
|
||||||
includeInlayFunctionParameterTypeHints = true,
|
|
||||||
includeInlayVariableTypeHints = true,
|
|
||||||
includeInlayPropertyDeclarationTypeHints = true,
|
|
||||||
includeInlayFunctionLikeReturnTypeHints = true,
|
|
||||||
includeInlayEnumMemberValueHints = true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
javascript = {
|
|
||||||
inlayHints = {
|
|
||||||
includeInlayParameterNameHints = "all",
|
|
||||||
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
|
|
||||||
includeInlayFunctionParameterTypeHints = true,
|
|
||||||
includeInlayVariableTypeHints = true,
|
|
||||||
includeInlayPropertyDeclarationTypeHints = true,
|
|
||||||
includeInlayFunctionLikeReturnTypeHints = true,
|
|
||||||
includeInlayEnumMemberValueHints = true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
sqlls = {},
|
|
||||||
dockerls = {},
|
|
||||||
docker_compose_language_service = {},
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Ensure the servers and tools above are installed
|
|
||||||
require("mason").setup()
|
|
||||||
|
|
||||||
-- Add completion capabilities
|
|
||||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
|
|
||||||
-- TODO: Remove this when we get neovim 0.11
|
-- NOTE: `nvim-lspconfig` has default LSP configs in its DB which saves time
|
||||||
capabilities = require("blink.cmp").get_lsp_capabilities(capabilities)
|
-- Useful even after NeoVim 0.11, which made LSP setup much easier
|
||||||
|
-- Configs in `nvim/lsp/*` are APPENDED to each LSP setup here
|
||||||
-- Add other (other than LSP servers) tools here that you want Mason to install for you
|
|
||||||
-- Which means: formatters and debuggers
|
|
||||||
local ensure_installed = vim.tbl_keys(servers or {})
|
|
||||||
vim.list_extend(ensure_installed, {
|
|
||||||
"black", -- Python formatter
|
|
||||||
"csharpier", -- C# formatter
|
|
||||||
"djlint", -- Handlebar Formatter
|
|
||||||
"markdown-toc",
|
|
||||||
"markdownlint",
|
|
||||||
"netcoredbg", -- C# Debugger
|
|
||||||
"prettier",
|
|
||||||
"prettierd",
|
|
||||||
"shellharden",
|
|
||||||
"shfmt",
|
|
||||||
"stylua",
|
|
||||||
"trivy", -- Vulnerability Linter
|
|
||||||
"yamlfmt",
|
|
||||||
})
|
|
||||||
|
|
||||||
-- TODO: Remove all installations through Mason
|
|
||||||
-- i.e. Remove mason.nvim, mason-lspconfig and mason-tool-installer
|
|
||||||
-- We should install those globally on the system
|
|
||||||
-- That would make it easier to work with on FreeBSD
|
|
||||||
require("mason-tool-installer").setup({ ensure_installed = ensure_installed })
|
|
||||||
|
|
||||||
---@diagnostic disable-next-line: missing-fields
|
|
||||||
require("mason-lspconfig").setup({
|
require("mason-lspconfig").setup({
|
||||||
handlers = {
|
handlers = {
|
||||||
function(server_name)
|
function(server_name)
|
||||||
local server = servers[server_name] or {}
|
local server = servers[server_name] or {}
|
||||||
-- This handles overriding only values explicitly passed
|
|
||||||
-- by the server configuration above. Useful when disabling
|
|
||||||
-- certain features of an LSP (for example, turning off formatting for ts_ls)
|
|
||||||
server.capabilities = vim.tbl_deep_extend("force", {}, capabilities, server.capabilities or {})
|
server.capabilities = vim.tbl_deep_extend("force", {}, capabilities, server.capabilities or {})
|
||||||
server.inlay_hints = { enabled = true }
|
server.inlay_hints = { enabled = true }
|
||||||
server.diagnostics = {
|
server.diagnostics = {
|
||||||
underline = true,
|
underline = true,
|
||||||
update_in_insert = false,
|
update_in_insert = false,
|
||||||
virtual_text = {
|
|
||||||
spacing = 4,
|
|
||||||
source = "if_many",
|
|
||||||
prefix = "●",
|
|
||||||
},
|
|
||||||
severity_sort = true,
|
severity_sort = true,
|
||||||
}
|
}
|
||||||
require("lspconfig")[server_name].setup(server)
|
require("lspconfig")[server_name].setup(server)
|
||||||
|
|||||||
@@ -252,10 +252,10 @@ return {
|
|||||||
{
|
{
|
||||||
"diagnostics",
|
"diagnostics",
|
||||||
symbols = {
|
symbols = {
|
||||||
error = config.icons.diagnostics.Error,
|
error = config.icons.diagnostics.ERROR,
|
||||||
warn = config.icons.diagnostics.Warn,
|
warn = config.icons.diagnostics.WARN,
|
||||||
info = config.icons.diagnostics.Info,
|
info = config.icons.diagnostics.INFO,
|
||||||
hint = config.icons.diagnostics.Hint,
|
hint = config.icons.diagnostics.HINT,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user