Skip to content

Commit 15189bb

Browse files
authored
Merge pull request #1149 from ahoppen/ahoppen/structured-tests
Return tests discovered by `workspace/tests` and `textDocument/tests` in a hierarchical format
2 parents 44b8a82 + 67a73f4 commit 15189bb

File tree

8 files changed

+319
-127
lines changed

8 files changed

+319
-127
lines changed

Sources/LanguageServerProtocol/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ add_library(LanguageServerProtocol STATIC
124124
SupportTypes/SKCompletionOptions.swift
125125
SupportTypes/StringOrMarkupContent.swift
126126
SupportTypes/SymbolKind.swift
127+
SupportTypes/TestItem.swift
127128
SupportTypes/TextDocumentContentChangeEvent.swift
128129
SupportTypes/TextDocumentEdit.swift
129130
SupportTypes/TextDocumentIdentifier.swift

Sources/LanguageServerProtocol/Requests/DocumentTestsRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/// **(LSP Extension)**
1616
public struct DocumentTestsRequest: TextDocumentRequest, Hashable {
1717
public static let method: String = "textDocument/tests"
18-
public typealias Response = [WorkspaceSymbolItem]?
18+
public typealias Response = [TestItem]
1919

2020
public var textDocument: TextDocumentIdentifier
2121

Sources/LanguageServerProtocol/Requests/WorkspaceTestsRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/// **(LSP Extension)**
1616
public struct WorkspaceTestsRequest: RequestType, Hashable {
1717
public static let method: String = "workspace/tests"
18-
public typealias Response = [WorkspaceSymbolItem]?
18+
public typealias Response = [TestItem]
1919

2020
public init() {}
2121
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
public struct TestTag: Codable, Equatable, Sendable {
14+
/// ID of the test tag. `TestTag` instances with the same ID are considered to be identical.
15+
public let id: String
16+
17+
public init(id: String) {
18+
self.id = id
19+
}
20+
}
21+
22+
/// A test item that can be shown an a client's test explorer or used to identify tests alongside a source file.
23+
///
24+
/// A `TestItem` can represent either a test suite or a test itself, since they both have similar capabilities.
25+
public struct TestItem: ResponseType, Equatable {
26+
/// Identifier for the `TestItem`.
27+
///
28+
/// This identifier uniquely identifies the test case or test suite. It can be used to run an individual test (suite).
29+
public let id: String
30+
31+
/// Display name describing the test.
32+
public let label: String
33+
34+
/// Optional description that appears next to the label.
35+
public let description: String?
36+
37+
/// A string that should be used when comparing this item with other items.
38+
///
39+
/// When `nil` the `label` is used.
40+
public let sortText: String?
41+
42+
/// The location of the test item in the source code.
43+
public let location: Location
44+
45+
/// The children of this test item.
46+
///
47+
/// For a test suite, this may contain the individual test cases or nested suites.
48+
public let children: [TestItem]
49+
50+
/// Tags associated with this test item.
51+
public let tags: [TestTag]
52+
53+
public init(
54+
id: String,
55+
label: String,
56+
description: String? = nil,
57+
sortText: String? = nil,
58+
location: Location,
59+
children: [TestItem],
60+
tags: [TestTag]
61+
) {
62+
self.id = id
63+
self.label = label
64+
self.description = description
65+
self.sortText = sortText
66+
self.location = location
67+
self.children = children
68+
self.tags = tags
69+
}
70+
}

Sources/SourceKitLSP/LanguageService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public protocol LanguageService: AnyObject {
198198
/// Perform a syntactic scan of the file at the given URI for test cases and test classes.
199199
///
200200
/// This is used as a fallback to show the test cases in a file if the index for a given file is not up-to-date.
201-
func syntacticDocumentTests(for uri: DocumentURI) async throws -> [WorkspaceSymbolItem]?
201+
func syntacticDocumentTests(for uri: DocumentURI) async throws -> [TestItem]
202202

203203
/// Crash the language server. Should be used for crash recovery testing only.
204204
func _crash() async

Sources/SourceKitLSP/SourceKitLSPServer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,8 +1317,8 @@ extension SourceKitLSPServer {
13171317
semanticTokensProvider: semanticTokensOptions,
13181318
inlayHintProvider: inlayHintOptions,
13191319
experimental: .dictionary([
1320-
"workspace/tests": .dictionary(["version": .int(1)]),
1321-
"textDocument/tests": .dictionary(["version": .int(1)]),
1320+
"workspace/tests": .dictionary(["version": .int(2)]),
1321+
"textDocument/tests": .dictionary(["version": .int(2)]),
13221322
])
13231323
)
13241324
}

0 commit comments

Comments
 (0)