1

I have max file size rule for files, setup in treesitter config, it works:

require 'nvim-treesitter.configs'.setup {
 highlight = {
  enable = true,
  is_supported = function()
    if vim.fn.strwidth(vim.fn.getline('.')) > 300 or vim.fn.getfsize(vim.fn.expand('%')) > 1024 * 1024 
    then
      return false
    else
      return true
  end
 }
}

but this setup doesn't work in telescope preview buffer anyway...

I tried this to disable highlight for telescope, but it doesn't work: vim.cmd([[ autocmd User TelescopePreviewerLoaded TSBufDisable highlight ]])

Is there a way to disable Treesiter in Telescope (ideally for big files only)?

UPD 1. Added this to my .config/nvim/after/plugin/telescope.lua

vim.cmd([[
  autocmd User TelescopePreviewerLoaded set filetype=
]])
vim.cmd([[
  autocmd User TelescopeFindPre set filetype=
]])

and no help .. syntax highlinght in file preview works anyway

UPD 2: What interesting, if disable treesitter at all like this:

require 'nvim-treesitter.configs'.setup {
 highlight = {
    enable = false,
 }
}

it successfully disables treesitter in telescope file preview too, but i lose (of course) syntax highlighting in simply opened files

2 Answers 2

0

You can use the User event TelescopePreviewerLoaded to set options on the preview buffer

You disable highlighting you could do:

autocmd User TelescopePreviewerLoaded set filetype=

If you want to only disable highlighting for large file you can replace set filetype= by a custom call or command.

4
  • tried to add ``` vim.cmd([[ autocmd User TelescopePreviewerLoaded set filetype= ]]) vim.cmd([[ autocmd User TelescopeFindPre set filetype= ]]) ``` to my telescope config file, no results. Anyway big file preview is loading 2 minutes Apr 25, 2023 at 10:28
  • Do you still have colorization or not anymore? Apr 25, 2023 at 10:30
  • 1
    Yea, its still colorized Apr 25, 2023 at 10:31
  • I don't have them colorized but for some they are still colorized the first time I visit them in the list. I suspect that the event is called after the file is first displayed. Apr 25, 2023 at 10:34
0

Finally i found a solution, this helped: :h telescope.defaults.preview.:

require('telescope').setup {
  defaults = {
    preview = {
      treesitter = false
    }
  },
}

it disables treesitter in telescope, but unfortunatelly at all.. According to this doc there is a way to disable treesitter by filetype, like preview = { treesitter = { disable = fileTypesTable }} but not by file size anyway

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.