From 984aee9a4458bd879d40500f8106c18905cb3cf7 Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Tue, 16 May 2023 19:27:45 +0100 Subject: [PATCH] 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. --- site-modules/core/files/vim/plugin/lsp.lua | 45 ++++++++++++++-------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/site-modules/core/files/vim/plugin/lsp.lua b/site-modules/core/files/vim/plugin/lsp.lua index 2f53be9..784f8d5 100644 --- a/site-modules/core/files/vim/plugin/lsp.lua +++ b/site-modules/core/files/vim/plugin/lsp.lua @@ -50,6 +50,31 @@ local on_attach = function(_, bufnr) vim.api.nvim_buf_set_keymap(bufnr, "n", "rn", "lua vim.lsp.buf.rename()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "ca", "lua vim.lsp.buf.code_action()", 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 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.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" }, { 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() end, - group = "lsp_document_highlight", - desc = "Document Highlight", -}) -vim.api.nvim_create_autocmd("CursorMoved", { - callback = function () - vim.lsp.buf.clear_references() - end, - group = "lsp_document_highlight", - desc = "Clear All the References", + group = "diagnostic_float", + desc = "Open Diagnostic Float", })