mirror of
https://github.com/tiyn/action-hints.nvim.git
synced 2025-11-13 13:59:45 +01:00
Switch to update on cursor move
This commit is contained in:
12
README.md
12
README.md
@@ -45,23 +45,15 @@ use({
|
|||||||
{ " ↱%s", "ActionHintsReferences" },
|
{ " ↱%s", "ActionHintsReferences" },
|
||||||
},
|
},
|
||||||
use_virtual_text = true,
|
use_virtual_text = true,
|
||||||
|
definition_color = "#add8e6",
|
||||||
|
reference_color = "#ff6666",
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
Adjust highlight colours for virtual text:
|
|
||||||
|
|
||||||
```
|
|
||||||
highlight ActionHintsDefinition guifg=#add8e6
|
|
||||||
highlight ActionHintsReferences guifg=#ff6666
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Note that for now the component must be included in the lualine for the virtual text to
|
|
||||||
be updated.
|
|
||||||
|
|
||||||
As a lualine component:
|
As a lualine component:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ M.config = {
|
|||||||
{ " ↱%s", "ActionHintsReferences" },
|
{ " ↱%s", "ActionHintsReferences" },
|
||||||
},
|
},
|
||||||
use_virtual_text = false,
|
use_virtual_text = false,
|
||||||
|
definition_color = "#add8e6",
|
||||||
|
reference_color = "#ff6666",
|
||||||
}
|
}
|
||||||
|
|
||||||
M.references_available = false
|
M.references_available = false
|
||||||
@@ -38,13 +40,12 @@ local function set_virtual_text(bufnr, line, chunks)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check if the current buffer is a regular file buffer
|
|
||||||
if
|
if
|
||||||
vim.api.nvim_buf_get_option(bufnr, "buftype") ~= ""
|
vim.api.nvim_buf_get_option(bufnr, "buftype") ~= ""
|
||||||
or vim.api.nvim_buf_get_option(bufnr, "filetype") == "help"
|
or vim.api.nvim_buf_get_option(bufnr, "filetype") == "help"
|
||||||
or vim.fn.bufname(bufnr) == ""
|
or vim.fn.bufname(bufnr) == ""
|
||||||
then
|
then
|
||||||
return -- Skip setting virtual text for non-editor buffers
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_buf_set_virtual_text(bufnr, references_namespace, line, chunks, {})
|
vim.api.nvim_buf_set_virtual_text(bufnr, references_namespace, line, chunks, {})
|
||||||
@@ -126,10 +127,12 @@ end
|
|||||||
local debounced_references = debounce(references, 100)
|
local debounced_references = debounce(references, 100)
|
||||||
local debounced_definition = debounce(definition, 100)
|
local debounced_definition = debounce(definition, 100)
|
||||||
|
|
||||||
M.statusline = function()
|
M.update = function()
|
||||||
debounced_references()
|
debounced_references()
|
||||||
debounced_definition()
|
debounced_definition()
|
||||||
|
end
|
||||||
|
|
||||||
|
M.statusline = function()
|
||||||
local definition_status = M.definition_available and " ⊛" or ""
|
local definition_status = M.definition_available and " ⊛" or ""
|
||||||
local reference_status = M.reference_count > 0 and " ↱" .. tostring(M.reference_count) or ""
|
local reference_status = M.reference_count > 0 and " ↱" .. tostring(M.reference_count) or ""
|
||||||
local chunks = {
|
local chunks = {
|
||||||
@@ -156,14 +159,18 @@ M.setup = function(options)
|
|||||||
options = {}
|
options = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Merge user supplied options with defaults
|
|
||||||
for k, v in pairs(options) do
|
for k, v in pairs(options) do
|
||||||
M.config[k] = v
|
M.config[k] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set default colors for ActionHintsDefinition and ActionHintsReferences
|
local defColor = M.config.definition_color
|
||||||
vim.api.nvim_command("highlight ActionHintsDefinition guifg=#add8e6")
|
local refColor = M.config.reference_color
|
||||||
vim.api.nvim_command("highlight ActionHintsReferences guifg=#ff6666")
|
|
||||||
|
vim.api.nvim_command("highlight ActionHintsDefinition guifg=" .. defColor)
|
||||||
|
vim.api.nvim_command("highlight ActionHintsReferences guifg=" .. refColor)
|
||||||
|
|
||||||
|
vim.api.nvim_command([[autocmd CursorMoved * lua require("action-hints").update()]])
|
||||||
|
vim.api.nvim_command([[autocmd CursorMovedI * lua require("action-hints").update()]])
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user