-
Notifications
You must be signed in to change notification settings - Fork 77
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
be406f8
Discover tests via LSP if available
plemarquand 1888d4b
Update comments
plemarquand 6ac7c0b
Member accessed tags no longer have a leading .
plemarquand 5f1f42b
Properly check if experimental lsp caps exist
plemarquand f216f32
Append target to swift-testing test ids
plemarquand c3bf0eb
Refactor out common LSP capability check
plemarquand eded282
Rename transform to transformToTestClass
plemarquand d587d81
No need to filter workspace tests to the workspace
plemarquand 9b9b505
Cache caps checks
plemarquand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the VSCode Swift open source project | ||
// | ||
// Copyright (c) 2021-2024 the VSCode Swift project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of VSCode Swift project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import * as vscode from "vscode"; | ||
import { TestClass } from "./TestDiscovery"; | ||
import { parseTestsFromSwiftTestListOutput } from "./SPMTestDiscovery"; | ||
|
||
export function parseTestsFromDocumentSymbols( | ||
target: string, | ||
symbols: vscode.DocumentSymbol[], | ||
uri: vscode.Uri | ||
): TestClass[] { | ||
// Converts a document into the output of `swift test list`. | ||
// This _only_ looks for XCTests. | ||
const locationLookup = new Map<string, vscode.Location | undefined>(); | ||
const swiftTestListOutput = symbols | ||
.filter( | ||
symbol => | ||
symbol.kind === vscode.SymbolKind.Class || | ||
symbol.kind === vscode.SymbolKind.Namespace | ||
) | ||
.flatMap(symbol => { | ||
const functions = symbol.children | ||
.filter(func => func.kind === vscode.SymbolKind.Method) | ||
.filter(func => func.name.match(/^test.*\(\)/)) | ||
.map(func => { | ||
const openBrackets = func.name.indexOf("("); | ||
let funcName = func.name; | ||
if (openBrackets) { | ||
funcName = func.name.slice(0, openBrackets); | ||
} | ||
return { | ||
name: funcName, | ||
location: new vscode.Location(uri, func.range), | ||
}; | ||
}); | ||
|
||
const location = | ||
symbol.kind === vscode.SymbolKind.Class | ||
? new vscode.Location(uri, symbol.range) | ||
: undefined; | ||
|
||
locationLookup.set(`${target}.${symbol.name}`, location); | ||
|
||
return functions.map(func => { | ||
const testName = `${target}.${symbol.name}/${func.name}`; | ||
locationLookup.set(testName, func.location); | ||
return testName; | ||
}); | ||
}) | ||
.join("\n"); | ||
|
||
const tests = parseTestsFromSwiftTestListOutput(swiftTestListOutput); | ||
|
||
// The locations for each test case/suite were captured when processing the | ||
// symbols. Annotate the processed TestClasses with their locations. | ||
const annotatedTests = annotateTestsWithLocations(tests, locationLookup); | ||
return annotatedTests; | ||
} | ||
|
||
function annotateTestsWithLocations( | ||
tests: TestClass[], | ||
locations: Map<string, vscode.Location | undefined> | ||
): TestClass[] { | ||
return tests.map(test => ({ | ||
...test, | ||
location: locations.get(test.id), | ||
children: annotateTestsWithLocations(test.children, locations), | ||
})); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.