From 99a89934d0ddf96fa2e646065eb9f3c089551e8e Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Thu, 17 Apr 2025 21:21:29 +0300 Subject: [PATCH] Force eval treesitter + Actually display the errors --- lua/telescope/builtin/__files.lua | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lua/telescope/builtin/__files.lua b/lua/telescope/builtin/__files.lua index 27b8d1c927..d0f7636de8 100644 --- a/lua/telescope/builtin/__files.lua +++ b/lua/telescope/builtin/__files.lua @@ -423,7 +423,8 @@ 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", @@ -431,6 +432,11 @@ files.treesitter = function(opts) 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 @@ -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",