113 lines
3.2 KiB
Lua
113 lines
3.2 KiB
Lua
return {
|
|
"neovim/nvim-lspconfig",
|
|
event = { "BufReadPre", "BufNewFile" },
|
|
dependencies = {
|
|
"hrsh7th/cmp-nvim-lsp",
|
|
"williamboman/mason.nvim",
|
|
"nvim-telescope/telescope.nvim",
|
|
},
|
|
config = function()
|
|
local lspconfig = require("lspconfig")
|
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
|
|
|
vim.diagnostic.config({
|
|
virtual_text = { spacing = 4, prefix = "●" },
|
|
signs = true,
|
|
update_in_insert = false,
|
|
underline = true,
|
|
severity_sort = true,
|
|
float = { border = "rounded", source = "always" },
|
|
})
|
|
|
|
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 = hl })
|
|
end
|
|
|
|
local on_attach = function(client, bufnr)
|
|
local opts = { buffer = bufnr, silent = true }
|
|
local telescope_builtin = require("telescope.builtin")
|
|
|
|
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
|
vim.keymap.set("n", "gd", telescope_builtin.lsp_definitions, opts)
|
|
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
|
|
vim.keymap.set("n", "gi", telescope_builtin.lsp_implementations, opts)
|
|
vim.keymap.set("n", "gr", telescope_builtin.lsp_references, opts)
|
|
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
|
|
vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts)
|
|
vim.keymap.set("n", "<leader>D", telescope_builtin.lsp_type_definitions, opts)
|
|
vim.keymap.set("n", "<leader>sh", vim.lsp.buf.signature_help, opts)
|
|
vim.keymap.set("n", "<leader>ls", telescope_builtin.lsp_document_symbols, opts)
|
|
vim.keymap.set("n", "<leader>lw", telescope_builtin.lsp_workspace_symbols, opts)
|
|
vim.keymap.set("n", "<leader>ld", telescope_builtin.diagnostics, opts)
|
|
|
|
if client.supports_method("textDocument/formatting") then
|
|
vim.keymap.set("n", "<leader>fm", function()
|
|
vim.lsp.buf.format({ async = true })
|
|
end, opts)
|
|
end
|
|
|
|
if client.name == "clangd" then
|
|
vim.keymap.set("n", "<leader>l", "<cmd>ClangdSwitchSourceHeader<CR>", opts)
|
|
end
|
|
end
|
|
|
|
local handlers = {
|
|
function(server_name)
|
|
lspconfig[server_name].setup({
|
|
capabilities = capabilities,
|
|
on_attach = on_attach,
|
|
})
|
|
end,
|
|
|
|
["clangd"] = function()
|
|
lspconfig.clangd.setup({
|
|
capabilities = capabilities,
|
|
on_attach = on_attach,
|
|
cmd = {
|
|
"clangd",
|
|
"--background-index",
|
|
"--clang-tidy",
|
|
"--header-insertion=iwyu",
|
|
"--completion-style=detailed",
|
|
},
|
|
})
|
|
end,
|
|
|
|
["gopls"] = function()
|
|
lspconfig.gopls.setup({
|
|
capabilities = capabilities,
|
|
on_attach = on_attach,
|
|
settings = {
|
|
gopls = {
|
|
gofumpt = true,
|
|
analyses = { unusedparams = true, shadow = true },
|
|
staticcheck = true,
|
|
},
|
|
},
|
|
})
|
|
end,
|
|
|
|
["lua_ls"] = function()
|
|
lspconfig.lua_ls.setup({
|
|
capabilities = capabilities,
|
|
on_attach = on_attach,
|
|
settings = {
|
|
Lua = {
|
|
diagnostics = { globals = { "vim" } },
|
|
workspace = {
|
|
library = vim.api.nvim_get_runtime_file("", true),
|
|
checkThirdParty = false,
|
|
},
|
|
telemetry = { enable = false },
|
|
},
|
|
},
|
|
})
|
|
end,
|
|
}
|
|
|
|
require("mason-lspconfig").setup({ handlers = handlers })
|
|
end,
|
|
}
|