Skip to content

Commit f0caedf

Browse files
jensenojsclason
authored andcommitted
fix(current_buffer_fuzzy_find): handle missing TS highlights query
1 parent da6992d commit f0caedf

1 file changed

Lines changed: 35 additions & 32 deletions

File tree

lua/telescope/builtin/__files.lua

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -477,50 +477,53 @@ files.current_buffer_fuzzy_find = function(opts)
477477
})
478478
end
479479

480+
-- TODO(clason): refactor when dropping support for Nvim 0.10 (no option, no filetype fallback)
480481
opts.results_ts_highlight = vim.F.if_nil(opts.results_ts_highlight, true)
481482
local lang = vim.treesitter.language.get_lang(filetype) or filetype
482483
if opts.results_ts_highlight and lang and utils.has_ts_parser(lang) then
483484
local parser = vim.treesitter.get_parser(opts.bufnr, lang)
484485
local query = vim.treesitter.query.get(lang, "highlights")
485-
local root = parser:parse()[1]:root()
486-
487-
local line_highlights = setmetatable({}, {
488-
__index = function(t, k)
489-
local obj = {}
490-
rawset(t, k, obj)
491-
return obj
492-
end,
493-
})
494-
495-
for id, node in query:iter_captures(root, opts.bufnr, 0, -1) do
496-
local hl = "@" .. query.captures[id]
497-
if hl and type(hl) ~= "number" then
498-
local row1, col1, row2, col2 = node:range()
499-
500-
if row1 == row2 then
501-
local row = row1 + 1
502-
503-
for index = col1, col2 do
504-
line_highlights[row][index] = hl
505-
end
506-
else
507-
local row = row1 + 1
508-
for index = col1, #lines[row] do
509-
line_highlights[row][index] = hl
510-
end
486+
if query then
487+
local root = parser:parse()[1]:root()
488+
489+
local line_highlights = setmetatable({}, {
490+
__index = function(t, k)
491+
local obj = {}
492+
rawset(t, k, obj)
493+
return obj
494+
end,
495+
})
496+
497+
for id, node in query:iter_captures(root, opts.bufnr, 0, -1) do
498+
local hl = "@" .. query.captures[id]
499+
if hl and type(hl) ~= "number" then
500+
local row1, col1, row2, col2 = node:range()
501+
502+
if row1 == row2 then
503+
local row = row1 + 1
504+
505+
for index = col1, col2 do
506+
line_highlights[row][index] = hl
507+
end
508+
else
509+
local row = row1 + 1
510+
for index = col1, #lines[row] do
511+
line_highlights[row][index] = hl
512+
end
511513

512-
while row < row2 + 1 do
513-
row = row + 1
514+
while row < row2 + 1 do
515+
row = row + 1
514516

515-
for index = 0, #(lines[row] or {}) do
516-
line_highlights[row][index] = hl
517+
for index = 0, #(lines[row] or {}) do
518+
line_highlights[row][index] = hl
519+
end
517520
end
518521
end
519522
end
520523
end
521-
end
522524

523-
opts.line_highlights = line_highlights
525+
opts.line_highlights = line_highlights
526+
end
524527
end
525528

526529
pickers

0 commit comments

Comments
 (0)