2025-02-12 11:49:02 +01:00
|
|
|
-- See: https://neovim.io/doc/user/lsp.html#lsp-defaults
|
|
|
|
vim.keymap.del('n', 'grn')
|
|
|
|
vim.keymap.del({ 'n', 'v' }, 'gra')
|
|
|
|
vim.keymap.del('n', 'grr')
|
|
|
|
vim.keymap.del('n', 'gri')
|
|
|
|
vim.keymap.del('n', 'gO')
|
|
|
|
vim.keymap.del('i', '<c-s>')
|
|
|
|
|
2025-02-13 08:58:49 +01:00
|
|
|
local startswith = function(text, prefix)
|
|
|
|
return text:find(prefix, 1, true) == 1
|
|
|
|
end
|
|
|
|
|
2025-02-12 11:49:02 +01:00
|
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
|
|
callback = function(args)
|
|
|
|
-- See: https://neovim.io/doc/user/lsp.html#lsp-defaults
|
|
|
|
vim.lsp.config('*', require('blink.cmp').get_lsp_capabilities({}, false))
|
|
|
|
|
|
|
|
-- Retrieve Dependencies
|
|
|
|
local lsp_client = vim.lsp.get_client_by_id(args.data.client_id)
|
|
|
|
local buf = args.buf
|
|
|
|
|
|
|
|
-- LSP: Code Completion
|
|
|
|
if lsp_client:supports_method('textDocument/completion') then
|
2025-02-13 09:04:17 +01:00
|
|
|
vim.lsp.completion.enable(true, lsp_client.id, buf, { autotrigger = false })
|
2025-02-12 11:49:02 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- LSP: Diagnostics
|
|
|
|
if lsp_client:supports_method('textDocument/diagnostic') then
|
|
|
|
vim.keymap.set(
|
|
|
|
'n',
|
|
|
|
'<leader>le',
|
|
|
|
require('fzf-lua').diagnostics_document,
|
2025-02-13 09:04:17 +01:00
|
|
|
{ buffer = buf, desc = '[L]SP [E]rrors' }
|
|
|
|
)
|
2025-02-12 11:49:02 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- LSP: Diagnostics
|
|
|
|
if lsp_client:supports_method('textDocument/signatureHelp') then
|
2025-02-13 09:04:17 +01:00
|
|
|
vim.keymap.set('i', '<c-s>', vim.lsp.buf.signature_help, { buffer = buf, desc = 'LSP Signature Help' })
|
2025-02-12 11:49:02 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- LSP Action: Formatting
|
2025-02-13 08:58:49 +01:00
|
|
|
if lsp_client:supports_method('textDocument/formatting') or startswith(lsp_client.name, 'otter-ls') then
|
2025-02-13 09:04:17 +01:00
|
|
|
vim.keymap.set('n', '<leader>lf', function()
|
|
|
|
require('conform').format({
|
|
|
|
async = true,
|
|
|
|
bufnr = buf,
|
|
|
|
id = lsp_client.id,
|
|
|
|
})
|
|
|
|
end, { buffer = buf, desc = '[L]SP [F]ormat' })
|
2025-02-12 11:49:02 +01:00
|
|
|
|
|
|
|
-- Format the current buffer on save
|
|
|
|
--- TODO: Only on filetypes w/fast formatters?
|
|
|
|
--vim.api.nvim_create_autocmd('BufWritePre', {
|
|
|
|
-- buffer = buf,
|
|
|
|
-- callback = function()
|
|
|
|
-- require('conform').format({
|
|
|
|
-- async = true,
|
|
|
|
-- bufnr = buf,
|
|
|
|
-- id = lsp_client.id,
|
|
|
|
-- })
|
|
|
|
-- --vim.lsp.buf.format({ bufnr = buf, id = lsp_client.id })
|
|
|
|
-- end
|
|
|
|
--})
|
|
|
|
end
|
|
|
|
|
|
|
|
-- LSP Action: Inlay Hint
|
|
|
|
--- WORKAROUND: otter-ls seems to crash with inlayHint.
|
2025-02-13 08:58:49 +01:00
|
|
|
if lsp_client:supports_method('textDocument/inlayHint') and not startswith(lsp_client.name, 'otter-ls') then
|
2025-02-12 11:49:02 +01:00
|
|
|
vim.lsp.inlay_hint.enable(true, { bufnr = buf })
|
|
|
|
|
2025-02-13 09:04:17 +01:00
|
|
|
vim.keymap.set('n', '<leader>lh', function()
|
|
|
|
if vim.lsp.inlay_hint.is_enabled({ bufnr = buf }) then
|
|
|
|
vim.lsp.inlay_hint.enable(false, { bufnr = buf })
|
|
|
|
else
|
|
|
|
vim.lsp.inlay_hint.enable(true, { bufnr = buf })
|
|
|
|
end
|
|
|
|
end, { desc = '[L]SP Toggle Inlay [H]ints' })
|
2025-02-12 11:49:02 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- LSP Action: Code Actions
|
|
|
|
if lsp_client:supports_method('textDocument/codeAction') then
|
|
|
|
vim.keymap.set(
|
|
|
|
'n',
|
|
|
|
'<leader>li',
|
|
|
|
require('fzf-lua').lsp_code_actions,
|
|
|
|
{ buffer = buf, desc = '[L]SP F[I]xes' }
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- LSP Action: Rename
|
|
|
|
if lsp_client:supports_method('textDocument/rename') then
|
2025-02-13 09:04:17 +01:00
|
|
|
vim.keymap.set('n', '<leader>lr', vim.lsp.buf.rename, { buffer = buf, desc = '[L]SP [R]ename' })
|
2025-02-12 11:49:02 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- LSP Action: "Hover"
|
|
|
|
if lsp_client:supports_method('textDocument/hover') then
|
2025-02-13 09:04:17 +01:00
|
|
|
vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = buf, desc = '[L]SP Hover' })
|
2025-02-12 11:49:02 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- LSP Action: References
|
2025-02-13 09:04:17 +01:00
|
|
|
if
|
|
|
|
lsp_client:supports_method('textDocument/references')
|
|
|
|
or lsp_client:supports_method('textDocument/typeDefinition')
|
|
|
|
or lsp_client:supports_method('textDocument/definition')
|
|
|
|
then
|
|
|
|
vim.keymap.set('n', '<leader>ld', require('fzf-lua').lsp_finder, { buffer = buf, desc = '[L]SP Fin[D]er' })
|
2025-02-12 11:49:02 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- LSP Action: List Buffer Symbols
|
|
|
|
if lsp_client:supports_method('textDocument/documentSymbol') then
|
2025-02-13 09:04:17 +01:00
|
|
|
vim.keymap.set(
|
|
|
|
'n',
|
|
|
|
'<leader>ls',
|
|
|
|
require('fzf-lua').lsp_document_symbols,
|
|
|
|
{ buffer = buf, desc = '[L]SP [S]ymbols' }
|
|
|
|
)
|
2025-02-12 11:49:02 +01:00
|
|
|
end
|
2025-02-13 09:04:17 +01:00
|
|
|
end,
|
2025-02-12 11:49:02 +01:00
|
|
|
})
|