nvim: lsp: highlight symbol under cursor

This commit is contained in:
tastytea 2022-08-10 16:24:04 +02:00
parent b1c3738b3a
commit 4a317170e0
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
2 changed files with 42 additions and 0 deletions

View File

@ -33,6 +33,47 @@ packer.use {
maplsp('n', '<space>ca', vim.lsp.buf.code_action)
maplsp('n', 'gr', vim.lsp.buf.references)
maplsp('n', '<space>f', vim.lsp.buf.formatting)
-- highlight symbol under cursor
if client.resolved_capabilities.document_highlight then
vim.cmd [[
hi! LspReferenceRead cterm=bold ctermbg=red guibg=#633466
hi! LspReferenceText cterm=bold ctermbg=red guibg=#633466
hi! LspReferenceWrite cterm=bold ctermbg=red guibg=#633466
]]
vim.api.nvim_create_augroup('lsp_document_highlight', {
clear = false
})
vim.api.nvim_clear_autocmds({
buffer = bufnr,
group = 'lsp_document_highlight',
})
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
group = 'lsp_document_highlight',
buffer = bufnr,
callback = vim.lsp.buf.document_highlight,
})
vim.api.nvim_create_autocmd('CursorMoved', {
group = 'lsp_document_highlight',
buffer = bufnr,
callback = vim.lsp.buf.clear_references,
})
end
vim.api.nvim_create_autocmd("CursorHold", {
buffer = bufnr,
callback = function()
local opts = {
focusable = false,
close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
border = 'rounded',
source = 'always',
prefix = ' ',
scope = 'cursor',
}
vim.diagnostic.open_float(nil, opts)
end
})
end
-- setup servers

View File

@ -13,6 +13,7 @@ vim.o.completeopt = 'menu,menuone,noselect' -- completion popup
vim.o.autochdir = true -- change workir to current file dir
vim.opt.conceallevel = 2 -- hidden stuff, needed for org
vim.opt.concealcursor = 'nc'
vim.o.updatetime = 500 -- fire CursorHold autocommand event
-- theme
vim.o.termguicolors = true -- 24 bit colours