-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhighlight.lua
More file actions
73 lines (59 loc) · 1.92 KB
/
highlight.lua
File metadata and controls
73 lines (59 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
local M = {}
---Used to keep track of if LSP reference highlights should be enabled
local highlight_references = false
local highlight_namespace = vim.api.nvim_create_namespace('RefjumpReferenceHighlights')
local reference_hl_name = 'RefjumpReference'
function M.create_fallback_hl_group(fallback_hl)
local hl = vim.api.nvim_get_hl(0, { name = reference_hl_name })
if vim.tbl_isempty(hl) then
vim.api.nvim_set_hl(0, reference_hl_name, { link = fallback_hl })
end
end
---@deprecated Use `enable()` instead
function M.enable_reference_highlights(references, bufnr)
local message = 'refjump.nvim: `enable_reference_highlights()` has been renamed to `enable()`'
vim.notify(message, vim.log.levels.WARN)
M.enable(references, bufnr)
end
function M.enable(references, bufnr)
for _, ref in ipairs(references) do
local line = ref.range.start.line
local start_col = ref.range.start.character
local end_col = ref.range['end'].character
vim.hl.range(
bufnr,
highlight_namespace,
reference_hl_name,
{ line, start_col },
{ line, end_col },
{ inclusive = false }
)
end
highlight_references = true
end
---Check if reference highlights are currently active
---@return boolean
function M.is_active()
return highlight_references
end
---@deprecated Use `disable()` instead
function M.disable_reference_highlights()
local message = 'refjump.nvim: `disable_reference_highlights()` has been renamed to `disable()`'
vim.notify(message, vim.log.levels.WARN)
M.disable()
end
function M.disable()
if not highlight_references then
vim.api.nvim_buf_clear_namespace(0, highlight_namespace, 0, -1)
require('refjump.counter').clear(0)
require('refjump.state').clear()
else
highlight_references = false
end
end
function M.auto_clear_reference_highlights()
vim.api.nvim_create_autocmd({ 'CursorMoved', 'ModeChanged', 'BufLeave' }, {
callback = M.disable,
})
end
return M