2025-01-01 18:56:17 -08:00
|
|
|
local i = require('icons')
|
|
|
|
|
|
|
|
-- Diagnostics -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
|
|
|
---@type vim.diagnostic.Opts
|
|
|
|
local diagnosticConfig = {
|
|
|
|
underline = true,
|
|
|
|
update_in_insert = true,
|
|
|
|
virtual_text = {
|
|
|
|
spacing = 4,
|
|
|
|
source = 'if_many',
|
|
|
|
prefix = function(diagnostic)
|
|
|
|
for d, icon in pairs(i.diagnostics) do
|
|
|
|
if diagnostic.severity == vim.diagnostic.severity[d:upper()] then
|
|
|
|
return icon
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return ''
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
severity_sort = true,
|
|
|
|
signs = {
|
|
|
|
text = {
|
|
|
|
[vim.diagnostic.severity.ERROR] = i.diagnostics.Error,
|
|
|
|
[vim.diagnostic.severity.WARN] = i.diagnostics.Warn,
|
|
|
|
[vim.diagnostic.severity.HINT] = i.diagnostics.Hint,
|
|
|
|
[vim.diagnostic.severity.INFO] = i.diagnostics.Info,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for severity, icon in pairs(diagnosticConfig.signs.text) do
|
|
|
|
local name =
|
|
|
|
vim.diagnostic.severity[severity]:lower():gsub('^%l', string.upper)
|
|
|
|
name = 'DiagnosticSign' .. name
|
|
|
|
|
|
|
|
vim.fn.sign_define(name, { text = icon, texthl = name, numhl = '' })
|
|
|
|
end
|
|
|
|
|
|
|
|
vim.diagnostic.config(diagnosticConfig)
|
|
|
|
|
|
|
|
-- Codelens -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
|
|
|
vim.api.nvim_create_autocmd('User', {
|
|
|
|
pattern = 'LspSupportsMethod',
|
|
|
|
callback = function(args)
|
|
|
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
|
|
|
local buffer = args.data.buffer
|
|
|
|
|
|
|
|
if client and args.data.method == 'textDocument/codeLens' then
|
|
|
|
vim.lsp.codelens.refresh()
|
|
|
|
|
|
|
|
vim.api.nvim_create_autocmd({ 'BufEnter', 'CursorHold', 'InsertLeave' }, {
|
|
|
|
buffer = buffer,
|
|
|
|
callback = vim.lsp.codelens.refresh,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Server Setup -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
|
|
|
local has_blink, blink = pcall(require, 'blink.cmp')
|
|
|
|
local capabilities = vim.tbl_deep_extend(
|
|
|
|
'force',
|
|
|
|
{},
|
|
|
|
vim.lsp.protocol.make_client_capabilities(),
|
|
|
|
has_blink and blink.get_lsp_capabilities() or {},
|
|
|
|
{
|
|
|
|
workspace = {
|
|
|
|
fileOperations = {
|
|
|
|
didRename = true,
|
|
|
|
willRename = true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
vim.lsp.config('*', {
|
|
|
|
root_markers = { '.git' },
|
|
|
|
capabilities = capabilities,
|
|
|
|
})
|
|
|
|
|
2025-01-05 11:15:03 -08:00
|
|
|
vim.lsp.enable({
|
|
|
|
'bash-language-server',
|
|
|
|
'emmet-language-server',
|
|
|
|
'lua-language-server',
|
2025-01-05 12:06:18 -08:00
|
|
|
'nixd',
|
|
|
|
'phpactor',
|
|
|
|
'stylelint-lsp',
|
|
|
|
'taplo',
|
|
|
|
'vscode-css-language-server',
|
|
|
|
'vscode-html-language-server',
|
2025-01-05 11:15:03 -08:00
|
|
|
})
|
2025-01-01 18:56:17 -08:00
|
|
|
|
|
|
|
-- Keymaps -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
2025-01-02 21:04:51 -08:00
|
|
|
MarleyVim.lsp.on_attach(function(client)
|
|
|
|
local set = vim.keymap.set
|
2025-01-01 18:56:17 -08:00
|
|
|
|
2025-01-02 21:04:51 -08:00
|
|
|
set('n', 'gD', vim.lsp.buf.declaration, { desc = 'declaration' })
|
|
|
|
set('n', 'gI', vim.lsp.buf.implementation, { desc = 'implementation' })
|
|
|
|
|
|
|
|
set('n', 'gr', vim.lsp.buf.references, { desc = 'references', nowait = true })
|
2025-01-01 18:56:17 -08:00
|
|
|
|
2025-01-02 21:04:51 -08:00
|
|
|
set('n', 'gy', vim.lsp.buf.type_definition, { desc = 'type definition' })
|
2025-01-01 18:56:17 -08:00
|
|
|
|
2025-01-02 21:04:51 -08:00
|
|
|
set('n', 'K', function()
|
|
|
|
return vim.lsp.buf.hover()
|
|
|
|
end, { desc = 'hover' })
|
2025-01-01 18:56:17 -08:00
|
|
|
|
2025-01-02 21:04:51 -08:00
|
|
|
if client.supports_method('textDocument/codeAction') then
|
2025-01-01 18:56:17 -08:00
|
|
|
set(
|
2025-01-02 21:04:51 -08:00
|
|
|
{ 'n', 'v' },
|
|
|
|
'<LEADER>ca',
|
|
|
|
vim.lsp.buf.code_action,
|
|
|
|
{ desc = 'code action' }
|
2025-01-01 18:56:17 -08:00
|
|
|
)
|
2025-01-02 21:04:51 -08:00
|
|
|
end
|
2025-01-01 18:56:17 -08:00
|
|
|
|
2025-01-02 21:04:51 -08:00
|
|
|
if client.supports_method('textDocument/codeLens') then
|
|
|
|
set(
|
|
|
|
{ 'n', 'v' },
|
|
|
|
'<LEADER>cc',
|
|
|
|
vim.lsp.codelens.run,
|
|
|
|
{ desc = 'run codelens' }
|
|
|
|
)
|
2025-01-01 18:56:17 -08:00
|
|
|
|
2025-01-02 21:04:51 -08:00
|
|
|
set(
|
|
|
|
'n',
|
|
|
|
'<LEADER>cC',
|
|
|
|
vim.lsp.codelens.refresh,
|
|
|
|
{ desc = 'refresh & display codelens' }
|
|
|
|
)
|
|
|
|
end
|
2025-01-01 18:56:17 -08:00
|
|
|
|
2025-01-02 21:04:51 -08:00
|
|
|
if client.supports_method('textDocument/definition') then
|
|
|
|
set('n', 'gd', vim.lsp.buf.definition, { desc = 'definition' })
|
|
|
|
end
|
2025-01-01 18:56:17 -08:00
|
|
|
|
2025-01-02 21:04:51 -08:00
|
|
|
if client.supports_method('textDocument/documentHighlight') then
|
|
|
|
if Snacks.words.is_enabled() then
|
|
|
|
set('n', '<A-n>', function()
|
|
|
|
Snacks.words.jump(vim.v.count1, true)
|
|
|
|
end, { desc = 'next reference' })
|
2025-01-01 18:56:17 -08:00
|
|
|
|
2025-01-02 21:04:51 -08:00
|
|
|
set('n', '<A-p>', function()
|
|
|
|
Snacks.words.jump(-vim.v.count1, true)
|
|
|
|
end, { desc = 'prev reference' })
|
2025-01-01 18:56:17 -08:00
|
|
|
|
2025-01-02 21:04:51 -08:00
|
|
|
set('n', ']]', function()
|
|
|
|
Snacks.words.jump(vim.v.count1)
|
|
|
|
end, { desc = 'next reference' })
|
2025-01-01 18:56:17 -08:00
|
|
|
|
2025-01-02 21:04:51 -08:00
|
|
|
set('n', '[[', function()
|
|
|
|
Snacks.words.jump(-vim.v.count1)
|
|
|
|
end, { desc = 'prev reference' })
|
2025-01-01 18:56:17 -08:00
|
|
|
end
|
2025-01-02 21:04:51 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
if client.supports_method('textDocument/rename') then
|
|
|
|
set('n', '<LEADER>cr', vim.lsp.buf.rename, { desc = 'rename' })
|
|
|
|
end
|
|
|
|
|
|
|
|
if client.supports_method('textDocument/signatureHelp') then
|
|
|
|
set('i', '<C-k>', function()
|
|
|
|
return vim.lsp.buf.signature_help()
|
|
|
|
end, { desc = 'signature help' })
|
|
|
|
|
|
|
|
set('n', 'gK', function()
|
|
|
|
vim.lsp.buf.signature_help()
|
|
|
|
end, { desc = 'signature help' })
|
|
|
|
end
|
|
|
|
|
|
|
|
if
|
|
|
|
client.supports_method('workspace/didRenameFiles')
|
|
|
|
or client.supports_method('workspace/willRenameFiles')
|
|
|
|
then
|
|
|
|
set('n', '<LEADER>cR', function()
|
|
|
|
Snacks.rename.rename_file()
|
|
|
|
end, { desc = 'rename file' })
|
|
|
|
end
|
|
|
|
end)
|