summaryrefslogtreecommitdiff
path: root/lua/telescope/builtin
diff options
context:
space:
mode:
authorSimon Hauser <Simon-Hauser@outlook.de>2023-02-20 22:43:15 +0100
committerGitHub <noreply@github.com>2023-02-20 22:43:15 +0100
commita486ac3e8fb2198f3636da1927ed57a28836fbd8 (patch)
tree87417a960434ea51b2bf717458c883e2530cba1c /lua/telescope/builtin
parent3915d933dc19d31571d2953ca9461fe6fa117a6e (diff)
fix: current_buffer_fuzzy_find highlighter (#2394)
Diffstat (limited to 'lua/telescope/builtin')
-rw-r--r--lua/telescope/builtin/__files.lua21
1 files changed, 16 insertions, 5 deletions
diff --git a/lua/telescope/builtin/__files.lua b/lua/telescope/builtin/__files.lua
index afb3d5a..3c2d259 100644
--- a/lua/telescope/builtin/__files.lua
+++ b/lua/telescope/builtin/__files.lua
@@ -456,9 +456,6 @@ files.current_buffer_fuzzy_find = function(opts)
if parser_ok and query_ok and ts_ok and ts_configs.is_enabled("highlight", filetype, opts.bufnr) then
local root = parser:parse()[1]:root()
- local highlighter = vim.treesitter.highlighter.new(parser)
- local highlighter_query = highlighter:get_query(filetype)
-
local line_highlights = setmetatable({}, {
__index = function(t, k)
local obj = {}
@@ -469,9 +466,23 @@ files.current_buffer_fuzzy_find = function(opts)
-- update to changes on Neovim master, see https://github.com/neovim/neovim/pull/19931
-- TODO(clason): remove when dropping support for Neovim 0.7
- local on_nvim_master = vim.fn.has "nvim-0.8" == 1
+ local get_hl_from_capture = (function()
+ if vim.fn.has "nvim-0.8" == 1 then
+ return function(q, id)
+ return "@" .. q.captures[id]
+ end
+ else
+ local highlighter = vim.treesitter.highlighter.new(parser)
+ local highlighter_query = highlighter:get_query(filetype)
+
+ return function(_, id)
+ return highlighter_query:_get_hl_from_capture(id)
+ end
+ end
+ end)()
+
for id, node in query:iter_captures(root, opts.bufnr, 0, -1) do
- local hl = on_nvim_master and query.captures[id] or highlighter_query:_get_hl_from_capture(id)
+ local hl = get_hl_from_capture(query, id)
if hl and type(hl) ~= "number" then
local row1, col1, row2, col2 = node:range()