Skip to content

Use textDocument/tests LSP request to augment test list on active document save #762

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

Closed
adam-fowler opened this issue Apr 21, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@adam-fowler
Copy link
Contributor

When a swift file is saved, make textDocument/tests LSP request and use the response to augment the test list generated from workspace/tests.

Currently we are using a middleware to parse symbols from document symbols responses. This can be disabled for Swift 6 once the above is implemented. This is the code setting it up https://github.com/swift-server/vscode-swift/blob/dfba3243e6cb97faa45037d11478e2714d4d5e17/src/TestExplorer/TestExplorer.ts#L127-L133

@plemarquand
Copy link
Contributor

I can take a look at this.

@daveyc123 daveyc123 moved this from Backlog to Todo in Visual Code Swift Extension Apr 23, 2024
plemarquand added a commit to plemarquand/vscode-swift that referenced this issue Apr 24, 2024
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 added a commit to plemarquand/vscode-swift that referenced this issue Apr 29, 2024
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 added a commit that referenced this issue Apr 29, 2024
* Discover tests via LSP if available

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 #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.

* Update comments

* Member accessed tags no longer have a leading .

* Properly check if experimental lsp caps exist

* Append target to swift-testing test ids

* Refactor out common LSP capability check

* Rename transform to transformToTestClass

* No need to filter workspace tests to the workspace

* Cache caps checks
@plemarquand
Copy link
Contributor

Closed by #767

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

No branches or pull requests

2 participants