LunarVim / LunarVim

🌙 LunarVim is an IDE layer for Neovim. Completely free and community driven.
https://www.lunarvim.org
GNU General Public License v3.0
18.47k stars 1.51k forks source link

Telescope previewer times out in big projects #2434

Closed expoure closed 2 years ago

expoure commented 2 years ago

Problem description

1 - open a big project 2 - try navigate in telescope

below a compartion between nvim and lvim

my nvim configuration for telescope: `if !exists('g:loaded_telescope') | finish | endif

nnoremap ;f lua require('telescope.builtin').find_files() nnoremap ;r lua require('telescope.builtin').live_grep() nnoremap ;b lua require('telescope.builtin').file_browser() nnoremap \ Telescope buffers nnoremap ;; Telescope help_tags

lua << EOF function telescope_buffer_dir() return vim.fn.expand('%:p:h') end

local telescope = require('telescope') local actions = require('telescope.actions')

telescope.setup{ defaults = { mappings = { n = { ["q"] = actions.close }, }, } } EOF`

https://user-images.githubusercontent.com/12136268/162202466-7d695897-664f-4020-ad0a-e3ea5580bfab.mp4

LunarVim version

master-23feb96

Neovim version (>= 0.6.1)

0.6.1

Operating system/version

Archlinux

Relevant log output

No output

Screenshots

No response

abzcoding commented 2 years ago

have you installed the telescope dependencies? ( fd-find and rg )

if yes, then you can try this ( to make sure telescope doesn't index useless files)

lvim.builtin.telescope.defaults.file_ignore_patterns = {
    "vendor/*",
    "%.lock",
    "__pycache__/*",
    "%.sqlite3",
    "%.ipynb",
    "node_modules/*",
    "%.jpg",
    "%.jpeg",
    "%.png",
    "%.svg",
    "%.otf",
    "%.ttf",
    ".git/",
    "%.webp",
    ".dart_tool/",
    ".github/",
    ".gradle/",
    ".idea/",
    ".settings/",
    ".vscode/",
    "__pycache__/",
    "build/",
    "env/",
    "gradle/",
    "node_modules/",
    "target/",
    "%.pdb",
    "%.dll",
    "%.class",
    "%.exe",
    "%.cache",
    "%.ico",
    "%.pdf",
    "%.dylib",
    "%.jar",
    "%.docx",
    "%.met",
    "smalljre_*/*",
    ".vale/",
    "%.burp",
    "%.mp4",
    "%.mkv",
    "%.rar",
    "%.zip",
    "%.7z",
    "%.tar",
    "%.bz2",
    "%.epub",
    "%.flac",
    "%.tar.gz",
  }
expoure commented 2 years ago

It does not work. The lag happens even when I filter by few files :/

https://user-images.githubusercontent.com/12136268/162248078-caae2905-c5ca-4c7c-b5ce-ea86eff5bbe1.mp4

abzcoding commented 2 years ago

hmm, @kylo252 any ideas what might cause this?

kylo252 commented 2 years ago

please share the output of :checkhealth telescope

expoure commented 2 years ago

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

Checking for required plugins

Checking external dependencies

===== Installed extensions =====

Telescope Extension: fzf

Telescope Extension: projects

kylo252 commented 2 years ago

Looking at that demo again, the project isn't that big, and it seems that only the previewer is slow.

expoure commented 2 years ago

With no previewer there is no lag. I run TSUpdate, restart lvim and telescope with lvim default config still lagging...

kylo252 commented 2 years ago

I don't really think there's anything to be done from lunarvim's side to be honest. Seems like a bottleneck somewhere between treesitter and telescope. You have actually installed the parser for typescript, right?

some more things to try

then search the issue tracker of either plugin, depending on the outcome of the 2 earlier tests

abzcoding commented 2 years ago

i mean you can try a couple of things as well

  1. using a higher previewer timeout
    :Telescope find_files preview={timeout=1000}
  2. use different previewers
    
    local previewers = require "telescope.previewers"
    lvim.builtin.telescope.file_previewer = previewers.vim_buffer_cat.new --use other ones

--- - previewers.cat --- - previewers.vimgrep --- - previewers.qflist --- - previewers.vim_buffer_cat --- - previewers.vim_buffer_vimgrep --- - previewers.vim_buffer_qflist

expoure commented 2 years ago

None of the alternatives worked... what intrigues me is that in nvim works perfectly. I also set this lvim.builtin.telescope.defaults = {} but it keeps lagging.

abzcoding commented 2 years ago

None of the alternatives worked... what intrigues me is that in nvim works perfectly. I also set this lvim.builtin.telescope.defaults = {} but it keeps lagging.

I actually would love to get to the bottom of this, this probably is caused because of some autocommand/misconfiguration on our part, but I'm not quite sure where to begin debugging it 😅 so I think we should keep this issue open until someone comes up with a solution

frontendwizard commented 2 years ago

I'm experiencing the same issue here

frontendwizard commented 2 years ago

specifically on my case, when the project is new and git hasn't been initialised yet, telescope with preview is incredibly slow. After I initialise git, the delay is gone and the preview works normally again. Adding it here cause it might be a good lead on why.

kylo252 commented 2 years ago

specifically on my case, when the project is new and git hasn't been initialised yet, telescope with preview is incredibly slow. After I initialise git, the delay is gone and the preview works normally again. Adding it here cause it might be a good lead on why.

Which command is specifically slow? is it :Telescope find_files? or are you using the mapping <leader>f because that one is bound to use this function https://github.com/LunarVim/LunarVim/blob/7712a63e7f1189788fd99be2f0af1159acf54b14/lua/lvim/core/telescope/custom-finders.lua#L87-L95

LandonSchropp commented 2 years ago

I'm experiencing lag when trying to use Telescope in a large Rails project. For example, if I want to open the config/test.rb file, I type test and see the UI update immediately with bad results. However, a couple of seconds later, the results update again with the correct match.

expoure commented 2 years ago

i just updated nvim to 0.7 and the telescope error disappeared...

kylo252 commented 2 years ago

I'm experiencing lag when trying to use Telescope in a large Rails project. For example, if I want to open the config/test.rb file, I type test and see the UI update immediately with bad results. However, a couple of seconds later, the results update again with the correct match.

just a sanity check, but you have installed a treesitter parser for ruby, right? and the performance there is acceptable?

LandonSchropp commented 2 years ago

just a sanity check, but you have installed a treesitter parser for ruby, right? and the performance there is acceptable?

Yep (assuming it was installed automatically by LunarVIm). Syntax highlight seems to work without a perceptible lag, so it seems to be working well. The null-ls Rubocop checks take about a second to run, but I think that's normal performance for Rubocop.

I have a gut feeling that this might be related to #2514, specifically, it being slow in projects with a large number of commits. I added a repro case to that PR for a project with a semi-large number of commits, and I noticed a perceptible slowdown for Telescope.

kylo252 commented 2 years ago

are you sure you're not somehow bottlenecked with your git version? I can't reproduce this with https://github.com/LandonSchropp/lunar-vim-example-issue either.

LandonSchropp commented 2 years ago

Hmm, I don't think so. I'm running 2.35.1 currently, which is fairly up-to-date.

Are you maybe using a more powerful machine than me? Could you try generating another 100,000 commits using the script in that repo and seeing if you still don't have any performance issues?

chsjr1996 commented 2 years ago

Hello everyone! I'm current using the Neovim 0.7 and I'm experiencing some lag when trying to use Telescope in some projects, specially in projects with minified JS files.

I'm found this issue on Telescope repository Telescope live_grep freezes nvim sometimes and following this comment I've changed the /.local/share/lunarvim/lvim/lua/lvim/core/telescope.lua file, adding this (preview.treesitter = false) on lvim.builtin.telescope.defaults section (line 16):

-- ...
  lvim.builtin.telescope = vim.tbl_extend("force", lvim.builtin.telescope, {
    defaults = {
      preview = {
        treesitter = false,
      },
      prompt_prefix = "ï‘« ",
-- ...

image

After this change, the Telescope find and live_grep modes works much more faster here!

kylo252 commented 2 years ago

I've changed the /.local/share/lunarvim/lvim/lua/lvim/core/telescope.lua file, adding this (preview.treesitter = false) on lvim.builtin.telescope.defaults section (line 16):

This is more of a hammer fix that isn't really needed

specially in projects with minified JS files.

you've identified the problem here, and so you can achieve the same thing in multiple more flexible ways

alternative 1

turn off treesitter for js until they fix the parser, :TSUninstall javascript typescript

-- remove it from this list
lvim.builtin.treesitter.ensure_installed = { "lua", "c", --[[ ... ]] }

alternative 2

create another telescope function that doesn't use the treesitter previewer which you can use in those projects

local function grep_no_ts()
  require("telescope.builtin").live_grep { preview = { treesitter = false }, prompt_title = "no treesitter" }
end

-- add a keybind for it for easier access
vim.keymap.set("n", "<c-f>", grep_no_ts)

alternative 3

if you're still not happy with all of this, simply use your solution like this

lvim.builtin.telescope.defaults.preview = { treesitter = false }
-- I think you can even do this
-- lvim.builtin.telescope.defaults.live_grep.preview = { treesitter = false }
chsjr1996 commented 2 years ago

@kylo252 I forgot of this option (alternative 1), it's works much more better, thank you!

gligorot commented 1 year ago

The actual problem on my side were too many open buffers, most of them unused. For closing all buffers you can use: :up | %bd | e#. Then reopen with <Space>bo as needed.

I can't find the original source, but here very similar commands are listed.