Bugfix #353 : Improve adapter discovery. #557
Open
+59
−10
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.
DISCLAIMER: Claude AI helped put together this PR.
Original Problem
When you opened a test file that belonged to a different project/directory than your current working directory (cwd), neotest would fail to find an adapter for that file. This happened because:
_get_adaptermethod would search through already-registered adaptersnil- it never attempted to discover new adaptersReal-World Scenario
Imagine you have:
/home/user/project-a/(your cwd when neotest starts)/home/user/project-b/test_file.py(a file you open later)When you opened
project-b/test_file.py, neotest would fail to recognize it as a test file because it never registered an adapter forproject-b. The adapter discovery only happened:The Fix
We modified
_get_adapterto implement lazy adapter discovery:_update_adapters(dir)for the file's parent directoryBenefits
✅ On-demand adapter discovery: Adapters are now discovered when needed, not just at startup
✅ Multi-project support: You can work with test files from multiple projects without restarting
✅ Reuses existing infrastructure: Leverages the existing _update_adapters method instead of duplicating logic
✅ Minimal performance impact: Only triggers when an adapter isn't found
✅ Safe: Only runs after client has started to avoid initialization issues
What This Enables
Users can now:
Fixes #353