Skip to content

Commit 58e562a

Browse files
committed
further cleanup of OpenGeneratedInterfaceRequest
removed from `LSP Extensions.md` deleted OpenInterfaceRequest.swift and moved GeneratedInterfaceDetails to LanguageService.swift refactored usages of TextDocumentIdentifier to DocumentURI reformatted all code changes
1 parent 2ce3fd8 commit 58e562a

File tree

6 files changed

+41
-83
lines changed

6 files changed

+41
-83
lines changed

Documentation/LSP Extensions.md

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -169,42 +169,6 @@ interface SKCompletionOptions {
169169
}
170170
```
171171
172-
## `textDocument/interface`
173-
174-
New request that request a textual interface of a module to display in the IDE. Used internally within SourceKit-LSP
175-
176-
- params: `OpenInterfaceParams`
177-
- result: `InterfaceDetails?`
178-
179-
```ts
180-
export interface OpenInterfaceRequest: TextDocumentRequest, Hashable {
181-
/**
182-
* The document whose compiler arguments should be used to generate the interface.
183-
*/
184-
textDocument: TextDocumentIdentifier
185-
186-
/**
187-
* The module to generate an index for.
188-
*/
189-
moduleName: string
190-
191-
/**
192-
* The module group name.
193-
*/
194-
groupName?: string
195-
196-
/**
197-
* The symbol USR to search for in the generated module interface.
198-
*/
199-
symbolUSR?: string
200-
}
201-
202-
interface InterfaceDetails {
203-
uri: DocumentURI
204-
position?: Position
205-
}
206-
```
207-
208172
## `textDocument/symbolInfo`
209173
210174
New request for semantic information about the symbol at a given location.

Sources/LanguageServerProtocol/Requests/OpenInterfaceRequest.swift

Lines changed: 0 additions & 23 deletions
This file was deleted.

Sources/SourceKitLSP/Clang/ClangLanguageService.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,10 @@ extension ClangLanguageService {
621621
}
622622
return try await forwardRequestToClangd(req)
623623
}
624-
625-
func openGeneratedInterface(textDocument: TextDocumentIdentifier, moduleName: String, groupName: String?, symbolUSR symbol: String?) async throws -> GeneratedInterfaceDetails? {
624+
625+
func openGeneratedInterface(document: DocumentURI, moduleName: String, groupName: String?, symbolUSR symbol: String?)
626+
async throws -> GeneratedInterfaceDetails?
627+
{
626628
throw ResponseError.unknown("unsupported method")
627629
}
628630

Sources/SourceKitLSP/LanguageService.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ public struct RenameLocation: Sendable {
7676
let usage: Usage
7777
}
7878

79+
/// The textual output of a module interface.
80+
public struct GeneratedInterfaceDetails: ResponseType, Hashable {
81+
82+
public var uri: DocumentURI
83+
public var position: Position?
84+
85+
public init(uri: DocumentURI, position: Position?) {
86+
self.uri = uri
87+
self.position = position
88+
}
89+
}
90+
7991
/// Provides language specific functionality to sourcekit-lsp from a specific toolchain.
8092
///
8193
/// For example, we may have a language service that provides semantic functionality for c-family using a clangd server,
@@ -147,7 +159,7 @@ public protocol LanguageService: AnyObject, Sendable {
147159
func hover(_ req: HoverRequest) async throws -> HoverResponse?
148160
func symbolInfo(_ request: SymbolInfoRequest) async throws -> [SymbolDetails]
149161
func openGeneratedInterface(
150-
textDocument: TextDocumentIdentifier,
162+
document: DocumentURI,
151163
moduleName: String,
152164
groupName: String?,
153165
symbolUSR symbol: String?

Sources/SourceKitLSP/SourceKitLSPServer.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,15 +1475,15 @@ extension SourceKitLSPServer {
14751475
}
14761476

14771477
func openGeneratedInterface(
1478-
textDocument: TextDocumentIdentifier,
1478+
document: DocumentURI,
14791479
moduleName: String,
14801480
groupName: String?,
14811481
symbolUSR symbol: String?,
14821482
workspace: Workspace,
14831483
languageService: LanguageService
14841484
) async throws -> GeneratedInterfaceDetails? {
14851485
return try await languageService.openGeneratedInterface(
1486-
textDocument: textDocument,
1486+
document: document,
14871487
moduleName: moduleName,
14881488
groupName: groupName,
14891489
symbolUSR: symbol
@@ -1891,12 +1891,14 @@ extension SourceKitLSPServer {
18911891
originatorUri: DocumentURI,
18921892
languageService: LanguageService
18931893
) async throws -> Location {
1894-
guard let interfaceDetails = try await languageService.openGeneratedInterface(
1895-
textDocument: TextDocumentIdentifier(originatorUri),
1896-
moduleName: moduleName,
1897-
groupName: groupName,
1898-
symbolUSR: symbolUSR
1899-
) else {
1894+
guard
1895+
let interfaceDetails = try await languageService.openGeneratedInterface(
1896+
document: originatorUri,
1897+
moduleName: moduleName,
1898+
groupName: groupName,
1899+
symbolUSR: symbolUSR
1900+
)
1901+
else {
19001902
throw ResponseError.unknown("Could not generate Swift Interface for \(moduleName)")
19011903
}
19021904
let position = interfaceDetails.position ?? Position(line: 0, utf16index: 0)

Sources/SourceKitLSP/Swift/OpenInterface.swift

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@ struct GeneratedInterfaceInfo {
2222

2323
extension SwiftLanguageService {
2424
public func openGeneratedInterface(
25-
textDocument: TextDocumentIdentifier,
25+
document: DocumentURI,
2626
moduleName: String,
2727
groupName: String?,
2828
symbolUSR symbol: String?
2929
) async throws -> GeneratedInterfaceDetails? {
30-
// Name of interface module name with group names appended
31-
let name = if let groupName {
30+
// Name of interface module name with group names appended
31+
let name =
32+
if let groupName {
3233
"\(moduleName).\(groupName.replacing("/", with: "."))"
33-
} else {
34+
} else {
3435
moduleName
35-
}
36+
}
3637
let interfaceFilePath = self.generatedInterfacesPath.appendingPathComponent("\(name).swiftinterface")
3738
let interfaceDocURI = DocumentURI(interfaceFilePath)
3839
// has interface already been generated
@@ -43,12 +44,12 @@ extension SwiftLanguageService {
4344
symbol: symbol
4445
)
4546
} else {
46-
let interfaceInfo = try await self.generatedInterfaceInfo(
47-
textDocument: textDocument,
48-
moduleName: moduleName,
49-
groupName: groupName,
50-
interfaceURI: interfaceDocURI
51-
)
47+
let interfaceInfo = try await self.generatedInterfaceInfo(
48+
document: document,
49+
moduleName: moduleName,
50+
groupName: groupName,
51+
interfaceURI: interfaceDocURI
52+
)
5253
try interfaceInfo.contents.write(to: interfaceFilePath, atomically: true, encoding: String.Encoding.utf8)
5354
let snapshot = DocumentSnapshot(
5455
uri: interfaceDocURI,
@@ -77,7 +78,7 @@ extension SwiftLanguageService {
7778
/// - Important: This opens a document with name `interfaceURI.pseudoPath` in sourcekitd. The caller is responsible
7879
/// for ensuring that the document will eventually get closed in sourcekitd again.
7980
private func generatedInterfaceInfo(
80-
textDocument: TextDocumentIdentifier,
81+
document: DocumentURI,
8182
moduleName: String,
8283
groupName: String?,
8384
interfaceURI: DocumentURI
@@ -89,7 +90,7 @@ extension SwiftLanguageService {
8990
keys.groupName: groupName,
9091
keys.name: interfaceURI.pseudoPath,
9192
keys.synthesizedExtension: 1,
92-
keys.compilerArgs: await self.buildSettings(for: textDocument.uri)?.compilerArgs as [SKDRequestValue]?,
93+
keys.compilerArgs: await self.buildSettings(for: document)?.compilerArgs as [SKDRequestValue]?,
9394
])
9495

9596
let dict = try await self.sourcekitd.send(skreq, fileContents: nil)

0 commit comments

Comments
 (0)