Support multiple test file matches in go to relevant file #3790
+77
−12
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.

Motivation
Closes #3789
"Go to relevant file" currently fails when tests for an implementation file are split into multiple test files within a subdirectory (e.g.,
user.rbhaving tests likeuser/creation_test.rb). This makes it harder to discover and maintain these split tests. This PR extends the feature to find all associated tests within a matching subdirectory.Instead of opening all found files at once, we present a list for the developer to select from. This gives developers control over which file to open rather than flooding their editor with tabs.
Example image
Implementation
The implementation was changed to search using multiple glob patterns instead of just one. This involved refactoring the old
relevant_filename_patternmethod intorelevant_filename_patternsto return an array of patterns.This enables two key improvements:
1. Finding tests in matching subdirectories:
When triggering "Go to relevant file" on
app/models/user.rb, the search now includes patterns that look inside auser/subdirectory, finding files like:test/models/user_test.rb(existing behavior)test/models/user/create_user_test.rb(new)test/models/user/test_update_user.rb(new)2. Navigating back from nested tests:
The reverse navigation now also works for nested files. For example, from
test/requests/go_to_relevant_file/go_to_relevant_file_a_test.rb, it will correctly findlib/requests/go_to_relevant_file.rb. This is done by checking if the parent directory's name is included in the test file's name.Automated Tests
New tests have been added to cover these scenarios.
Manual Tests
In a test project, create the following file structure:
Open
app/models/user.rb.Click on the "Go to relevant file" button.
Expected: A VS Code quick pick should appear with both
create_user_test.rbandupdate_user_test.rbas options.Now open
test/models/user/create_user_test.rb.Click on the "Go to relevant file" button.
Expected: The editor should navigate directly to
app/models/user.rb.