From ce7b395e90bbf736a8b27a6c3b72afa470d2addd Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Thu, 16 Mar 2023 20:48:12 +0000 Subject: [PATCH] feat(vim): setup document highlighting and diagnostics on hover Now when the editor is idle it will use the lsp to highlight other references to the token under the cursor. It will also show all the diagnostics in a popup like the lsp hover that I manually use via . This is helpful with long diagnostic messages that run off the edge of the terminal when. --- site-modules/core/files/vim/plugin/lsp.lua | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/site-modules/core/files/vim/plugin/lsp.lua b/site-modules/core/files/vim/plugin/lsp.lua index 69b2b18..d1193c9 100644 --- a/site-modules/core/files/vim/plugin/lsp.lua +++ b/site-modules/core/files/vim/plugin/lsp.lua @@ -83,3 +83,27 @@ vim.diagnostic.config({ border = border } }) + +vim.cmd([[set updatetime=1000]]) +vim.api.nvim_create_augroup("lsp_document_highlight", { 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", +})