Skip to content

Conversation

@st0012
Copy link
Member

@st0012 st0012 commented Jun 20, 2023

Motivation

Since we want extensions to provide code lenses for libraries like RSpec, we should not generate any code lens ourselves when the test library is not supported/unknown. Otherwise it could create wrong code lenses and mess with with what our extensions generate.

Implementation

  1. Instead of falling back test library to minitest, we simply return unknown if it's not a known one.
  2. Before generating test code lenses, we check if the test library is supported. If not, we don't generate any code lenses.

Automated Tests

Added 2 test cases to make sure code lenses will not be generated when the library is rspec or unknown.

Manual Tests

…d/unknown

Since we want extensions to provide code lenses for libraries like RSpec,
we should not generate any code lens ourselves when the test library is
not supported/unknown. Otherwise it could create wrong code lenses and
mess with with what our extensions generate.
@st0012 st0012 added the bugfix This PR will fix an existing bug label Jun 20, 2023
@st0012 st0012 added this to the 2023-Q2 milestone Jun 20, 2023
@st0012 st0012 requested a review from a team as a code owner June 20, 2023 13:50
@st0012 st0012 self-assigned this Jun 20, 2023
sig { params(node: SyntaxTree::Node, name: String, command: String, kind: Symbol).void }
def add_test_code_lens(node, name:, command:, kind:)
# don't add code lenses if the test library is not supported or unknown
return unless SUPPORTED_TEST_LIBRARIES.include?(@test_library)
Copy link
Member Author

Choose a reason for hiding this comment

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

Just an idea: if we split test code lens listeners into 2, like TestCodeLens and BundlerCodeLens, we can skip registering events in TestCodeLens if the test library is not supported. I think this will save us some unnecessary computation.
If it's preferred, now could be a good time for this before we ship ruby-lsp-rails' code lens support.

WDYT? @vinistock @andyw8

Copy link
Contributor

@andyw8 andyw8 Jun 20, 2023

Choose a reason for hiding this comment

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

I think it's not critical for now though, we can bump the ruby-lsp-rails dependency later if we refactor things.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think splitting is worth the complexity yet.

@github-actions
Copy link
Contributor

Benchmark results in seconds (slowest at top)

          textDocument/completion average: 0.261409 std_dev: 0.004837
          textDocument/diagnostic average: 0.038498 std_dev: 0.009038
      textDocument/selectionRange average: 0.003168 std_dev: 0.000397
   textDocument/documentHighlight average: 0.001674 std_dev: 8.9e-05
        textDocument/documentLink average: 0.001655 std_dev: 8.7e-05
            textDocument/codeLens average: 0.001649 std_dev: 0.000119
 textDocument/semanticTokens/full average: 0.00163 std_dev: 0.000255
      textDocument/documentSymbol average: 0.001619 std_dev: 9.1e-05
        textDocument/foldingRange average: 0.001449 std_dev: 9.7e-05
textDocument/semanticTokens/range average: 0.000835 std_dev: 5.6e-05
           textDocument/inlayHint average: 0.00059 std_dev: 5.1e-05
               codeAction/resolve average: 0.00056 std_dev: 5.9e-05
               textDocument/hover average: 0.000525 std_dev: 5.0e-05
    textDocument/onTypeFormatting average: 9.9e-05 std_dev: 4.8e-05
          textDocument/formatting average: 5.8e-05 std_dev: 0.000279
          textDocument/codeAction average: 3.3e-05 std_dev: 2.7e-05


================================================================================
Comparison with main branch:

 textDocument/semanticTokens/full unchanged
textDocument/semanticTokens/range unchanged
      textDocument/documentSymbol unchanged
        textDocument/foldingRange unchanged
          textDocument/formatting unchanged
          textDocument/diagnostic unchanged
        textDocument/documentLink unchanged
           textDocument/inlayHint unchanged
      textDocument/selectionRange unchanged
   textDocument/documentHighlight unchanged
               textDocument/hover unchanged
          textDocument/codeAction unchanged
    textDocument/onTypeFormatting unchanged
               codeAction/resolve unchanged
          textDocument/completion unchanged
            textDocument/codeLens unchanged

@st0012 st0012 merged commit 03220fc into main Jun 20, 2023
@st0012 st0012 deleted the create-code-lens-more-conservatively branch June 20, 2023 15:09
sig { params(node: SyntaxTree::Node, name: String, command: String, kind: Symbol).void }
def add_test_code_lens(node, name:, command:, kind:)
# don't add code lenses if the test library is not supported or unknown
return unless SUPPORTED_TEST_LIBRARIES.include?(@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.

I don't think splitting is worth the complexity yet.

Comment on lines +77 to +79
response = listener.response

assert_equal(0, response.size)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
response = listener.response
assert_equal(0, response.size)
assert_empty(listener.response)

Comment on lines +59 to +61
response = listener.response

assert_equal(0, response.size)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
response = listener.response
assert_equal(0, response.size)
assert_empty(listener.response)

assert_equal(0, response.size)
end

def test_no_code_lens_for_rspec
Copy link
Member

Choose a reason for hiding this comment

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

Does this test verify any behaviour that the unknown one doesn't? Do we need both?

@shopify-shipit shopify-shipit bot temporarily deployed to production June 23, 2023 15:44 Inactive
vinistock pushed a commit that referenced this pull request Feb 28, 2024
…de-20.5.7

Bump @types/node from 20.5.1 to 20.5.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix This PR will fix an existing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants