Skip to content
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

Disable highlight in preview base on a config array of function #3150

Open
Fildo7525 opened this issue Jun 1, 2024 · 6 comments
Open

Disable highlight in preview base on a config array of function #3150

Fildo7525 opened this issue Jun 1, 2024 · 6 comments
Labels
bug Something isn't working not reproducible question Further information is requested

Comments

@Fildo7525
Copy link

Description

If you do not have a treesitter for a specific filetype for me it's latex you get errors every time your cursor is on a filetype.
The filetype is disabled in treesitter.

Error in decoration provider treesitter/highlighter.win:
Error executing lua: ...-linux64/share/nvim/runtime/lua/vim/treesitter/query.lua:252: Query error at 74:3. Impossible pattern:
  name: (curly_group_text_list
  ^

stack traceback:
        [C]: in function '_ts_parse_query'
        ...-linux64/share/nvim/runtime/lua/vim/treesitter/query.lua:252: in function 'fn'
        ...vim-linux64/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'fn'
        ...vim-linux64/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'get'
        ...64/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:28: in function 'new'
        ...64/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:240: in function 'get_query'
        ...64/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:188: in function 'fn'
        ...4/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:473: in function 'for_each_tree'
        ...64/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:175: in function 'prepare_highlight_states'
        ...64/share/nvim/runtime/lua/vim/treesitter/hig

It's extremely annoying. It would be great to have a filed in the config that accepts either table or function that determines if the filetype should use treesitter in the preview or not.

Neovim version

NVIM v0.11.0-dev-67+g0e9c92a90
Build type: RelWithDebInfo
LuaJIT 2.1.1713484068

Operating system and version

ubuntu 22.04

Telescope version / branch / rev

telescope 0.1.7

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 13.0.0
- OK fd: found fd 8.3.1

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

Telescope Extension: `clang_reloader` ~
- No healthcheck provided

Telescope Extension: `projects` ~
- No healthcheck provided

Steps to reproduce

  1. open project with files that you do not have treesitter on
  2. file_file with preview
  3. scroll the files and find the file in the telescope.

Expected behavior

The treesitter will not be applied

Actual behavior

Even thou I have in my treesitter config latex disabled I still get errors for the treesitter, that it could not parse the preview

Minimal config

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]
local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'
local function load_plugins()
  require('packer').startup {
    {
      'wbthomason/packer.nvim',
      {
        'nvim-telescope/telescope.nvim',
        requires = {
          'nvim-lua/plenary.nvim',
          { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' },
        },
      },
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. '/plugin/packer_compiled.lua',
      display = { non_interactive = true },
    },
  }
end
_G.load_config = function()
  require('telescope').setup()
  require('telescope').load_extension('fzf')
  -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Installing Telescope and dependencies.")
  vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }
end
load_plugins()
require('packer').sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]
@Fildo7525 Fildo7525 added the bug Something isn't working label Jun 1, 2024
@jamestrew
Copy link
Contributor

You don't have a tree-sitter parser for latex or you have it but have the tree-sitter highlighting disabled?

I can't reproduce this with your provided instructions. Please edit the minimal config in the bug report to add the minimum number of changes needed to reproduce this error.

@jamestrew jamestrew added question Further information is requested not reproducible labels Jun 6, 2024
@bn-peters
Copy link
Contributor

bn-peters commented Jun 11, 2024

I also had this issue. I might be able to construct a minimal config etc. on the weekend, but for now:

It appears that this happens if a TS parser is installed with highlighting is disabled, like this:

require("nvim-treesitter.configs").setup({
    ensure_installed = { "latex" },
    highlight = {
        enable = true,
        disable =  { "latex" },
    },
})

There are usecases for this when you want to use external syntax highlighting and plugins relying on tree-sitter. For now my workaround is uninstalling the latex parser.

@jamestrew
Copy link
Contributor

Thanks for the additional info.

Here's a minimal config I tried:

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-treesitter/nvim-treesitter",
    build = ":TSUpdate",
    config = function()
      require("nvim-treesitter.configs").setup({
        ensure_installed = { "latex" },
        highlight = {
          enable = true,
          disable = { "latex" },
        },
      })
    end,
  },

  -- seeing if this makes a difference
  {
    "lervag/vimtex",
    lazy = false,
    enabled = false,
  },
  { "folke/tokyonight.nvim" }, -- just so I can tell highlighting is on/off
  {
    "nvim-telescope/telescope.nvim",
    tag = "0.1.7",
    dependencies = {
      "nvim-lua/plenary.nvim",
    },
    opts = {},
  },
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")

Still not able to reproduce.

@Conni2461
Copy link
Member

You can disable highlighting for specific languages within telescope. Checkout :help telescope.defaults.preview to e.g. disable treesitter highlighting only for latex within our previewer. Let me know if that works, i am currently on mobile and confirm that this still works but i am confident right now that ive implemented support for this

@kunzaatko
Copy link

I can confirm that this is working. The relevant part of opts is

defaults = {
  preview = {
    treesitter = {
      enable = true,
      disable = { 'tex' }, -- NOTE: https://github.com/nvim-telescope/telescope.nvim/issues/3150 <17-06-24>
    },
}

@kunzaatko
Copy link

kunzaatko commented Jun 17, 2024

What however does not work is

require('telescope.builtin').current_buffer_fuzzy_find

where you could only disable highlighting globally.
You won't get the colours but for avoiding the error, you can define your mapping as

function()
  require('telescope.builtin').current_buffer_fuzzy_find { results_ts_highlight = vim.o.filetype ~= 'tex' }
end,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working not reproducible question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants