Skip to content

removed OpenGeneratedInterfaceRequest #1532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 76 additions & 16 deletions Documentation/LSP Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,39 +73,99 @@ Added case
identifier = 'identifier'
```

## `textDocument/interface`
## `WorkspaceFolder`

New request that request a textual interface of a module to display in the IDE. Used internally within SourceKit-LSP
Added field:

```ts
/**
* Build settings that should be used for this workspace.
*
* For arguments that have a single value (like the build configuration), this takes precedence over the global
* options set when launching sourcekit-lsp. For all other options, the values specified in the workspace-specific
* build setup are appended to the global options.
*/
var buildSetup?: WorkspaceBuildSetup
```

- params: `OpenInterfaceParams`
- result: `InterfaceDetails?`
with

```ts
export interface OpenInterfaceRequest: TextDocumentRequest, Hashable {
/**
* The configuration to build a workspace in.
*/
export enum BuildConfiguration {
case debug = 'debug'
case release = 'release'
}

/**
* The type of workspace; default workspace type selection logic can be overridden.
*/
export enum WorkspaceType {
buildServer = 'buildServer'
compilationDatabase = 'compilationDatabase'
swiftPM = 'swiftPM'
}

/// Build settings that should be used for a workspace.
interface WorkspaceBuildSetup {
/**
* The document whose compiler arguments should be used to generate the interface.
* The configuration that the workspace should be built in.
*/
textDocument: TextDocumentIdentifier
buildConfiguration?: BuildConfiguration

/**
* The module to generate an index for.
* The default workspace type to use for this workspace.
*/
moduleName: string
defaultWorkspaceType?: WorkspaceType

/**
* The module group name.
* The build directory for the workspace.
*/
groupName?: string
scratchPath?: DocumentURI

/**
* Arguments to be passed to any C compiler invocations.
*/
cFlags?: string[]

/**
* Arguments to be passed to any C++ compiler invocations.
*/
cxxFlags?: string[]

/**
* Arguments to be passed to any linker invocations.
*/
linkerFlags?: string[]

/**
* The symbol USR to search for in the generated module interface.
* Arguments to be passed to any Swift compiler invocations.
*/
symbolUSR?: string
swiftFlags?: string[]
}
```

## `textDocument/completion`

Added field:

```ts
/**
* Options to control code completion behavior in Swift
*/
sourcekitlspOptions?: SKCompletionOptions
```

with

interface InterfaceDetails {
uri: DocumentURI
position?: Position
```ts
interface SKCompletionOptions {
/**
* The maximum number of completion results to return, or `null` for unlimited.
*/
maxResults?: int
}
```

Expand Down
1 change: 0 additions & 1 deletion Sources/LanguageServerProtocol/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ add_library(LanguageServerProtocol STATIC
Requests/InlineValueRequest.swift
Requests/LinkedEditingRangeRequest.swift
Requests/MonikersRequest.swift
Requests/OpenInterfaceRequest.swift
Requests/PollIndexRequest.swift
Requests/PrepareRenameRequest.swift
Requests/ReferencesRequest.swift
Expand Down
1 change: 0 additions & 1 deletion Sources/LanguageServerProtocol/Messages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public let builtinRequests: [_RequestType.Type] = [
InlineValueRequest.self,
LinkedEditingRangeRequest.self,
MonikersRequest.self,
OpenGeneratedInterfaceRequest.self,
PollIndexRequest.self,
PrepareRenameRequest.self,
ReferencesRequest.self,
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove this file from CMakeLists.txt. On Windows SourceKit-LSP is built using CMake instead of SwiftPM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, please check

This file was deleted.

7 changes: 6 additions & 1 deletion Sources/SourceKitLSP/Clang/ClangLanguageService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,12 @@ extension ClangLanguageService {
return try await forwardRequestToClangd(req)
}

func openGeneratedInterface(_ request: OpenGeneratedInterfaceRequest) async throws -> GeneratedInterfaceDetails? {
func openGeneratedInterface(
document: DocumentURI,
moduleName: String,
groupName: String?,
symbolUSR symbol: String?
) async throws -> GeneratedInterfaceDetails? {
throw ResponseError.unknown("unsupported method")
}

Expand Down
26 changes: 25 additions & 1 deletion Sources/SourceKitLSP/LanguageService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ public struct RenameLocation: Sendable {
let usage: Usage
}

/// The textual output of a module interface.
public struct GeneratedInterfaceDetails: ResponseType, Hashable {
public var uri: DocumentURI
public var position: Position?

public init(uri: DocumentURI, position: Position?) {
self.uri = uri
self.position = position
}
}

/// Provides language specific functionality to sourcekit-lsp from a specific toolchain.
///
/// For example, we may have a language service that provides semantic functionality for c-family using a clangd server,
Expand Down Expand Up @@ -147,7 +158,20 @@ public protocol LanguageService: AnyObject, Sendable {
func completion(_ req: CompletionRequest) async throws -> CompletionList
func hover(_ req: HoverRequest) async throws -> HoverResponse?
func symbolInfo(_ request: SymbolInfoRequest) async throws -> [SymbolDetails]
func openGeneratedInterface(_ request: OpenGeneratedInterfaceRequest) async throws -> GeneratedInterfaceDetails?

/// Request a generated interface of a module to display in the IDE.
///
/// - Parameters:
/// - document: The document whose compiler arguments should be used to generate the interface.
/// - moduleName: The module to generate an index for.
/// - groupName: The module group name.
/// - symbol: The symbol USR to search for in the generated module interface.
func openGeneratedInterface(
document: DocumentURI,
moduleName: String,
groupName: String?,
symbolUSR symbol: String?
) async throws -> GeneratedInterfaceDetails?
Comment on lines +169 to +174
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed this in the first review. Could you add the comments of the members in OpenGeneratedInterfaceRequest as parameter documentation to this method?


/// - Note: Only called as a fallback if the definition could not be found in the index.
func definition(_ request: DefinitionRequest) async throws -> LocationsOrLocationLinksResponse?
Expand Down
29 changes: 18 additions & 11 deletions Sources/SourceKitLSP/SourceKitLSPServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,6 @@ extension SourceKitLSPServer: MessageHandler {
initialized = true
case let request as RequestAndReply<InlayHintRequest>:
await self.handleRequest(for: request, requestHandler: self.inlayHint)
case let request as RequestAndReply<OpenGeneratedInterfaceRequest>:
await self.handleRequest(for: request, requestHandler: self.openGeneratedInterface)
case let request as RequestAndReply<PollIndexRequest>:
await request.reply { try await pollIndex(request.params) }
case let request as RequestAndReply<PrepareRenameRequest>:
Expand Down Expand Up @@ -1434,11 +1432,19 @@ extension SourceKitLSPServer {
}

func openGeneratedInterface(
_ req: OpenGeneratedInterfaceRequest,
document: DocumentURI,
moduleName: String,
groupName: String?,
symbolUSR symbol: String?,
workspace: Workspace,
languageService: LanguageService
) async throws -> GeneratedInterfaceDetails? {
return try await languageService.openGeneratedInterface(req)
return try await languageService.openGeneratedInterface(
document: document,
moduleName: moduleName,
groupName: groupName,
symbolUSR: symbol
)
}

/// Find all symbols in the workspace that include a string in their name.
Expand Down Expand Up @@ -1842,13 +1848,14 @@ extension SourceKitLSPServer {
originatorUri: DocumentURI,
languageService: LanguageService
) async throws -> Location {
let openInterface = OpenGeneratedInterfaceRequest(
textDocument: TextDocumentIdentifier(originatorUri),
name: moduleName,
groupName: groupName,
symbolUSR: symbolUSR
)
guard let interfaceDetails = try await languageService.openGeneratedInterface(openInterface) else {
guard
let interfaceDetails = try await languageService.openGeneratedInterface(
document: originatorUri,
moduleName: moduleName,
groupName: groupName,
symbolUSR: symbolUSR
)
else {
throw ResponseError.unknown("Could not generate Swift Interface for \(moduleName)")
}
let position = interfaceDetails.position ?? Position(line: 0, utf16index: 0)
Expand Down
38 changes: 26 additions & 12 deletions Sources/SourceKitLSP/Swift/OpenInterface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,34 @@ struct GeneratedInterfaceInfo {

extension SwiftLanguageService {
public func openGeneratedInterface(
_ request: OpenGeneratedInterfaceRequest
document: DocumentURI,
moduleName: String,
groupName: String?,
symbolUSR symbol: String?
) async throws -> GeneratedInterfaceDetails? {
let name = request.name
let symbol = request.symbolUSR
// Name of interface module name with group names appended
let name =
if let groupName {
"\(moduleName).\(groupName.replacing("/", with: "."))"
} else {
moduleName
}
let interfaceFilePath = self.generatedInterfacesPath.appendingPathComponent("\(name).swiftinterface")
let interfaceDocURI = DocumentURI(interfaceFilePath)
// has interface already been generated
if let snapshot = try? self.documentManager.latestSnapshot(interfaceDocURI) {
return await self.generatedInterfaceDetails(
request: request,
uri: interfaceDocURI,
snapshot: snapshot,
symbol: symbol
)
} else {
let interfaceInfo = try await self.generatedInterfaceInfo(request: request, interfaceURI: interfaceDocURI)
let interfaceInfo = try await self.generatedInterfaceInfo(
document: document,
moduleName: moduleName,
groupName: groupName,
interfaceURI: interfaceDocURI
)
try interfaceInfo.contents.write(to: interfaceFilePath, atomically: true, encoding: String.Encoding.utf8)
let snapshot = DocumentSnapshot(
uri: interfaceDocURI,
Expand All @@ -46,7 +58,6 @@ extension SwiftLanguageService {
lineTable: LineTable(interfaceInfo.contents)
)
let result = await self.generatedInterfaceDetails(
request: request,
uri: interfaceDocURI,
snapshot: snapshot,
symbol: symbol
Expand All @@ -61,31 +72,34 @@ extension SwiftLanguageService {
/// Open the Swift interface for a module.
///
/// - Parameters:
/// - request: The OpenGeneratedInterfaceRequest.
/// - document: The document whose compiler arguments should be used to generate the interface.
/// - moduleName: The module to generate an index for.
/// - groupName: The module group name.
/// - interfaceURI: The file where the generated interface should be written.
///
/// - Important: This opens a document with name `interfaceURI.pseudoPath` in sourcekitd. The caller is responsible
/// for ensuring that the document will eventually get closed in sourcekitd again.
private func generatedInterfaceInfo(
request: OpenGeneratedInterfaceRequest,
document: DocumentURI,
moduleName: String,
groupName: String?,
interfaceURI: DocumentURI
) async throws -> GeneratedInterfaceInfo {
let keys = self.keys
let skreq = sourcekitd.dictionary([
keys.request: requests.editorOpenInterface,
keys.moduleName: request.moduleName,
keys.groupName: request.groupName,
keys.moduleName: moduleName,
keys.groupName: groupName,
keys.name: interfaceURI.pseudoPath,
keys.synthesizedExtension: 1,
keys.compilerArgs: await self.buildSettings(for: request.textDocument.uri)?.compilerArgs as [SKDRequestValue]?,
keys.compilerArgs: await self.buildSettings(for: document)?.compilerArgs as [SKDRequestValue]?,
])

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

private func generatedInterfaceDetails(
request: OpenGeneratedInterfaceRequest,
uri: DocumentURI,
snapshot: DocumentSnapshot,
symbol: String?
Expand Down
Loading