From f6a19a3a7500f4536a86bed072154542f731e93e Mon Sep 17 00:00:00 2001 From: Adam Poniatowski Date: Wed, 30 Apr 2025 14:58:34 +0200 Subject: [PATCH] added illuminate and some fixes --- lua/plugins/illuminate.lua | 35 +++++++++++++++++++++++++++ lua/plugins/lsp/overrides.lua | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 lua/plugins/illuminate.lua create mode 100644 lua/plugins/lsp/overrides.lua diff --git a/lua/plugins/illuminate.lua b/lua/plugins/illuminate.lua new file mode 100644 index 00000000..bdef833f --- /dev/null +++ b/lua/plugins/illuminate.lua @@ -0,0 +1,35 @@ +---@diagnostic disable: undefined-global +return { + 'RRethy/vim-illuminate', + event = { "BufReadPost", "BufNewFile" }, + opts = { + delay = 200, + large_file_cutoff = 2000, + large_file_overrides = { + providers = { "lsp" } + }, + providers = { + 'lsp', + 'treesitter', + 'regex', + }, + min_count_to_highlight = 2, -- minimum number of matches required to perform highlighting + }, + config = function(_, opts) + require('illuminate').configure(opts) + + -- Set highlight style (using colors that match with gruvbox theme) + vim.api.nvim_set_hl(0, 'IlluminatedWordText', { bg = '#3c3836', bold = true }) + vim.api.nvim_set_hl(0, 'IlluminatedWordRead', { bg = '#3c3836', bold = true }) + vim.api.nvim_set_hl(0, 'IlluminatedWordWrite', { bg = '#3c3836', bold = true }) + + -- Map keys to navigate between highlighted words + vim.keymap.set('n', 'hn', function() + require('illuminate').goto_next_reference() + end, { desc = 'Go to next reference' }) + + vim.keymap.set('n', 'hp', function() + require('illuminate').goto_prev_reference() + end, { desc = 'Go to previous reference' }) + end, +} diff --git a/lua/plugins/lsp/overrides.lua b/lua/plugins/lsp/overrides.lua new file mode 100644 index 00000000..6cfa14f9 --- /dev/null +++ b/lua/plugins/lsp/overrides.lua @@ -0,0 +1,45 @@ +---@diagnostic disable: undefined-global +-- Override internal LSP functions to ensure position_encoding is always set + +local M = {} + +function M.setup() + -- Create a wrapper that ensures position_encoding is added to all calls + local function with_encoding(fn) + return function(params, ...) + params = params or {} + if not params.position_encoding then + params.position_encoding = 'utf-16' + end + return fn(params, ...) + end + end + + -- Override standard LSP buffer functions that may be missing position_encoding + vim.lsp.buf.code_action = with_encoding(vim.lsp.buf.code_action) + vim.lsp.buf.rename = with_encoding(vim.lsp.buf.rename) + vim.lsp.buf.hover = with_encoding(vim.lsp.buf.hover) + vim.lsp.buf.formatting = with_encoding(vim.lsp.buf.formatting) + vim.lsp.buf.range_formatting = with_encoding(vim.lsp.buf.range_formatting) + vim.lsp.buf.format = with_encoding(vim.lsp.buf.format) + + -- Patch util functions as well + local orig_make_position_params = vim.lsp.util.make_position_params + vim.lsp.util.make_position_params = function(window, client, position_encoding) + if not position_encoding then + position_encoding = 'utf-16' + end + return orig_make_position_params(window, client, position_encoding) + end + + -- Override symbols_to_items to ensure position_encoding is set + local orig_symbols_to_items = vim.lsp.util.symbols_to_items + vim.lsp.util.symbols_to_items = function(symbols, bufnr, position_encoding) + if not position_encoding then + position_encoding = 'utf-16' + end + return orig_symbols_to_items(symbols, bufnr, position_encoding) + end +end + +return M