feat: lsp
This commit is contained in:
@@ -19,6 +19,13 @@ return {
|
||||
TabLine = { fg = c.muted, bg = c.none },
|
||||
TabLineSel = { fg = c.text, bg = c.none, bold = true },
|
||||
TabLineFill = { fg = c.outline_light, bg = c.none },
|
||||
|
||||
Pmenu = { fg = c.text, bg = c.surface },
|
||||
PmenuSel = { fg = c.text, bg = c.accent_light },
|
||||
QuickFixLine = { fg = c.accent, bg = c.none, bold = true },
|
||||
-- PmenuSbar = { bg = c.surface },
|
||||
-- PmenuThumb = { bg = c.outline },
|
||||
-- PmenuBorder = { fg = c.outline },
|
||||
}
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -13,8 +13,8 @@ local language_specs = {
|
||||
'gitignore',
|
||||
'dockerfile',
|
||||
'diff',
|
||||
{ 'json', nil, nil, 'prettier' },
|
||||
{ 'jsonc', nil, nil, 'prettier' },
|
||||
{ 'json', 'json-lsp' },
|
||||
{ 'jsonc', 'json-lsp' },
|
||||
|
||||
-- Shell / scripting
|
||||
{ 'bash', 'bash-language-server', 'shellcheck', 'shfmt' },
|
||||
@@ -30,12 +30,12 @@ local language_specs = {
|
||||
-- { 'python', 'pyright', 'ruff', 'ruff' }, -- install ensurepip
|
||||
|
||||
-- Web stack
|
||||
{ 'html', nil, nil, 'prettier' },
|
||||
{ 'css', nil, nil, 'prettier' },
|
||||
{ 'javascript', 'vtsls', 'eslint_d', 'prettier' },
|
||||
{ 'typescript', 'vtsls', 'eslint_d', 'prettier' },
|
||||
{ nil, 'vtsls', 'eslint_d', 'prettier', filetype = 'javascriptreact' },
|
||||
{ 'tsx', 'vtsls', 'eslint_d', 'prettier', filetype = 'typescriptreact' },
|
||||
{ 'html', 'html-lsp' },
|
||||
{ 'css', 'css-lsp' },
|
||||
{ 'javascript', { 'vtsls', 'eslint-lsp' }, nil, 'prettier' },
|
||||
{ 'typescript', { 'vtsls', 'eslint-lsp' }, nil, 'prettier' },
|
||||
{ nil, { 'vtsls', 'eslint-lsp' }, nil, 'prettier', filetype = 'javascriptreact' },
|
||||
{ 'tsx', { 'vtsls', 'eslint-lsp' }, nil, 'prettier', filetype = 'typescriptreact' },
|
||||
}
|
||||
|
||||
local function normalize(spec)
|
||||
@@ -71,7 +71,13 @@ local function collect(specs)
|
||||
table.insert(ts, s.treesitter)
|
||||
end
|
||||
if s.lsp then
|
||||
table.insert(lsps, s.lsp)
|
||||
if type(s.lsp) == 'table' then
|
||||
for _, v in ipairs(s.lsp) do
|
||||
table.insert(lsps, v)
|
||||
end
|
||||
else
|
||||
table.insert(lsps, s.lsp)
|
||||
end
|
||||
end
|
||||
if s.linter then
|
||||
linters[s.filetype] = { s.linter }
|
||||
@@ -187,9 +193,124 @@ vim.api.nvim_create_user_command('TreesitterInstallAll', function()
|
||||
end
|
||||
end
|
||||
end, { desc = 'Install all Treesitter parsers defined in ensure_installed' })
|
||||
|
||||
vim.api.nvim_create_user_command('General', function()
|
||||
print(vim.inspect(general))
|
||||
end, {})
|
||||
|
||||
local special_sources = {
|
||||
lua_ls = 'lua',
|
||||
eslint = 'eslint',
|
||||
}
|
||||
|
||||
vim.diagnostic.config({
|
||||
underline = true,
|
||||
severity_sort = true,
|
||||
update_in_insert = true,
|
||||
|
||||
virtual_text = {
|
||||
format = function(diagnostic)
|
||||
local src = diagnostic.source and (special_sources[diagnostic.source] or diagnostic.source)
|
||||
if src then
|
||||
return string.format('%s: %s', src, diagnostic.message)
|
||||
end
|
||||
return diagnostic.message
|
||||
end,
|
||||
},
|
||||
|
||||
float = {
|
||||
border = 'rounded',
|
||||
header = '',
|
||||
format = function(diagnostic)
|
||||
local src = diagnostic.source and (special_sources[diagnostic.source] or diagnostic.source)
|
||||
if src then
|
||||
return string.format('%s: %s', src, diagnostic.message)
|
||||
end
|
||||
return diagnostic.message
|
||||
end,
|
||||
},
|
||||
})
|
||||
|
||||
-- Override the virtual text diagnostic handler so that the most severe diagnostic is shown first.
|
||||
local show_handler = vim.diagnostic.handlers.virtual_text.show
|
||||
assert(show_handler)
|
||||
local hide_handler = vim.diagnostic.handlers.virtual_text.hide
|
||||
vim.diagnostic.handlers.virtual_text = {
|
||||
show = function(ns, bufnr, diagnostics, opts)
|
||||
table.sort(diagnostics, function(diag1, diag2)
|
||||
return diag1.severity > diag2.severity
|
||||
end)
|
||||
return show_handler(ns, bufnr, diagnostics, opts)
|
||||
end,
|
||||
hide = hide_handler,
|
||||
}
|
||||
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
group = vim.api.nvim_create_augroup('minimal_lsp', { clear = true }),
|
||||
callback = function(ev)
|
||||
local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
||||
if not client then
|
||||
return
|
||||
end
|
||||
|
||||
-- Enable native completion
|
||||
if client:supports_method('textDocument/completion') then
|
||||
vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true })
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- Optional: annotate completion items with their kind
|
||||
---------------------------------------------------------------------
|
||||
vim.lsp.handlers['textDocument/completion'] = function(err, result, ctx, config)
|
||||
if err or not result then
|
||||
return
|
||||
end
|
||||
for _, item in ipairs(result.items or result) do
|
||||
if item.kind then
|
||||
local kind = vim.lsp.protocol.CompletionItemKind[item.kind] or ''
|
||||
item.menu = '[' .. kind .. ']'
|
||||
end
|
||||
end
|
||||
return vim.lsp.completion._on_completion_result(err, result, ctx, config)
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------
|
||||
-- Plugins
|
||||
---------------------------------------------------------------------
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
group = vim.api.nvim_create_augroup('lsp_attach_timing', { clear = true }),
|
||||
callback = function(ev)
|
||||
local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
||||
if client then
|
||||
vim.notify(
|
||||
string.format('LSP attached: %s (buf: %d)', client.name, ev.buf),
|
||||
vim.log.levels.INFO
|
||||
)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
local function enable_lsp_with_timing(lsp_name)
|
||||
local start_time = vim.uv.hrtime()
|
||||
|
||||
vim.lsp.enable(lsp_name)
|
||||
|
||||
-- Track when the server actually attaches
|
||||
local group = vim.api.nvim_create_augroup('lsp_timing_' .. lsp_name, { clear = true })
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
group = group,
|
||||
callback = function(ev)
|
||||
local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
||||
if client and client.name == lsp_name then
|
||||
local elapsed = (vim.uv.hrtime() - start_time) / 1e6 -- Convert to milliseconds
|
||||
vim.notify(string.format('%s attached in %.2f ms', lsp_name, elapsed), vim.log.levels.INFO)
|
||||
vim.api.nvim_del_augroup_by_id(group)
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
return {
|
||||
{ 'windwp/nvim-ts-autotag', config = true },
|
||||
{ 'windwp/nvim-autopairs', event = 'InsertEnter', config = true },
|
||||
@@ -210,7 +331,8 @@ return {
|
||||
table.insert(lsp_configs, lsp_name)
|
||||
|
||||
-- Native enable call (Neovim ≥ 0.11)
|
||||
vim.lsp.enable(lsp_name)
|
||||
-- vim.lsp.enable(lsp_name)
|
||||
enable_lsp_with_timing(lsp_name)
|
||||
else
|
||||
vim.notify('Unknown LSP: ' .. lsp, vim.log.levels.WARN)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user