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

fix: don't crawl cwd when adding a new buffer #442

Closed
wants to merge 1 commit into from

Conversation

stevearc
Copy link
Contributor

If you recall a long time ago I advocated for the option to set discovery.enabled = false because I work with a large repo and crawling it for tests causes Neovim to be nearly frozen for 20+ minutes while pegging the CPU. I noticed this behavior again recently, and tracked it down to this:

autocmd({ "BufAdd", "BufWritePost" }, function(ev)
local file_path = vim.fn.fnamemodify(ev.file, ":p")
if not lib.files.exists(file_path) then
return
end

For me, this was happening when I opened the quickfix, but the key is just that BufAdd was getting triggered for a non-file buffer. This lead to ev.file being an empty string, and when you pass that in to fnamemodify you get vim.fn.fnamemodify("", ":p") which returns your current directory. It looks like the intent of this autocmd is to check for changes to existing files or creation of new files and re-searching the parent directory for tests. What was actually happening was we were passing that file_path into self._update_positions lower down in that function

self:_update_positions(file_path, { adapter = adapter_id })

Which resulted in a recursive search originating from the current working directory.

The fix that I opted to put in here was just to early return if the ev.file is an empty string, since it seems like neotest probably shouldn't care about those buffers.

@stevearc stevearc deleted the stevearc-discovery branch September 30, 2024 21:16
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

Successfully merging this pull request may close these issues.

2 participants