149 lines
4.2 KiB
Lua
149 lines
4.2 KiB
Lua
local ok, lspconfig = pcall(require, "lspconfig")
|
|
|
|
if not ok then
|
|
return
|
|
end
|
|
|
|
local nmap = require("my.utils").nmap
|
|
|
|
local border = {
|
|
{ "┌", "FloatBorder" },
|
|
{ "─", "FloatBorder" },
|
|
{ "┐", "FloatBorder" },
|
|
{ "│", "FloatBorder" },
|
|
{ "┘", "FloatBorder" },
|
|
{ "─", "FloatBorder" },
|
|
{ "└", "FloatBorder" },
|
|
{ "│", "FloatBorder" },
|
|
}
|
|
|
|
local handlers = {
|
|
["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border }),
|
|
["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = border }),
|
|
}
|
|
|
|
local capabilities = {}
|
|
|
|
local has_cmp, cmp_lsp = pcall(require, "cmp_nvim_lsp")
|
|
if has_cmp then
|
|
capabilities = cmp_lsp.default_capabilities()
|
|
end
|
|
|
|
local has_lsp_status, lsp_status = pcall(require, "lsp_status")
|
|
if has_lsp_status then
|
|
capabilities = vim.tbl_extend("keep", capabilities, lsp_status.capabilities)
|
|
end
|
|
|
|
local format_augroup = setmetatable({}, {
|
|
__index = function(self, id)
|
|
local group = vim.api.nvim_create_augroup(string.format("lsp-format-%s", id), { clear = true })
|
|
rawset(self, id, group)
|
|
return group
|
|
end,
|
|
})
|
|
|
|
local on_attach = function(client, bufnr)
|
|
nmap("K", vim.lsp.buf.hover, "LSP hover", bufnr)
|
|
nmap("<C-]>", vim.lsp.buf.definition, "Go to definition", bufnr)
|
|
nmap("<Leader>r", vim.lsp.buf.rename, "Rename", bufnr)
|
|
nmap("<Leader>cf", vim.lsp.buf.format, "Format document", bufnr)
|
|
nmap("<Leader>ca", vim.lsp.buf.code_action, "Code actions", bufnr)
|
|
nmap("<Leader>ci", vim.lsp.buf.implementation, "Go to implementation", bufnr)
|
|
nmap("<Leader>D", vim.lsp.buf.type_definition, "Go to type definition", bufnr)
|
|
nmap("gr", "<Cmd>Telescope lsp_references<CR>", "View references", bufnr)
|
|
|
|
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
|
|
|
|
-- Highlight on cursor hold
|
|
if client.server_capabilities.documentHighlightProvider then
|
|
vim.api.nvim_create_autocmd({ "CursorHold" }, {
|
|
callback = vim.lsp.buf.document_highlight,
|
|
buffer = bufnr,
|
|
})
|
|
vim.api.nvim_create_autocmd({ "CursorHoldI" }, {
|
|
callback = vim.lsp.buf.signature_help,
|
|
buffer = bufnr,
|
|
})
|
|
vim.api.nvim_create_autocmd({ "CursorMoved" }, {
|
|
callback = vim.lsp.buf.clear_references,
|
|
buffer = bufnr,
|
|
})
|
|
end
|
|
|
|
-- Format on save
|
|
if client.server_capabilities.documentFormattingProvider then
|
|
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
|
group = format_augroup[client.id],
|
|
callback = function()
|
|
vim.lsp.buf.format { async = false }
|
|
end,
|
|
})
|
|
end
|
|
|
|
if has_lsp_status then
|
|
lsp_status.on_attach(client)
|
|
end
|
|
end
|
|
|
|
local servers = {
|
|
gopls = {},
|
|
intelephense = {
|
|
settings = {
|
|
intelephense = {
|
|
format = {
|
|
braces = "k&r",
|
|
},
|
|
telemetry = {
|
|
enabled = false,
|
|
},
|
|
files = {
|
|
maxSize = 10000000,
|
|
},
|
|
},
|
|
}
|
|
},
|
|
pylsp = {},
|
|
rust_analyzer = {
|
|
assist = {
|
|
importGranularity = "module",
|
|
importPrefix = "self",
|
|
},
|
|
cargo = {
|
|
loadOutDirsFromCheck = true,
|
|
},
|
|
procMacro = {
|
|
enable = true,
|
|
},
|
|
},
|
|
sumneko_lua = {
|
|
settings = {
|
|
Lua = {
|
|
runtime = {
|
|
version = "LuaJIT",
|
|
},
|
|
diagnostics = {
|
|
globals = { "vim" },
|
|
},
|
|
workspace = {
|
|
library = vim.api.nvim_get_runtime_file("", true),
|
|
},
|
|
telemetry = {
|
|
enable = false,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
svelte = {},
|
|
-- tailwindcss = {
|
|
-- root_dir = lspconfig.util.root_pattern("tailwind.config.js", "tailwind.config.ts", "tailwind.config.cjs"),
|
|
-- },
|
|
tsserver = {},
|
|
}
|
|
|
|
for lsp, settings in pairs(servers) do
|
|
lspconfig[lsp].setup(vim.tbl_extend("force", {
|
|
on_attach = on_attach,
|
|
capabilities = capabilities,
|
|
handlers = handlers,
|
|
}, settings))
|
|
end
|