clear autocmd #191

fix-keymap-buffer
ray-x 2 years ago
parent 01ef2ce1a1
commit 5713f79265

@ -394,8 +394,8 @@ M.show_buf_diagnostics = function()
end
-- set loc list win
M.set_diag_loclist = function()
local bufnr = api.nvim_get_current_buf()
M.set_diag_loclist = function(bufnr)
bufnr = bufnr or api.nvim_get_current_buf()
local diag_cnt = get_count(bufnr, [[Error]]) + get_count(bufnr, [[Warning]])
if diag_cnt == 0 then
log('great, no errors!')

@ -145,7 +145,6 @@ local handle_document_highlight = function(_, result, ctx)
return
end
if type(result) ~= 'table' or vim.fn.empty(result) == 1 then
log('clear up', result)
vim.lsp.util.buf_clear_references(ctx.bufnr)
return
end
@ -205,11 +204,12 @@ local function cmd_nohl()
end
end
local nav_doc_hl = function()
local bufnr = vim.api.nvim_get_current_buf()
local nav_doc_hl = function(bufnr)
bufnr = bufnr or vim.api.nvim_get_current_buf()
local ref_params = vim.lsp.util.make_position_params()
vim.lsp.for_each_buffer_client(bufnr, function(client, _, _)
if client.server_capabilities.documentHighlightProvider == true then
trace("sending doc highlight", client.name, bufnr)
client.request('textDocument/documentHighlight', ref_params, handle_document_highlight, bufnr)
end
end)
@ -224,7 +224,7 @@ local function documentHighlight(bufnr)
group = cmd_group,
buffer = bufnr,
callback = function()
require('navigator.dochighlight').nav_doc_hl()
require('navigator.dochighlight').nav_doc_hl(bufnr)
end,
})

@ -36,9 +36,16 @@ M.on_attach = function(client, bufnr)
})
if client.server_capabilities.documentHighlightProvider == true then
require('navigator.dochighlight').documentHighlight(bufnr)
trace('attaching doc highlight: ', bufnr, client.name)
vim.defer_fn(function()
require('navigator.dochighlight').documentHighlight(bufnr)
end, 50) -- allow a bit time for it to settle down
else
log('skip doc highlight: ', bufnr, client.name)
end
require('navigator.lspclient.lspkind').init()
local config = require('navigator').config_values()

@ -3,12 +3,6 @@ local log = util.log
local trace = util.trace
local api = vim.api
local event_hdlrs = {
{ ev = 'BufWritePre', func = require('navigator.diagnostics').set_diag_loclist },
{ ev = { 'CursorHold', 'CursorHoldI' }, func = vim.lsp.buf.document_highlight },
{ ev = 'CursorMoved', func = vim.lsp.buf.clear_references },
}
if vim.lsp.buf.format == nil then
vim.lsp.buf.format = vim.lsp.buf.formatting
end
@ -282,42 +276,6 @@ local function autocmd()
})
end
local function set_event_handler(user_opts)
user_opts = user_opts or {}
local file_types = {
'*.c',
'*.cpp',
'*.h',
'*.go',
'*.python',
'*.vim',
'*.sh',
'*.javascript',
'*.html',
'*.css',
'*.lua',
'*.typescript',
'*.rust',
'*.javascriptreact',
'*.typescriptreact',
'*.kotlin',
'*.php',
'*.dart',
'*.nim',
'*.java',
}
-- local format_files = "c,cpp,h,go,python,vim,javascript,typescript" --html,css,
local gn = api.nvim_create_augroup('nvim_nv_event_autos', {})
for _, value in pairs(event_hdlrs) do
api.nvim_create_autocmd(value.ev, {
group = gn,
pattern = file_types,
callback = value.func,
})
end
end
M.toggle_lspformat = function(on)
if on == nil then
_NgConfigValues.lsp.format_on_save = not _NgConfigValues.lsp.format_on_save
@ -349,7 +307,6 @@ function M.setup(attach_opts)
set_cmds(attach_opts)
autocmd()
set_event_handler(attach_opts)
local client = attach_opts.client or {}
local cap = client.server_capabilities or vim.lsp.protocol.make_client_capabilities()
@ -392,6 +349,14 @@ function M.setup(attach_opts)
})
end
api.nvim_create_autocmd({ 'BufWritePre' }, {
group = api.nvim_create_augroup('nvim_nv_event_autos', {}),
buffer = attach_opts.bufnr,
callback = function()
require('navigator.diagnostics').set_diag_loclist(attach_opts.bufnr)
end,
})
local border_style = single
if _NgConfigValues.border == 'double' then
border_style = double

Loading…
Cancel
Save