refactor: update nvim settings

This commit is contained in:
hhhh hgfh 2026-02-08 16:52:42 +03:00
parent af02e31fe9
commit 6748725b17
33 changed files with 1390 additions and 344 deletions

View file

@ -1,34 +1,55 @@
local M = {}
local api = vim.api
local map = vim.keymap.set
local function check_triggeredChars(triggerChars)
local cur_line = api.nvim_get_current_line()
local pos = api.nvim_win_get_cursor(0)[2]
local prev_char = cur_line:sub(pos - 1, pos - 1)
local cur_char = cur_line:sub(pos, pos)
-- export on_attach & capabilities
M.on_attach = function(_, bufnr)
local function opts(desc)
return { buffer = bufnr, desc = "LSP " .. desc }
end
for _, char in ipairs(triggerChars) do
if cur_char == char or prev_char == char then
return true
map("n", "gD", vim.lsp.buf.declaration, opts "Go to declaration")
map("n", "gd", vim.lsp.buf.definition, opts "Go to definition")
map("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, opts "Add workspace folder")
map("n", "<leader>wr", vim.lsp.buf.remove_workspace_folder, opts "Remove workspace folder")
map("n", "<leader>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts "List workspace folders")
map("n", "<leader>D", vim.lsp.buf.type_definition, opts "Go to type definition")
end
-- disable semanticTokens
M.on_init = function(client, _)
if vim.fn.has "nvim-0.11" ~= 1 then
if client.supports_method "textDocument/semanticTokens" then
client.server_capabilities.semanticTokensProvider = nil
end
else
if client:supports_method "textDocument/semanticTokens" then
client.server_capabilities.semanticTokensProvider = nil
end
end
end
M.setup = function(client, bufnr)
local group = api.nvim_create_augroup("LspSignature", { clear = false })
api.nvim_clear_autocmds { group = group, buffer = bufnr }
M.capabilities = vim.lsp.protocol.make_client_capabilities()
local triggerChars = client.server_capabilities.signatureHelpProvider.triggerCharacters
api.nvim_create_autocmd("TextChangedI", {
group = group,
buffer = bufnr,
callback = function()
if check_triggeredChars(triggerChars) then
vim.lsp.buf.signature_help { focus = false, silent = true, max_height = 7, border = "single" }
end
end,
})
end
M.capabilities.textDocument.completion.completionItem = {
documentationFormat = { "markdown", "plaintext" },
snippetSupport = true,
preselectSupport = true,
insertReplaceSupport = true,
labelDetailsSupport = true,
deprecatedSupport = true,
commitCharactersSupport = true,
tagSupport = { valueSet = { 1 } },
resolveSupport = {
properties = {
"documentation",
"detail",
"additionalTextEdits",
},
},
}
return M

View file

@ -2,7 +2,7 @@ local on_attach = require("configs.lsp.e-lspconfig").on_attach
local on_init = require("configs.lsp.e-lspconfig").on_init
local capabilities = require("configs.lsp.e-lspconfig").capabilities
-- clangd lsp server
-- C/C++
vim.lsp.config('clangd', {
on_attach = on_attach,
on_init = on_init,
@ -17,16 +17,48 @@ vim.lsp.config('clangd', {
"--completion-style=detailed",
"--header-insertion=iwyu",
"--limit-references=5",
"--malloc-trim",
"--pch-storage=disk",
},
filetypes = { "c", "cpp", "objc", "objcpp" },
init_options = {
fallbackFlags = {'-std=c++20'},
}
filetypes = { "c", "cpp", "h", "hpp", "objc", "objcpp" },
root_markers = { '.git' },
})
vim.lsp.enable('clangd')
-- Go (gopls) lsp server
vim.lsp.config('gopls', {
on_attach = on_attach,
on_init = on_init,
capabilities = capabilities,
cmd = { 'gopls' },
filetypes = { 'go', 'gomod', 'gowork', 'gotmpl' },
root_markers = { 'go.mod', '.git' },
single_file_support = true,
settings = {
gopls = {
completeUnimported = true,
usePlaceholders = true,
analyses = {
unusedparams = true,
},
staticcheck = true,
gofumpt = true,
},
},
})
vim.lsp.enable('gopls')
-- PhP
vim.lsp.config('phpactor', {
cmd = { 'phpactor', 'language-server' },
filetypes = { 'php' },
root_markers = { 'composer.json', '.git' },
init_options = {
["language_server_phpstan.enabled"] = false,
["language_server_psalm.enabled"] = false,
}
})
vim.lsp.enable('phpactor')
-- Lua
vim.lsp.config('lua_ls', {
cmd = { 'lua-language-server' },
@ -59,6 +91,16 @@ vim.lsp.config('bashls', {
})
vim.lsp.enable('bashls')
-- Meson
vim.lsp.config('meson_ls', {
cmd = { 'mesonlsp' },
filetypes = { 'meson' },
root_markers = { 'meson.build', '.git' },
single_file_support = true,
settings = {}
})
vim.lsp.enable('meson_ls')
-- For all
vim.diagnostic.config({
virtual_text = false,