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

File picker for #file: may cause the editor to freeze when cwd has large number of files #690

Open
unlimitedsola opened this issue Dec 14, 2024 · 0 comments

Comments

@unlimitedsola
Copy link

When hitting <Tab> after #file:, it may cause the editor to freeze when the current working directory has a large number of files (e.g.: working in a Rust project where target/ directory contains a large number of compiled objects.)

I assume this is caused by globbing too many files into the table here:

local files = vim.tbl_filter(function(file)
return vim.fn.isdirectory(file) == 0
end, vim.fn.glob(cwd .. '/**/*', false, true))

I read that this plugin has fzf-lua support but after digging into the source code a little bit it seems that the relevant code is no longer in use.

Since the plugin exposes the context configuration so I did an ad-hoc fix for this to avoid loading too many files into the memory:

{
  "CopilotC-Nvim/CopilotChat.nvim",
  opts = {
    contexts = {
      file = {
        input = function(callback)
          local fzf = require('fzf-lua')
          local fzf_path = require('fzf-lua.path')
          fzf.files({
            complete = function(selected, opts)
              local file = fzf_path.entry_to_file(selected[1], opts, opts._uri)
              if file.path == "none" then return end
              vim.defer_fn(function()
                callback(file.path)
              end, 100)
            end
          })
        end
      }
    }

  }
}

I think it is worth having such behavior by default so that it is easier to work with large projects. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant