Skip to content

fix(builtin.treesitter) Force eval treesitter #3449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions lua/telescope/builtin/__files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,20 @@ files.treesitter = function(opts)
end

local parsers = require "nvim-treesitter.parsers"
if not parsers.has_parser(parsers.get_buf_lang(opts.bufnr)) then
local lang = parsers.get_buf_lang(opts.bufnr)
if not parsers.has_parser(lang) then
utils.notify("builtin.treesitter", {
msg = "No parser for the current buffer",
level = "ERROR",
})
return
end

-- force evaluation, don't wait for it to lazily load
local parser = vim.treesitter.get_parser(opts.bufnr, lang)
---@diagnostic disable-next-line: need-check-nil
parser:parse()

local ts_locals = require "nvim-treesitter.locals"
local results = {}
for _, definition in ipairs(ts_locals.get_definitions(opts.bufnr)) do
Expand All @@ -441,16 +447,23 @@ files.treesitter = function(opts)
end
end

results = utils.filter_symbols(results, opts)
if vim.tbl_isempty(results) then
-- error message already printed in `utils.filter_symbols`
utils.notify("builtin.treesitter", {
msg = "Parser provided no results",
level = "ERROR",
})
return
end

results = utils.filter_symbols(results, opts)

if vim.tbl_isempty(results) then
utils.notify("builtin.treesitter", {
msg = "Parser gave results, but we filtered them all away",
level = "ERROR",
})
return
end

pickers
.new(opts, {
prompt_title = "Treesitter Symbols",
Expand Down