fix(vim): split out document highlight and diagnostic float auto commands
This was an issue when editing files that don't have an lsp server. The document highlight is only enabled for lsp's. This splits out the highlighting and the diagnostic float into two separate auto commands. The document highlight is now only enabled when the lsp is registered. The diagnostic float is now enabled for all files. This is because the the vim diagnostics are used for lots of other things like spell checking and codelimate.
This commit is contained in:
parent
ed9b5c7db5
commit
984aee9a44
1 changed files with 28 additions and 17 deletions
|
|
@ -50,6 +50,31 @@ local on_attach = function(_, bufnr)
|
||||||
|
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
|
||||||
|
|
||||||
|
vim.api.nvim_create_augroup("lsp_document_highlight", { clear = true })
|
||||||
|
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
|
||||||
|
buffer = bufnr,
|
||||||
|
callback = function ()
|
||||||
|
-- Highlight document symbles for every file type other erb files because
|
||||||
|
-- solargraph only supports textDocument/documentHighlight in rb files.
|
||||||
|
local file_type = vim.api.nvim_buf_get_option(0, "filetype")
|
||||||
|
if file_type ~= "eruby" then
|
||||||
|
vim.lsp.buf.document_highlight()
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
group = "lsp_document_highlight",
|
||||||
|
desc = "Document Highlight",
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd("CursorMoved", {
|
||||||
|
buffer = bufnr,
|
||||||
|
callback = function ()
|
||||||
|
vim.lsp.buf.clear_references()
|
||||||
|
end,
|
||||||
|
group = "lsp_document_highlight",
|
||||||
|
desc = "Clear All the References",
|
||||||
|
})
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
|
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||||
|
|
@ -86,25 +111,11 @@ vim.diagnostic.config({
|
||||||
})
|
})
|
||||||
|
|
||||||
vim.cmd([[set updatetime=1000]])
|
vim.cmd([[set updatetime=1000]])
|
||||||
vim.api.nvim_create_augroup("lsp_document_highlight", { clear = true })
|
vim.api.nvim_create_augroup("diagnostic_float", { clear = true })
|
||||||
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
|
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
|
||||||
callback = function ()
|
callback = function ()
|
||||||
-- Highlight document symbles for every file type other erb files because
|
|
||||||
-- solargraph only supports textDocument/documentHighlight in rb files.
|
|
||||||
local file_type = vim.api.nvim_buf_get_option(0, "filetype")
|
|
||||||
if file_type ~= "eruby" then
|
|
||||||
vim.lsp.buf.document_highlight()
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.diagnostic.open_float()
|
vim.diagnostic.open_float()
|
||||||
end,
|
end,
|
||||||
group = "lsp_document_highlight",
|
group = "diagnostic_float",
|
||||||
desc = "Document Highlight",
|
desc = "Open Diagnostic Float",
|
||||||
})
|
|
||||||
vim.api.nvim_create_autocmd("CursorMoved", {
|
|
||||||
callback = function ()
|
|
||||||
vim.lsp.buf.clear_references()
|
|
||||||
end,
|
|
||||||
group = "lsp_document_highlight",
|
|
||||||
desc = "Clear All the References",
|
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue