Skip to content

Commit 91c55f9

Browse files
authored
Merge pull request #1532 from AppAppWorks/remove-OpenGeneratedInterfaceRequest
removed OpenGeneratedInterfaceRequest
2 parents 5784bf8 + eb6f919 commit 91c55f9

File tree

9 files changed

+151
-149
lines changed

9 files changed

+151
-149
lines changed

Documentation/LSP Extensions.md

+76-16
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/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ add_library(LanguageServerProtocol STATIC
6666
Requests/InlineValueRequest.swift
6767
Requests/LinkedEditingRangeRequest.swift
6868
Requests/MonikersRequest.swift
69-
Requests/OpenInterfaceRequest.swift
7069
Requests/PollIndexRequest.swift
7170
Requests/PrepareRenameRequest.swift
7271
Requests/ReferencesRequest.swift

Sources/LanguageServerProtocol/Messages.swift

-1
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

-57
This file was deleted.

Sources/SourceKitLSP/Clang/ClangLanguageService.swift

+6-1
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

+25-1
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,20 @@ 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+
/// - Parameters:
165+
/// - document: The document whose compiler arguments should be used to generate the interface.
166+
/// - moduleName: The module to generate an index for.
167+
/// - groupName: The module group name.
168+
/// - symbol: The symbol USR to search for in the generated module interface.
169+
func openGeneratedInterface(
170+
document: DocumentURI,
171+
moduleName: String,
172+
groupName: String?,
173+
symbolUSR symbol: String?
174+
) async throws -> GeneratedInterfaceDetails?
151175

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

Sources/SourceKitLSP/SourceKitLSPServer.swift

+18-11
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

+26-12
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
@@ -61,31 +72,34 @@ extension SwiftLanguageService {
6172
/// Open the Swift interface for a module.
6273
///
6374
/// - Parameters:
64-
/// - request: The OpenGeneratedInterfaceRequest.
75+
/// - document: The document whose compiler arguments should be used to generate the interface.
76+
/// - moduleName: The module to generate an index for.
77+
/// - groupName: The module group name.
6578
/// - interfaceURI: The file where the generated interface should be written.
6679
///
6780
/// - Important: This opens a document with name `interfaceURI.pseudoPath` in sourcekitd. The caller is responsible
6881
/// for ensuring that the document will eventually get closed in sourcekitd again.
6982
private func generatedInterfaceInfo(
70-
request: OpenGeneratedInterfaceRequest,
83+
document: DocumentURI,
84+
moduleName: String,
85+
groupName: String?,
7186
interfaceURI: DocumentURI
7287
) async throws -> GeneratedInterfaceInfo {
7388
let keys = self.keys
7489
let skreq = sourcekitd.dictionary([
7590
keys.request: requests.editorOpenInterface,
76-
keys.moduleName: request.moduleName,
77-
keys.groupName: request.groupName,
91+
keys.moduleName: moduleName,
92+
keys.groupName: groupName,
7893
keys.name: interfaceURI.pseudoPath,
7994
keys.synthesizedExtension: 1,
80-
keys.compilerArgs: await self.buildSettings(for: request.textDocument.uri)?.compilerArgs as [SKDRequestValue]?,
95+
keys.compilerArgs: await self.buildSettings(for: document)?.compilerArgs as [SKDRequestValue]?,
8196
])
8297

8398
let dict = try await self.sourcekitd.send(skreq, fileContents: nil)
8499
return GeneratedInterfaceInfo(contents: dict[keys.sourceText] ?? "")
85100
}
86101

87102
private func generatedInterfaceDetails(
88-
request: OpenGeneratedInterfaceRequest,
89103
uri: DocumentURI,
90104
snapshot: DocumentSnapshot,
91105
symbol: String?

0 commit comments

Comments
 (0)