Skip to content

Commit fcdf0d4

Browse files
committed
Added testDefinitionInSystemModuleInterface
Use SwiftPMPackage test module Added version of buildAndIndex that includes system symbols
1 parent 2a06084 commit fcdf0d4

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

Sources/SKTestSupport/INPUTS/SwiftPMPackage/Sources/lib/lib.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
public struct Lib {
2+
let a: /*Lib.a.string*/String
3+
24
public func /*Lib.foo:def*/foo() {}
35

4-
public init() {}
6+
public init() {
7+
self.a = "lib"
8+
}
59
}
610

711
func topLevelFunction() {

Sources/SKTestSupport/SKSwiftPMTestWorkspace.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ extension SKSwiftPMTestWorkspace {
125125
index.pollForUnitChangesAndWait()
126126
}
127127

128+
public func buildAndIndexWithSystemSymbols() throws {
129+
try buildWithSystemSymbols()
130+
index.pollForUnitChangesAndWait()
131+
}
132+
128133
func build() throws {
129134
try TSCBasic.Process.checkNonZeroExit(arguments: [
130135
toolchain.swift!.pathString,
@@ -135,6 +140,15 @@ extension SKSwiftPMTestWorkspace {
135140
"-Xcc", "-index-ignore-system-symbols",
136141
])
137142
}
143+
144+
func buildWithSystemSymbols() throws {
145+
try TSCBasic.Process.checkNonZeroExit(arguments: [
146+
toolchain.swift!.pathString,
147+
"build",
148+
"--package-path", sources.rootDirectory.path,
149+
"--scratch-path", buildDir.path,
150+
])
151+
}
138152
}
139153

140154
extension SKSwiftPMTestWorkspace {

Tests/SourceKitLSPTests/SwiftInterfaceTests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Foundation
1414
import LanguageServerProtocol
1515
import LSPTestSupport
1616
import LSPLogging
17+
import SKSupport
1718
import SKTestSupport
1819
import SourceKitLSP
1920
import XCTest
@@ -113,6 +114,27 @@ final class SwiftInterfaceTests: XCTestCase {
113114
"""))
114115
}
115116

117+
func testDefinitionInSystemModuleInterface() throws {
118+
guard let ws = try staticSourceKitSwiftPMWorkspace(name: "SwiftPMPackage") else { return }
119+
try ws.buildAndIndexWithSystemSymbols()
120+
let stringRef = ws.testLoc("Lib.a.string")
121+
try ws.openDocument(stringRef.url, language: .swift)
122+
let definition = try ws.sk.sendSync(DefinitionRequest(
123+
textDocument: stringRef.docIdentifier,
124+
position: stringRef.position))
125+
guard case .locations(let jump) = definition else {
126+
XCTFail("Response is not locations")
127+
return
128+
}
129+
let location = try XCTUnwrap(jump.first)
130+
XCTAssertTrue(location.uri.pseudoPath.hasSuffix("/Swift.String.swiftinterface"))
131+
// load contents of swiftinterface
132+
let contents = try XCTUnwrap(location.uri.fileURL.flatMap({ try String(contentsOf: $0, encoding: .utf8) }))
133+
let lineTable = LineTable(contents)
134+
let line = lineTable[location.range.lowerBound.line]
135+
XCTAssert(line.hasPrefix("@frozen public struct String"))
136+
}
137+
116138
func testSwiftInterfaceAcrossModules() throws {
117139
guard let ws = try staticSourceKitSwiftPMWorkspace(name: "SwiftPMPackage") else { return }
118140
try ws.buildAndIndex()

0 commit comments

Comments
 (0)