swiftlang / vscode-swift

Visual Studio Code Extension for Swift
https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang
Apache License 2.0
709 stars 47 forks source link

Discover tests via LSP if available #767

Closed plemarquand closed 2 months ago

plemarquand commented 2 months ago

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.

This patch addresses both #761 and #762.

plemarquand commented 2 months ago

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.

adam-fowler commented 2 months ago

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

adam-fowler commented 2 months ago

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