forked from niuiic/blink-cmp-rg.nvim
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(debug,opt-in): temporarily highlight the search prefix (#95)
Issue ===== It's hard to understand when exactly ripgrep is called to find matching words in the project. This is an important concern because of performance - ripgrep can take a long time to search through a large project. Solution ======== Temporarily highlight the search prefix when a new ripgrep search is started. This will help users and maintainers understand the behavior of the plugin. To enable this feature, set `debug` to `true` in the configuration. It's recommended to only enable this feature when debugging the plugin.
- Loading branch information
1 parent
182da8e
commit 7854eee
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
local visualization = {} | ||
|
||
local ns_id = vim.api.nvim_create_namespace("blink_ripgrep_debug") | ||
|
||
vim.api.nvim_set_hl( | ||
0, | ||
"BlinkRipgrepSearchPrefix", | ||
{ link = "Search", default = true } | ||
) | ||
|
||
---@param prefix string | ||
function visualization.flash_search_prefix(prefix) | ||
vim.api.nvim_buf_clear_namespace(0, ns_id, 0, -1) | ||
local cursor = vim.api.nvim_win_get_cursor(0) | ||
|
||
local hlstart = cursor[2] - #prefix | ||
local hlend = cursor[2] | ||
vim.api.nvim_buf_add_highlight( | ||
0, | ||
ns_id, | ||
"BlinkRipgrepSearchPrefix", | ||
cursor[1] - 1, | ||
hlstart, | ||
hlend | ||
) | ||
|
||
vim.defer_fn(function() | ||
vim.api.nvim_buf_clear_namespace(0, ns_id, 0, -1) | ||
end, 500) | ||
end | ||
|
||
return visualization |