@@ -332,6 +332,7 @@ files.current_buffer_fuzzy_find = function(opts)
332332 -- All actions are on the current buffer
333333 local bufnr = vim .api .nvim_get_current_buf ()
334334 local filename = vim .fn .expand (vim .api .nvim_buf_get_name (bufnr ))
335+ local filetype = vim .api .nvim_buf_get_option (bufnr , " filetype" )
335336
336337 local lines = vim .api .nvim_buf_get_lines (0 , 0 , - 1 , false )
337338 local lines_with_numbers = {}
@@ -345,6 +346,53 @@ files.current_buffer_fuzzy_find = function(opts)
345346 })
346347 end
347348
349+ local ok , parser = pcall (vim .treesitter .get_parser , bufnr , filetype )
350+ if ok then
351+ local query = vim .treesitter .get_query (filetype , " highlights" )
352+
353+ local root = parser :parse ()[1 ]:root ()
354+
355+ local highlighter = vim .treesitter .highlighter .new (parser )
356+ local highlighter_query = highlighter :get_query (filetype )
357+
358+ local line_highlights = setmetatable ({}, {
359+ __index = function (t , k )
360+ local obj = {}
361+ rawset (t , k , obj )
362+ return obj
363+ end ,
364+ })
365+ for id , node in query :iter_captures (root , bufnr , 0 , - 1 ) do
366+ local hl = highlighter_query .hl_cache [id ]
367+ if hl then
368+ local row1 , col1 , row2 , col2 = node :range ()
369+
370+ if row1 == row2 then
371+ local row = row1 + 1
372+
373+ for index = col1 , col2 do
374+ line_highlights [row ][index ] = hl
375+ end
376+ else
377+ local row = row1 + 1
378+ for index = col1 , # lines [row ] do
379+ line_highlights [row ][index ] = hl
380+ end
381+
382+ while row < row2 + 1 do
383+ row = row + 1
384+
385+ for index = 0 , # lines [row ] do
386+ line_highlights [row ][index ] = hl
387+ end
388+ end
389+ end
390+ end
391+ end
392+
393+ opts .line_highlights = line_highlights
394+ end
395+
348396 pickers .new (opts , {
349397 prompt_title = ' Current Buffer Fuzzy' ,
350398 finder = finders .new_table {
0 commit comments