You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
4.8 KiB
162 lines
4.8 KiB
local M = { |
|
"neovim/nvim-lspconfig", |
|
event = { "BufReadPre", "BufNewFile" }, |
|
dependencies = { |
|
{ |
|
"folke/neodev.nvim", |
|
}, |
|
}, |
|
} |
|
|
|
local function lsp_keymaps(bufnr) |
|
local opts = { noremap = true, silent = true } |
|
local keymap = vim.api.nvim_buf_set_keymap |
|
keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts) |
|
keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts) |
|
-- keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts) |
|
vim.keymap.set("n", "K", function() |
|
local winid = require("ufo").peekFoldedLinesUnderCursor() |
|
if not winid then |
|
vim.lsp.buf.hover() |
|
end |
|
end) |
|
keymap(bufnr, "n", "gI", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts) |
|
keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts) |
|
keymap(bufnr, "n", "gl", "<cmd>lua vim.diagnostic.open_float()<CR>", opts) |
|
end |
|
|
|
M.on_attach = function(client, bufnr) |
|
lsp_keymaps(bufnr) |
|
|
|
if client.supports_method "textDocument/inlayHint" then |
|
vim.lsp.inlay_hint.enable(bufnr, true) |
|
end |
|
end |
|
|
|
M.toggle_inlay_hints = function() |
|
local bufnr = vim.api.nvim_get_current_buf() |
|
vim.lsp.inlay_hint.enable(bufnr, not vim.lsp.inlay_hint.is_enabled(bufnr)) |
|
end |
|
|
|
function M.common_capabilities() |
|
local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") |
|
if status_ok then |
|
return cmp_nvim_lsp.default_capabilities() |
|
end |
|
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities() |
|
capabilities.textDocument.completion.completionItem.snippetSupport = true |
|
capabilities.textDocument.completion.completionItem.resolveSupport = { |
|
properties = { |
|
"documentation", |
|
"detail", |
|
"additionalTextEdits", |
|
}, |
|
} |
|
capabilities.textDocument.foldingRange = { |
|
dynamicRegistration = false, |
|
lineFoldingOnly = true, |
|
} |
|
|
|
return capabilities |
|
end |
|
|
|
function M.config() |
|
local wk = require "which-key" |
|
wk.register { |
|
["<leader>la"] = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action" }, |
|
["<leader>lf"] = { |
|
"<cmd>lua vim.lsp.buf.format({async = true, filter = function(client) return client.name ~= 'typescript-tools' end})<cr>", |
|
"Format", |
|
}, |
|
["<leader>li"] = { "<cmd>LspInfo<cr>", "Info" }, |
|
["<leader>lj"] = { "<cmd>lua vim.diagnostic.goto_next()<cr>", "Next Diagnostic" }, |
|
["<leader>lh"] = { "<cmd>lua require('user.lspconfig').toggle_inlay_hints()<cr>", "Hints" }, |
|
["<leader>lk"] = { "<cmd>lua vim.diagnostic.goto_prev()<cr>", "Prev Diagnostic" }, |
|
["<leader>ll"] = { "<cmd>lua vim.lsp.codelens.run()<cr>", "CodeLens Action" }, |
|
["<leader>lq"] = { "<cmd>lua vim.diagnostic.setloclist()<cr>", "Quickfix" }, |
|
["<leader>lr"] = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" }, |
|
} |
|
|
|
wk.register { |
|
["<leader>la"] = { |
|
name = "LSP", |
|
a = { "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action", mode = "v" }, |
|
}, |
|
} |
|
|
|
local lspconfig = require "lspconfig" |
|
local icons = require "user.icons" |
|
|
|
local servers = { |
|
"lua_ls", |
|
"cssls", |
|
"html", |
|
-- "tsserver", |
|
"astro", |
|
"pyright", |
|
"bashls", |
|
"lemminx", |
|
"jsonls", |
|
"yamlls", |
|
"marksman", |
|
"tailwindcss", |
|
"eslint", |
|
"rust_analyzer", |
|
-- "prismals", |
|
} |
|
|
|
local default_diagnostic_config = { |
|
signs = { |
|
active = true, |
|
values = { |
|
{ name = "DiagnosticSignError", text = icons.diagnostics.Error }, |
|
{ name = "DiagnosticSignWarn", text = icons.diagnostics.Warning }, |
|
{ name = "DiagnosticSignHint", text = icons.diagnostics.Hint }, |
|
{ name = "DiagnosticSignInfo", text = icons.diagnostics.Information }, |
|
}, |
|
}, |
|
virtual_text = false, |
|
update_in_insert = false, |
|
underline = true, |
|
severity_sort = true, |
|
float = { |
|
focusable = true, |
|
style = "minimal", |
|
border = "rounded", |
|
source = "always", |
|
header = "", |
|
prefix = "", |
|
}, |
|
} |
|
|
|
vim.diagnostic.config(default_diagnostic_config) |
|
|
|
for _, sign in ipairs(vim.tbl_get(vim.diagnostic.config(), "signs", "values") or {}) do |
|
vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name }) |
|
end |
|
|
|
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) |
|
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" }) |
|
require("lspconfig.ui.windows").default_options.border = "rounded" |
|
|
|
for _, server in pairs(servers) do |
|
local opts = { |
|
on_attach = M.on_attach, |
|
capabilities = M.common_capabilities(), |
|
} |
|
|
|
local require_ok, settings = pcall(require, "user.lspsettings." .. server) |
|
if require_ok then |
|
opts = vim.tbl_deep_extend("force", settings, opts) |
|
end |
|
|
|
if server == "lua_ls" then |
|
require("neodev").setup {} |
|
end |
|
|
|
lspconfig[server].setup(opts) |
|
end |
|
end |
|
|
|
return M
|
|
|