nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.59k stars 827 forks source link

Previewer errors out when there is no treesitter parser for the detected filetype #3314

Closed ChristianHeinigk closed 23 hours ago

ChristianHeinigk commented 1 day ago

Description

When previewing a file, which does not have a treesitter parser, on nvim v0.11 an error is thrown. This change always uses pcall to try to add the treesitter parser for the detected filetype. Hence, the success and a message is returned and the previewer can gracefully just display the file's contents without highlighting.

Neovim version

NVIM v0.11.0-dev-616+gfd65422b9
Build type: RelWithDebInfo
LuaJIT 2.1.1723675123

Operating system and version

Windows 11 Enterprise

Telescope version / branch / rev

main

checkhealth telescope

==============================================================================
telescope: require("telescope.health").check()

Checking for required plugins ~
- OK plenary installed.
- OK nvim-treesitter installed.

Checking external dependencies ~
- OK rg: found ripgrep 14.1.0 (rev e50df40a19)
- WARNING fd: not found. Install [sharkdp/fd](https://github.com/sharkdp/fd) for extended capabilities

===== Installed extensions ===== ~

Telescope Extension: `dap` ~
- No healthcheck provided

Telescope Extension: `refactoring` ~
- No healthcheck provided

Steps to reproduce

  1. echo ' .file "test.cpp"' > test.s
  2. nvim -nu init.lua
  3. :lua require"telescope.builtin".find_files()
  4. Type test.s
  5. search for an existing file with a filetype for which no treesitter parser exists, in this case test.s which requires the asm parser

Expected behavior

The preview window shows the contents without any highlighting.

Actual behavior

Error executing vim.schedule lua callback: ...eovim/share/nvim/runtime/lua/vim/treesitter/language.lua:107: no parser for 'asm' language, see :help treesitter-parsers
stack traceback:
        [C]: in function 'error'
        ...eovim/share/nvim/runtime/lua/vim/treesitter/language.lua:107: in function 'has_ts_parser'
        ...lugins/telescope.nvim/lua/telescope/previewers/utils.lua:173: in function 'ts_highlighter'
        ...lugins/telescope.nvim/lua/telescope/previewers/utils.lua:154: in function 'highlighter'
        ...scope.nvim/lua/telescope/previewers/buffer_previewer.lua:233: in function 'fn'
        vim/_editor.lua:351: in function <vim/_editor.lua:350>

Minimal config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs { "config", "data", "state", "cache" } do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.uv.fs_stat(lazypath) then
  vim.fn.system {
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  }
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "nvim-telescope/telescope.nvim",
    dependencies = {
      "nvim-lua/plenary.nvim",
    },
    config = function()
      -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
      require("telescope").setup {}
    end,
  },
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})
jamestrew commented 23 hours ago

As mentioned in your PR, this should already be resolved by https://github.com/nvim-telescope/telescope.nvim/pull/3308