Skip to content
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

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

andyw8
Copy link
Contributor

@andyw8 andyw8 commented Jan 9, 2025

Closes #1334

Co-authored with @st0012

TODO:

  • consider ruby-lsp-rspec
  • consider ruby-lsp-rails
  • do we still need unknown vs none?

@response_builder = T.let(
ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens].new,
ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens],
)
super()
Listeners::CodeLens.new(@response_builder, global_state, uri, dispatcher)
Listeners::CodeLens.new(@response_builder, test_library, uri, dispatcher)

Addon.addons.each do |addon|
addon.create_code_lens_listener(@response_builder, uri, dispatcher)
Copy link
Contributor Author

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 make test_library be an optional keyword argument? That would prevent breaking the API for other addons.

Copy link
Contributor Author

@andyw8 andyw8 Jan 10, 2025

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 of uri (since uri is available via document).

Copy link
Member

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?

Copy link
Contributor Author

@andyw8 andyw8 Jan 10, 2025

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 of test_library, which should allow for more flexibility in future. I'm still considering if uri could be dropped.

(also have to investigate some test failures).

@@ -5,21 +5,19 @@
require_relative "support/expectations_test_runner"

class CodeLensExpectationsTest < ExpectationsTestRunner
expectations_tests RubyLsp::Requests::CodeLens, "code_lens"
# expectations_tests RubyLsp::Requests::CodeLens, "code_lens"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(will re-enable)

@andyw8 andyw8 added the enhancement New feature or request label Jan 10, 2025
@@ -491,7 +491,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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if is temporary

@@ -257,6 +257,37 @@ def locate_node(position, node_types: [])
)
end

sig { returns(String) }
def test_library
Copy link
Member

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?

Comment on lines +274 to +281
if ancestors.include?("ActiveSupport::TestCase")
"rails"
elsif ancestors.include?("Minitest::Test")
"minitest"
elsif ancestors.include?("Test::Unit::TestCase")
"test-unit"
else
"unknown"
Copy link
Member

Choose a reason for hiding this comment

The 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 ActiveSupport::TestCase.

We can check for ActiveSupport::Testing::Declarative and cover a broader range of cases.

Same thing for Minitest and Test Unit. We can now do a better job at detecting the spec style syntax.

@andyw8
Copy link
Contributor Author

andyw8 commented Jan 16, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use ancestors to determine test framework in code lens
3 participants