Skip to content

Commit 2ce3fd8

Browse files
committed
removed OpenGeneratedInterfaceRequest
replaced its usage by passing its members as parameters directly removed from Messages.builtinRequests removed from SwiftInterfaceTests
1 parent a4b6a74 commit 2ce3fd8

File tree

7 files changed

+43
-106
lines changed

7 files changed

+43
-106
lines changed

Sources/LanguageServerProtocol/Messages.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public let builtinRequests: [_RequestType.Type] = [
5858
InlineValueRequest.self,
5959
LinkedEditingRangeRequest.self,
6060
MonikersRequest.self,
61-
OpenGeneratedInterfaceRequest.self,
6261
PollIndexRequest.self,
6362
PrepareRenameRequest.self,
6463
ReferencesRequest.self,

Sources/LanguageServerProtocol/Requests/OpenInterfaceRequest.swift

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
/// Request a generated interface of a module to display in the IDE.
14-
/// **(LSP Extension)**
15-
public struct OpenGeneratedInterfaceRequest: TextDocumentRequest, Hashable {
16-
public static let method: String = "textDocument/openInterface"
17-
public typealias Response = GeneratedInterfaceDetails?
18-
19-
/// The document whose compiler arguments should be used to generate the interface.
20-
public var textDocument: TextDocumentIdentifier
21-
22-
/// The module to generate an index for.
23-
public var moduleName: String
24-
25-
/// The module group name.
26-
public var groupName: String?
27-
28-
/// The symbol USR to search for in the generated module interface.
29-
public var symbolUSR: String?
30-
31-
public init(textDocument: TextDocumentIdentifier, name: String, groupName: String?, symbolUSR: String?) {
32-
self.textDocument = textDocument
33-
self.symbolUSR = symbolUSR
34-
self.moduleName = name
35-
self.groupName = groupName
36-
}
37-
38-
/// Name of interface module name with group names appended
39-
public var name: String {
40-
if let groupName {
41-
return "\(self.moduleName).\(groupName.replacing("/", with: "."))"
42-
}
43-
return self.moduleName
44-
}
45-
}
46-
4713
/// The textual output of a module interface.
4814
public struct GeneratedInterfaceDetails: ResponseType, Hashable {
4915

Sources/SourceKitLSP/Clang/ClangLanguageService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,8 @@ extension ClangLanguageService {
621621
}
622622
return try await forwardRequestToClangd(req)
623623
}
624-
625-
func openGeneratedInterface(_ request: OpenGeneratedInterfaceRequest) async throws -> GeneratedInterfaceDetails? {
624+
625+
func openGeneratedInterface(textDocument: TextDocumentIdentifier, moduleName: String, groupName: String?, symbolUSR symbol: String?) async throws -> GeneratedInterfaceDetails? {
626626
throw ResponseError.unknown("unsupported method")
627627
}
628628

Sources/SourceKitLSP/LanguageService.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ public protocol LanguageService: AnyObject, Sendable {
146146
func completion(_ req: CompletionRequest) async throws -> CompletionList
147147
func hover(_ req: HoverRequest) async throws -> HoverResponse?
148148
func symbolInfo(_ request: SymbolInfoRequest) async throws -> [SymbolDetails]
149-
func openGeneratedInterface(_ request: OpenGeneratedInterfaceRequest) async throws -> GeneratedInterfaceDetails?
149+
func openGeneratedInterface(
150+
textDocument: TextDocumentIdentifier,
151+
moduleName: String,
152+
groupName: String?,
153+
symbolUSR symbol: String?
154+
) async throws -> GeneratedInterfaceDetails?
150155

151156
/// - Note: Only called as a fallback if the definition could not be found in the index.
152157
func definition(_ request: DefinitionRequest) async throws -> LocationsOrLocationLinksResponse?

Sources/SourceKitLSP/SourceKitLSPServer.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,6 @@ extension SourceKitLSPServer: MessageHandler {
738738
initialized = true
739739
case let request as RequestAndReply<InlayHintRequest>:
740740
await self.handleRequest(for: request, requestHandler: self.inlayHint)
741-
case let request as RequestAndReply<OpenGeneratedInterfaceRequest>:
742-
await self.handleRequest(for: request, requestHandler: self.openGeneratedInterface)
743741
case let request as RequestAndReply<PollIndexRequest>:
744742
await request.reply { try await pollIndex(request.params) }
745743
case let request as RequestAndReply<PrepareRenameRequest>:
@@ -1477,11 +1475,19 @@ extension SourceKitLSPServer {
14771475
}
14781476

14791477
func openGeneratedInterface(
1480-
_ req: OpenGeneratedInterfaceRequest,
1478+
textDocument: TextDocumentIdentifier,
1479+
moduleName: String,
1480+
groupName: String?,
1481+
symbolUSR symbol: String?,
14811482
workspace: Workspace,
14821483
languageService: LanguageService
14831484
) async throws -> GeneratedInterfaceDetails? {
1484-
return try await languageService.openGeneratedInterface(req)
1485+
return try await languageService.openGeneratedInterface(
1486+
textDocument: textDocument,
1487+
moduleName: moduleName,
1488+
groupName: groupName,
1489+
symbolUSR: symbol
1490+
)
14851491
}
14861492

14871493
/// Find all symbols in the workspace that include a string in their name.
@@ -1885,13 +1891,12 @@ extension SourceKitLSPServer {
18851891
originatorUri: DocumentURI,
18861892
languageService: LanguageService
18871893
) async throws -> Location {
1888-
let openInterface = OpenGeneratedInterfaceRequest(
1894+
guard let interfaceDetails = try await languageService.openGeneratedInterface(
18891895
textDocument: TextDocumentIdentifier(originatorUri),
1890-
name: moduleName,
1896+
moduleName: moduleName,
18911897
groupName: groupName,
18921898
symbolUSR: symbolUSR
1893-
)
1894-
guard let interfaceDetails = try await languageService.openGeneratedInterface(openInterface) else {
1899+
) else {
18951900
throw ResponseError.unknown("Could not generate Swift Interface for \(moduleName)")
18961901
}
18971902
let position = interfaceDetails.position ?? Position(line: 0, utf16index: 0)

Sources/SourceKitLSP/Swift/OpenInterface.swift

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,33 @@ struct GeneratedInterfaceInfo {
2222

2323
extension SwiftLanguageService {
2424
public func openGeneratedInterface(
25-
_ request: OpenGeneratedInterfaceRequest
25+
textDocument: TextDocumentIdentifier,
26+
moduleName: String,
27+
groupName: String?,
28+
symbolUSR symbol: String?
2629
) async throws -> GeneratedInterfaceDetails? {
27-
let name = request.name
28-
let symbol = request.symbolUSR
30+
// Name of interface module name with group names appended
31+
let name = if let groupName {
32+
"\(moduleName).\(groupName.replacing("/", with: "."))"
33+
} else {
34+
moduleName
35+
}
2936
let interfaceFilePath = self.generatedInterfacesPath.appendingPathComponent("\(name).swiftinterface")
3037
let interfaceDocURI = DocumentURI(interfaceFilePath)
3138
// has interface already been generated
3239
if let snapshot = try? self.documentManager.latestSnapshot(interfaceDocURI) {
3340
return await self.generatedInterfaceDetails(
34-
request: request,
3541
uri: interfaceDocURI,
3642
snapshot: snapshot,
3743
symbol: symbol
3844
)
3945
} else {
40-
let interfaceInfo = try await self.generatedInterfaceInfo(request: request, interfaceURI: interfaceDocURI)
46+
let interfaceInfo = try await self.generatedInterfaceInfo(
47+
textDocument: textDocument,
48+
moduleName: moduleName,
49+
groupName: groupName,
50+
interfaceURI: interfaceDocURI
51+
)
4152
try interfaceInfo.contents.write(to: interfaceFilePath, atomically: true, encoding: String.Encoding.utf8)
4253
let snapshot = DocumentSnapshot(
4354
uri: interfaceDocURI,
@@ -46,7 +57,6 @@ extension SwiftLanguageService {
4657
lineTable: LineTable(interfaceInfo.contents)
4758
)
4859
let result = await self.generatedInterfaceDetails(
49-
request: request,
5060
uri: interfaceDocURI,
5161
snapshot: snapshot,
5262
symbol: symbol
@@ -67,25 +77,26 @@ extension SwiftLanguageService {
6777
/// - Important: This opens a document with name `interfaceURI.pseudoPath` in sourcekitd. The caller is responsible
6878
/// for ensuring that the document will eventually get closed in sourcekitd again.
6979
private func generatedInterfaceInfo(
70-
request: OpenGeneratedInterfaceRequest,
80+
textDocument: TextDocumentIdentifier,
81+
moduleName: String,
82+
groupName: String?,
7183
interfaceURI: DocumentURI
7284
) async throws -> GeneratedInterfaceInfo {
7385
let keys = self.keys
7486
let skreq = sourcekitd.dictionary([
7587
keys.request: requests.editorOpenInterface,
76-
keys.moduleName: request.moduleName,
77-
keys.groupName: request.groupName,
88+
keys.moduleName: moduleName,
89+
keys.groupName: groupName,
7890
keys.name: interfaceURI.pseudoPath,
7991
keys.synthesizedExtension: 1,
80-
keys.compilerArgs: await self.buildSettings(for: request.textDocument.uri)?.compilerArgs as [SKDRequestValue]?,
92+
keys.compilerArgs: await self.buildSettings(for: textDocument.uri)?.compilerArgs as [SKDRequestValue]?,
8193
])
8294

8395
let dict = try await self.sourcekitd.send(skreq, fileContents: nil)
8496
return GeneratedInterfaceInfo(contents: dict[keys.sourceText] ?? "")
8597
}
8698

8799
private func generatedInterfaceDetails(
88-
request: OpenGeneratedInterfaceRequest,
89100
uri: DocumentURI,
90101
snapshot: DocumentSnapshot,
91102
symbol: String?

Tests/SourceKitLSPTests/SwiftInterfaceTests.swift

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -49,55 +49,6 @@ final class SwiftInterfaceTests: XCTestCase {
4949
)
5050
}
5151

52-
func testOpenInterface() async throws {
53-
let project = try await SwiftPMTestProject(
54-
files: [
55-
"MyLibrary/MyLibrary.swift": """
56-
public struct Lib {
57-
public func foo() {}
58-
public init() {}
59-
}
60-
""",
61-
"Exec/main.swift": "import MyLibrary",
62-
],
63-
manifest: """
64-
let package = Package(
65-
name: "MyLibrary",
66-
targets: [
67-
.target(name: "MyLibrary"),
68-
.executableTarget(name: "Exec", dependencies: ["MyLibrary"])
69-
]
70-
)
71-
""",
72-
enableBackgroundIndexing: true
73-
)
74-
75-
let (mainUri, _) = try project.openDocument("main.swift")
76-
let openInterface = OpenGeneratedInterfaceRequest(
77-
textDocument: TextDocumentIdentifier(mainUri),
78-
name: "MyLibrary",
79-
groupName: nil,
80-
symbolUSR: nil
81-
)
82-
let interfaceDetails = try unwrap(await project.testClient.send(openInterface))
83-
XCTAssert(interfaceDetails.uri.pseudoPath.hasSuffix("/MyLibrary.swiftinterface"))
84-
let fileContents = try XCTUnwrap(
85-
interfaceDetails.uri.fileURL.flatMap({ try String(contentsOf: $0, encoding: .utf8) })
86-
)
87-
XCTAssertTrue(
88-
fileContents.contains(
89-
"""
90-
public struct Lib {
91-
92-
public func foo()
93-
94-
public init()
95-
}
96-
"""
97-
)
98-
)
99-
}
100-
10152
func testDefinitionInSystemModuleInterface() async throws {
10253
let project = try await IndexedSingleSwiftFileTestProject(
10354
"""

0 commit comments

Comments
 (0)