Skip to content

Commit f8ac8a7

Browse files
authored
Merge pull request #2284 from a7medev/test/skip-unless-signature-help
Skip signature help tests if not supported in sourcekitd
2 parents a5854f4 + 8c1ea67 commit f8ac8a7

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

Sources/SKTestSupport/SkipUnless.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,46 @@ package actor SkipUnless {
432432
#endif
433433
}
434434

435+
package static func sourcekitdSupportsSignatureHelp(
436+
file: StaticString = #filePath,
437+
line: UInt = #line
438+
) async throws {
439+
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 2), file: file, line: line) {
440+
let sourcekitd = try await getSourceKitD()
441+
442+
return try await withTestScratchDir { scratchDirectory in
443+
let (positions, source) = extractMarkers(
444+
"""
445+
func foo() {
446+
foo(1️⃣)
447+
}
448+
"""
449+
)
450+
451+
let testURL = scratchDirectory.appending(component: "test.swift")
452+
try source.write(to: testURL, atomically: false, encoding: .utf8)
453+
454+
let offset = positions["1️⃣"]
455+
let sourceFile = try testURL.filePath
456+
457+
let skreq = sourcekitd.dictionary([
458+
sourcekitd.keys.offset: offset,
459+
sourcekitd.keys.sourceFile: sourceFile,
460+
sourcekitd.keys.compilerArgs: [sourceFile],
461+
])
462+
463+
do {
464+
let response = try await sourcekitd.send(\.signatureHelp, skreq)
465+
466+
let signatures: SKDResponseArray? = response[sourcekitd.keys.signatures]
467+
return signatures != nil
468+
} catch {
469+
return false
470+
}
471+
}
472+
}
473+
}
474+
435475
private static func getSourceKitD() async throws -> SourceKitD {
436476
guard let sourcekitdPath = await ToolchainRegistry.forTesting.default?.sourcekitd else {
437477
throw GenericError("Could not find SourceKitD")

Tests/SourceKitLSPTests/SwiftSignatureHelpTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import XCTest
1818

1919
final class SwiftSignatureHelpTests: XCTestCase {
2020
func testSignatureHelpFunction() async throws {
21+
try await SkipUnless.sourcekitdSupportsSignatureHelp()
22+
2123
let testClient = try await TestSourceKitLSPClient()
2224
let uri = DocumentURI(for: .swift)
2325

@@ -75,6 +77,8 @@ final class SwiftSignatureHelpTests: XCTestCase {
7577
}
7678

7779
func testSignatureHelpSubscript() async throws {
80+
try await SkipUnless.sourcekitdSupportsSignatureHelp()
81+
7882
let testClient = try await TestSourceKitLSPClient()
7983
let uri = DocumentURI(for: .swift)
8084

@@ -134,6 +138,8 @@ final class SwiftSignatureHelpTests: XCTestCase {
134138
}
135139

136140
func testSignatureHelpInitializer() async throws {
141+
try await SkipUnless.sourcekitdSupportsSignatureHelp()
142+
137143
let testClient = try await TestSourceKitLSPClient()
138144
let uri = DocumentURI(for: .swift)
139145

@@ -189,6 +195,8 @@ final class SwiftSignatureHelpTests: XCTestCase {
189195
}
190196

191197
func testSignatureHelpEnumCase() async throws {
198+
try await SkipUnless.sourcekitdSupportsSignatureHelp()
199+
192200
let testClient = try await TestSourceKitLSPClient()
193201
let uri = DocumentURI(for: .swift)
194202

@@ -246,6 +254,8 @@ final class SwiftSignatureHelpTests: XCTestCase {
246254
}
247255

248256
func testSignatureHelpNoParameters() async throws {
257+
try await SkipUnless.sourcekitdSupportsSignatureHelp()
258+
249259
let testClient = try await TestSourceKitLSPClient()
250260
let uri = DocumentURI(for: .swift)
251261

@@ -284,6 +294,8 @@ final class SwiftSignatureHelpTests: XCTestCase {
284294
}
285295

286296
func testSignatureHelpNoSignatures() async throws {
297+
try await SkipUnless.sourcekitdSupportsSignatureHelp()
298+
287299
let testClient = try await TestSourceKitLSPClient()
288300
let uri = DocumentURI(for: .swift)
289301

@@ -307,6 +319,8 @@ final class SwiftSignatureHelpTests: XCTestCase {
307319
}
308320

309321
func testSignatureHelpNoActiveParameter() async throws {
322+
try await SkipUnless.sourcekitdSupportsSignatureHelp()
323+
310324
let testClient = try await TestSourceKitLSPClient()
311325
let uri = DocumentURI(for: .swift)
312326

@@ -348,6 +362,8 @@ final class SwiftSignatureHelpTests: XCTestCase {
348362
}
349363

350364
func testSignatureHelpAdjustToStartOfArgument() async throws {
365+
try await SkipUnless.sourcekitdSupportsSignatureHelp()
366+
351367
let testClient = try await TestSourceKitLSPClient()
352368
let uri = DocumentURI(for: .swift)
353369

@@ -416,6 +432,8 @@ final class SwiftSignatureHelpTests: XCTestCase {
416432
}
417433

418434
func testSignatureHelpMultipleOverloads() async throws {
435+
try await SkipUnless.sourcekitdSupportsSignatureHelp()
436+
419437
let testClient = try await TestSourceKitLSPClient()
420438
let uri = DocumentURI(for: .swift)
421439

@@ -477,6 +495,8 @@ final class SwiftSignatureHelpTests: XCTestCase {
477495
}
478496

479497
func testSignatureHelpPreservesActiveSignature() async throws {
498+
try await SkipUnless.sourcekitdSupportsSignatureHelp()
499+
480500
let testClient = try await TestSourceKitLSPClient()
481501
let uri = DocumentURI(for: .swift)
482502

@@ -532,6 +552,8 @@ final class SwiftSignatureHelpTests: XCTestCase {
532552
}
533553

534554
func testSignatureHelpNonASCII() async throws {
555+
try await SkipUnless.sourcekitdSupportsSignatureHelp()
556+
535557
let testClient = try await TestSourceKitLSPClient()
536558
let uri = DocumentURI(for: .swift)
537559

@@ -574,6 +596,8 @@ final class SwiftSignatureHelpTests: XCTestCase {
574596
}
575597

576598
func testSignatureHelpSwiftPMProject() async throws {
599+
try await SkipUnless.sourcekitdSupportsSignatureHelp()
600+
577601
let project = try await SwiftPMTestProject(
578602
files: [
579603
"utils.swift": #"""

0 commit comments

Comments
 (0)