fix: don't crawl cwd when adding a new buffer #442
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:neotest/lua/neotest/client/init.lua
Lines 393 to 398 in 32ff2ac
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 toev.file
being an empty string, and when you pass that in to fnamemodify you getvim.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 thatfile_path
intoself._update_positions
lower down in that functionneotest/lua/neotest/client/init.lua
Line 438 in 32ff2ac
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.