-
Notifications
You must be signed in to change notification settings - Fork 176
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 10 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
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 |
---|---|---|
|
@@ -240,5 +240,27 @@ def locate_node(position, node_types: []) | |
node_types: node_types, | ||
) | ||
end | ||
|
||
sig { returns(String) } | ||
def test_library | ||
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. 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? |
||
# TODO: return 'none' immediately if path doesn't contain 'test' or 'spec' ? | ||
class_entries = @global_state.index.entries_for(@uri.to_s, RubyIndexer::Entry::Class) | ||
return "none" unless class_entries | ||
|
||
# TODO: consider performance hit | ||
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 | ||
"none" | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -461,7 +461,7 @@ 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) | ||
code_lens = Requests::CodeLens.new(uri, document.test_library, dispatcher) if document.is_a?(RubyDocument) | ||
inlay_hint = Requests::InlayHints.new(document, T.must(@store.features_configuration.dig(:inlayHint)), dispatcher) | ||
|
||
# Re-index the file as it is modified. This mode of indexing updates entries only. Require path trees are only | ||
|
@@ -477,7 +477,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.
@st0012 @vinistock I'm wondering how we should update this since currently ruby-lsp-rails checks
@global_state.test_library == "rails"
. What if we maketest_library
be an optional keyword argument? That would prevent breaking the API for other addons.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.
Alternatively, we change it to pass
document
instead ofuri
(sinceuri
is available viadocument
).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.
This should be considered a breaking change anyway so I think changing args is expected?
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.
True. I've updated it to pass
document
insead oftest_library
, which should allow for more flexibility in future. I'm still considering ifuri
could be dropped.(also have to investigate some test failures).