Skip to content

Commit bee65ae

Browse files
committed
removed OpenGeneratedInterfaceRequest
deleted OpenInterfaceRequest.swift and moved GeneratedInterfaceDetails to LanguageService.swift replaced usages by passing its members as parameters directly, refactored usage of TextDocumentIdentifier to DocumentURI removed from Messages.builtinRequests removed from SwiftInterfaceTests removed from `LSP Extensions.md`
1 parent e5d93e1 commit bee65ae

File tree

8 files changed

+147
-147
lines changed

8 files changed

+147
-147
lines changed

Documentation/LSP Extensions.md

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,39 +73,99 @@ Added case
7373
identifier = 'identifier'
7474
```
7575
76-
## `textDocument/interface`
76+
## `WorkspaceFolder`
7777
78-
New request that request a textual interface of a module to display in the IDE. Used internally within SourceKit-LSP
78+
Added field:
79+
80+
```ts
81+
/**
82+
* Build settings that should be used for this workspace.
83+
*
84+
* For arguments that have a single value (like the build configuration), this takes precedence over the global
85+
* options set when launching sourcekit-lsp. For all other options, the values specified in the workspace-specific
86+
* build setup are appended to the global options.
87+
*/
88+
var buildSetup?: WorkspaceBuildSetup
89+
```
7990
80-
- params: `OpenInterfaceParams`
81-
- result: `InterfaceDetails?`
91+
with
8292
8393
```ts
84-
export interface OpenInterfaceRequest: TextDocumentRequest, Hashable {
94+
/**
95+
* The configuration to build a workspace in.
96+
*/
97+
export enum BuildConfiguration {
98+
case debug = 'debug'
99+
case release = 'release'
100+
}
101+
102+
/**
103+
* The type of workspace; default workspace type selection logic can be overridden.
104+
*/
105+
export enum WorkspaceType {
106+
buildServer = 'buildServer'
107+
compilationDatabase = 'compilationDatabase'
108+
swiftPM = 'swiftPM'
109+
}
110+
111+
/// Build settings that should be used for a workspace.
112+
interface WorkspaceBuildSetup {
85113
/**
86-
* The document whose compiler arguments should be used to generate the interface.
114+
* The configuration that the workspace should be built in.
87115
*/
88-
textDocument: TextDocumentIdentifier
116+
buildConfiguration?: BuildConfiguration
89117

90118
/**
91-
* The module to generate an index for.
119+
* The default workspace type to use for this workspace.
92120
*/
93-
moduleName: string
121+
defaultWorkspaceType?: WorkspaceType
94122

95123
/**
96-
* The module group name.
124+
* The build directory for the workspace.
97125
*/
98-
groupName?: string
126+
scratchPath?: DocumentURI
127+
128+
/**
129+
* Arguments to be passed to any C compiler invocations.
130+
*/
131+
cFlags?: string[]
132+
133+
/**
134+
* Arguments to be passed to any C++ compiler invocations.
135+
*/
136+
cxxFlags?: string[]
137+
138+
/**
139+
* Arguments to be passed to any linker invocations.
140+
*/
141+
linkerFlags?: string[]
99142

100143
/**
101-
* The symbol USR to search for in the generated module interface.
144+
* Arguments to be passed to any Swift compiler invocations.
102145
*/
103-
symbolUSR?: string
146+
swiftFlags?: string[]
104147
}
148+
```
149+
150+
## `textDocument/completion`
151+
152+
Added field:
153+
154+
```ts
155+
/**
156+
* Options to control code completion behavior in Swift
157+
*/
158+
sourcekitlspOptions?: SKCompletionOptions
159+
```
160+
161+
with
105162
106-
interface InterfaceDetails {
107-
uri: DocumentURI
108-
position?: Position
163+
```ts
164+
interface SKCompletionOptions {
165+
/**
166+
* The maximum number of completion results to return, or `null` for unlimited.
167+
*/
168+
maxResults?: int
109169
}
110170
```
111171

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 & 57 deletions
This file was deleted.

Sources/SourceKitLSP/Clang/ClangLanguageService.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,12 @@ extension ClangLanguageService {
623623
return try await forwardRequestToClangd(req)
624624
}
625625

626-
func openGeneratedInterface(_ request: OpenGeneratedInterfaceRequest) async throws -> GeneratedInterfaceDetails? {
626+
func openGeneratedInterface(
627+
document: DocumentURI,
628+
moduleName: String,
629+
groupName: String?,
630+
symbolUSR symbol: String?
631+
) async throws -> GeneratedInterfaceDetails? {
627632
throw ResponseError.unknown("unsupported method")
628633
}
629634

Sources/SourceKitLSP/LanguageService.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ 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+
public var uri: DocumentURI
82+
public var position: Position?
83+
84+
public init(uri: DocumentURI, position: Position?) {
85+
self.uri = uri
86+
self.position = position
87+
}
88+
}
89+
7990
/// Provides language specific functionality to sourcekit-lsp from a specific toolchain.
8091
///
8192
/// For example, we may have a language service that provides semantic functionality for c-family using a clangd server,
@@ -147,7 +158,19 @@ public protocol LanguageService: AnyObject, Sendable {
147158
func completion(_ req: CompletionRequest) async throws -> CompletionList
148159
func hover(_ req: HoverRequest) async throws -> HoverResponse?
149160
func symbolInfo(_ request: SymbolInfoRequest) async throws -> [SymbolDetails]
150-
func openGeneratedInterface(_ request: OpenGeneratedInterfaceRequest) async throws -> GeneratedInterfaceDetails?
161+
162+
/// Request a generated interface of a module to display in the IDE.
163+
///
164+
/// - Parameter document: The document whose compiler arguments should be used to generate the interface.
165+
/// - Parameter moduleName: The module to generate an index for.
166+
/// - Parameter groupName: The module group name.
167+
/// - Parameter symbol: The symbol USR to search for in the generated module interface.
168+
func openGeneratedInterface(
169+
document: DocumentURI,
170+
moduleName: String,
171+
groupName: String?,
172+
symbolUSR symbol: String?
173+
) async throws -> GeneratedInterfaceDetails?
151174

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

Sources/SourceKitLSP/SourceKitLSPServer.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,6 @@ extension SourceKitLSPServer: MessageHandler {
743743
initialized = true
744744
case let request as RequestAndReply<InlayHintRequest>:
745745
await self.handleRequest(for: request, requestHandler: self.inlayHint)
746-
case let request as RequestAndReply<OpenGeneratedInterfaceRequest>:
747-
await self.handleRequest(for: request, requestHandler: self.openGeneratedInterface)
748746
case let request as RequestAndReply<PollIndexRequest>:
749747
await request.reply { try await pollIndex(request.params) }
750748
case let request as RequestAndReply<PrepareRenameRequest>:
@@ -1434,11 +1432,19 @@ extension SourceKitLSPServer {
14341432
}
14351433

14361434
func openGeneratedInterface(
1437-
_ req: OpenGeneratedInterfaceRequest,
1435+
document: DocumentURI,
1436+
moduleName: String,
1437+
groupName: String?,
1438+
symbolUSR symbol: String?,
14381439
workspace: Workspace,
14391440
languageService: LanguageService
14401441
) async throws -> GeneratedInterfaceDetails? {
1441-
return try await languageService.openGeneratedInterface(req)
1442+
return try await languageService.openGeneratedInterface(
1443+
document: document,
1444+
moduleName: moduleName,
1445+
groupName: groupName,
1446+
symbolUSR: symbol
1447+
)
14421448
}
14431449

14441450
/// Find all symbols in the workspace that include a string in their name.
@@ -1842,13 +1848,14 @@ extension SourceKitLSPServer {
18421848
originatorUri: DocumentURI,
18431849
languageService: LanguageService
18441850
) async throws -> Location {
1845-
let openInterface = OpenGeneratedInterfaceRequest(
1846-
textDocument: TextDocumentIdentifier(originatorUri),
1847-
name: moduleName,
1848-
groupName: groupName,
1849-
symbolUSR: symbolUSR
1850-
)
1851-
guard let interfaceDetails = try await languageService.openGeneratedInterface(openInterface) else {
1851+
guard
1852+
let interfaceDetails = try await languageService.openGeneratedInterface(
1853+
document: originatorUri,
1854+
moduleName: moduleName,
1855+
groupName: groupName,
1856+
symbolUSR: symbolUSR
1857+
)
1858+
else {
18521859
throw ResponseError.unknown("Could not generate Swift Interface for \(moduleName)")
18531860
}
18541861
let position = interfaceDetails.position ?? Position(line: 0, utf16index: 0)

Sources/SourceKitLSP/Swift/OpenInterface.swift

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

2323
extension SwiftLanguageService {
2424
public func openGeneratedInterface(
25-
_ request: OpenGeneratedInterfaceRequest
25+
document: DocumentURI,
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 =
32+
if let groupName {
33+
"\(moduleName).\(groupName.replacing("/", with: "."))"
34+
} else {
35+
moduleName
36+
}
2937
let interfaceFilePath = self.generatedInterfacesPath.appendingPathComponent("\(name).swiftinterface")
3038
let interfaceDocURI = DocumentURI(interfaceFilePath)
3139
// has interface already been generated
3240
if let snapshot = try? self.documentManager.latestSnapshot(interfaceDocURI) {
3341
return await self.generatedInterfaceDetails(
34-
request: request,
3542
uri: interfaceDocURI,
3643
snapshot: snapshot,
3744
symbol: symbol
3845
)
3946
} else {
40-
let interfaceInfo = try await self.generatedInterfaceInfo(request: request, interfaceURI: interfaceDocURI)
47+
let interfaceInfo = try await self.generatedInterfaceInfo(
48+
document: document,
49+
moduleName: moduleName,
50+
groupName: groupName,
51+
interfaceURI: interfaceDocURI
52+
)
4153
try interfaceInfo.contents.write(to: interfaceFilePath, atomically: true, encoding: String.Encoding.utf8)
4254
let snapshot = DocumentSnapshot(
4355
uri: interfaceDocURI,
@@ -46,7 +58,6 @@ extension SwiftLanguageService {
4658
lineTable: LineTable(interfaceInfo.contents)
4759
)
4860
let result = await self.generatedInterfaceDetails(
49-
request: request,
5061
uri: interfaceDocURI,
5162
snapshot: snapshot,
5263
symbol: symbol
@@ -67,25 +78,26 @@ extension SwiftLanguageService {
6778
/// - Important: This opens a document with name `interfaceURI.pseudoPath` in sourcekitd. The caller is responsible
6879
/// for ensuring that the document will eventually get closed in sourcekitd again.
6980
private func generatedInterfaceInfo(
70-
request: OpenGeneratedInterfaceRequest,
81+
document: DocumentURI,
82+
moduleName: String,
83+
groupName: String?,
7184
interfaceURI: DocumentURI
7285
) async throws -> GeneratedInterfaceInfo {
7386
let keys = self.keys
7487
let skreq = sourcekitd.dictionary([
7588
keys.request: requests.editorOpenInterface,
76-
keys.moduleName: request.moduleName,
77-
keys.groupName: request.groupName,
89+
keys.moduleName: moduleName,
90+
keys.groupName: groupName,
7891
keys.name: interfaceURI.pseudoPath,
7992
keys.synthesizedExtension: 1,
80-
keys.compilerArgs: await self.buildSettings(for: request.textDocument.uri)?.compilerArgs as [SKDRequestValue]?,
93+
keys.compilerArgs: await self.buildSettings(for: document)?.compilerArgs as [SKDRequestValue]?,
8194
])
8295

8396
let dict = try await self.sourcekitd.send(skreq, fileContents: nil)
8497
return GeneratedInterfaceInfo(contents: dict[keys.sourceText] ?? "")
8598
}
8699

87100
private func generatedInterfaceDetails(
88-
request: OpenGeneratedInterfaceRequest,
89101
uri: DocumentURI,
90102
snapshot: DocumentSnapshot,
91103
symbol: String?

0 commit comments

Comments
 (0)