-
Notifications
You must be signed in to change notification settings - Fork 185
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
WIP: Use index to detect test library #3031
base: main
Are you sure you want to change the base?
Changes from all commits
37c2363
658ec55
c51615c
47bb0e1
13382b9
28476bb
616ac36
b5d286e
d6aabe4
1279d16
9ff365b
6892885
99f96c1
42b0ab0
28b3258
7c77de2
d9ba140
0bcb134
90a26b9
62f5e44
26c300c
4b9f5c1
b694ae9
4d87b79
4846245
e67f369
eaa7d71
9c25240
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,3 +87,6 @@ Layout/ClassStructure: | |
- include | ||
- prepend | ||
- extend | ||
|
||
Minitest/LiteralAsActualArgument: | ||
Enabled: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,6 +257,41 @@ def locate_node(position, node_types: []) | |
) | ||
end | ||
|
||
sig { returns(String) } | ||
def test_library | ||
return "none" unless test_file? | ||
|
||
class_entries = @global_state.index.entries_for(@uri.to_s, RubyIndexer::Entry::Class) | ||
unless class_entries | ||
return "none" | ||
end | ||
|
||
# TODO: consider performance hit | ||
# A better approach might be check the classes entries one at a time. | ||
ancestors = class_entries | ||
.map { @global_state.index.linearized_ancestors_of(_1.name) }.flatten | ||
|
||
# ActiveSupport::TestCase is a subclass of Minitest::Test so we must check for it first | ||
if ancestors.include?("ActiveSupport::TestCase") | ||
"rails" | ||
elsif ancestors.include?("Minitest::Test") | ||
"minitest" | ||
elsif ancestors.include?("Test::Unit::TestCase") | ||
"test-unit" | ||
else | ||
"unknown" | ||
Comment on lines
+275
to
+282
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should become a bit more specific now that we're checking for ancestors. For example, as Alex mentioned here, the test framework isn't really "rails" and is not tied to We can check for Same thing for Minitest and Test Unit. We can now do a better job at detecting the spec style syntax. |
||
end | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def test_file? | ||
# if the file is not saved, then we don't know its path, so can't know it's a test | ||
return false unless @uri.path # file may not be saved | ||
|
||
path = T.must(@uri.path) | ||
path.include?("/test/") || path.include?("/spec/") | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def should_index? | ||
# This method controls when we should index documents. If there's no recent edit and the document has just been | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -470,7 +470,8 @@ def run_combined_requests(message) | |
folding_range = Requests::FoldingRanges.new(parse_result.comments, dispatcher) | ||
document_symbol = Requests::DocumentSymbol.new(uri, dispatcher) | ||
document_link = Requests::DocumentLink.new(uri, parse_result.comments, dispatcher) | ||
code_lens = Requests::CodeLens.new(@global_state, uri, dispatcher) | ||
# TODO: seperate PR for global state | ||
code_lens = Requests::CodeLens.new(global_state, uri, document, dispatcher) if document.is_a?(RubyDocument) | ||
inlay_hint = Requests::InlayHints.new(document, T.must(@store.features_configuration.dig(:inlayHint)), dispatcher) | ||
|
||
if document.is_a?(RubyDocument) && document.should_index? | ||
|
@@ -494,7 +495,7 @@ def run_combined_requests(message) | |
document.cache_set("textDocument/foldingRange", folding_range.perform) | ||
document.cache_set("textDocument/documentSymbol", document_symbol.perform) | ||
document.cache_set("textDocument/documentLink", document_link.perform) | ||
document.cache_set("textDocument/codeLens", code_lens.perform) | ||
document.cache_set("textDocument/codeLens", code_lens.perform) if code_lens | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
document.cache_set("textDocument/inlayHint", inlay_hint.perform) | ||
|
||
send_message(Result.new(id: message[:id], response: document.cache_get(message[:method]))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of the advantage of looking at the ancestors is that we become more accurate even in very uncommon setups, like mixing test frameworks - which is something that came up a few times.
Considering that test files can have multiple test classes and they can inherit from different parents, is this approach flexible enough to account for that?
What was the idea behind putting it in document versus doing it in the code lens implementation?