Skip to content

Discover tests via LSP if available #767

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

Merged
merged 9 commits into from
Apr 29, 2024

Conversation

plemarquand
Copy link
Contributor

If the LSP is available and supports the two requests for listing tests then use those to discover tests in the workspace/document. If these requests are unsupported or if they fail, fall back to the existing methods.

This patch uses the existing code to leverage the LSP's workspace/tests method and adds the textDocument/tests for listing tests within documents as they change.

These requests produce a collection of TestClass structures, which are hierarchical. These are passed to one of the methods in TestDiscovery.ts which diffs against the existing tree and adds/removes tests. This is similar to how it already worked, but now supports arbitrary levels of nesting in the TestClass structure.

This patch also adds preliminary support for listing swift-testing tests through the LSP methods, as well as through swift test --list-tests. It does not support finding swift-testing tests through the document symbols.

Another small improvement is if listing tests fails via swift test --list-tests we'll attempt a swift build --build-tests before trying again. Today, if the user was on the 5.10 toolchain and no build had yet been performed they would get a somewhat cryptic error in the test explorer.

Swift-testing tests are filtered out of the list of available tests until code is added to run them. This will be added with #757.

  • Adds tests for parsing the results of swift test --list-tests
  • Adds tests for parsing tests via document symbols

This patch addresses both #761 and #762.

@plemarquand
Copy link
Contributor Author

Note: This will only work with the latest sourcekit-lsp. To test you can clone the sourcekit-lsp repo, swift build and then set the swift.sourcekit-lsp.serverPath VSCode setting to point to your built sourcekit-lsp.

@plemarquand plemarquand requested a review from award999 April 26, 2024 12:48
Copy link
Contributor

@award999 award999 left a comment

Choose a reason for hiding this comment

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

looks good to me, but probably should get another set of eyes

Copy link
Contributor

@adam-fowler adam-fowler left a comment

Choose a reason for hiding this comment

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

This looks great. Left a few comments about minor issues

If the LSP is available and supports the two requests for listing tests
then use those to discover tests in the workspace/document. If these
requests are unsupported or if they fail, fall back to the existing
methods.

This patch uses the existing code to leverage the LSP's workspace/tests
method and adds the textDocument/tests for listing tests within
documents as they change.

These requests produce a collection of TestClass structures, which are
hierarchical. These are passed to one of the methods in TestDiscovery.ts
which diffs against the existing tree and adds/removes tests. This is
similar to how it already worked, but now supports arbitrary levels of
nesting in the TestClass structure.

This patch also adds preliminary support for listing swift-testing tests
through the LSP methods, as well as through `swift test --list-tests`. It
does not support finding swift-testing tests through the document
symbols.

Another small improvement is if listing tests fails via `swift test
--list-tests` we'll attempt a `swift build --build-tests` before trying
again. If the user was on the 5.10 toolchain and no build had yet been
performed they would get an error.

Swift-testing tests are filtered out of the list of available tests
until code is added to run them. This will be added with swiftlang#757.

- Adds tests for parsing the results of `swift test --list-tests`
- Adds tests for parsing tests via document symbols

This patch addresses both swiftlang#761 and swiftlang#762.
@plemarquand plemarquand merged commit 0f21573 into swiftlang:main Apr 29, 2024
8 checks passed
@plemarquand plemarquand deleted the lsp-test-discovery branch April 29, 2024 15:42
@adam-fowler
Copy link
Contributor

Before merging this I thought I'd test swift 5.10 and it looks like the document symbols loading isn't working

@adam-fowler
Copy link
Contributor

Ah I see what you have done. By converting to the swift test list output, you lose the location information that comes with the document symbols. This will need to be fixed before this PR is merged

plemarquand added a commit that referenced this pull request Apr 29, 2024
plemarquand added a commit to plemarquand/vscode-swift that referenced this pull request Apr 29, 2024
If the LSP is unavailable `swift test list` will be used to enumerate
the tests. This method cannot attach a location to the TestClasses.

The code pre swiftlang#767 took this in to account, but swiftlang#767 introduced a
regression that would overwrite an existing item enumerated by document
symbols which had a location with one that didn't.
plemarquand added a commit that referenced this pull request Apr 30, 2024
If the LSP is unavailable `swift test list` will be used to enumerate
the tests. This method cannot attach a location to the TestClasses.

The code pre #767 took this in to account, but #767 introduced a
regression that would overwrite an existing item enumerated by document
symbols which had a location with one that didn't.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants