nvim-telescope / telescope-file-browser.nvim

File Browser extension for telescope.nvim
MIT License
1.6k stars 89 forks source link

files = true opt for picker = freeze / 100% CPU load #371

Closed scippio closed 3 months ago

scippio commented 3 months ago

Description

I'm using file browser in my plugin like:

local file_browser = require("telescope._extensions.file_browser")
local path = vim.loop.cwd()

file_browser.exports.file_browser({
  cwd = path,
  files = false,
  attach_mappings = function(props, map)
    ...
  end,
})

With files = true or nothing (because it's default) everything is ok. The browser opens etc... But with files = false browser freeze and CPU go up to 100%:

image

Neovim version

NVIM v0.9.5                                                                                                                                                                                                                                     
Build type: Release                                                                                                                                                                                                                             
LuaJIT 2.1.1702233742

Operating system and version

Archlinux

Steps to reproduce

  1. Run nvim and open file browser

Expected behavior

do not freeze

Actual behavior

freeze

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.loop.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-file-browser.nvim",
    dependencies = {
      "nvim-telescope/telescope.nvim",
      "nvim-lua/plenary.nvim",
    },
    config = function()
      require("telescope").setup({})
      require("telescope").load_extension("file_browser")
    end,
  },
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})
scippio commented 3 months ago

I found that not really freeze but it scanning my whole directory tree! and it takes very long time. I tried adding depth = 1, but it didn't help.

scippio commented 3 months ago

Maybe I don't understand what is this option for. I want directories browser only, without any preview... Just for directory selecting. :thinking:

jamestrew commented 3 months ago

Are you using fd? files=false let's you fuzzy find over all directories in your cwd with no depth limit. But you can do something like :Telescope file_browser files=false depth=1 previewer=false. This give me only directories in the current directory with no previewer.

scippio commented 3 months ago

Oh, that looks interesting. Thanks. I'm closing this because I realized I'm loading config after loading extensions and that's ignore my setup :facepalm: Everything looks fine now.