mirror of
https://github.com/apple/sourcekit-lsp.git
synced 2026-03-02 18:23:24 +01:00
------------------------------------------------------------------------------- This implements an LSP Extension `PeekDocumentsRequest` to let `ExpandMacroCommand` to open the macro expansions in a "peeked" editor window. For this to work, the client has to pass "workspace/peekDocuments" enabled to `ClientCapabilities.experimental` and the client should handle the `PeekDocumentsRequest` and show the expansions in a "peeked" editor window. PR to support the above capability in the "Swift for VS Code" Extension: https://github.com/swiftlang/vscode-swift/pull/945 The "Swift for VS Code" extension cannot send the client capability, so it instead passes the same through `initializationOptions` in the `InitializeRequest`. For editors which doesn't support this capability, `sourcekit-lsp` sends a `ShowDocumentRequest`. The `ShowDocumentRequest` is updated to show all the macro expansions in a single generated file. Moreover, its folder structure is updated to use hex string of MD5 hash of concatenation of buffer names of expansions. Fixes https://github.com/swiftlang/vscode-swift/issues/564 Fixes https://github.com/swiftlang/sourcekit-lsp/issues/1498 ( rdar://130207754 )
58 lines
2.1 KiB
Swift
58 lines
2.1 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// Request from the server to the client to show the given documents in a "peeked" editor **(LSP Extension)**
|
|
///
|
|
/// This request is handled by the client to show the given documents in a
|
|
/// "peeked" editor (i.e. inline with / inside the editor canvas). This is
|
|
/// similar to VS Code's built-in "editor.action.peekLocations" command.
|
|
///
|
|
/// - Parameters:
|
|
/// - uri: The DocumentURI of the text document in which to show the "peeked" editor
|
|
/// - position: The position in the given text document in which to show the "peeked editor"
|
|
/// - locations: The DocumentURIs of documents to appear inside the "peeked" editor
|
|
///
|
|
/// - Returns: `PeekDocumentsResponse` which indicates the `success` of the request.
|
|
///
|
|
/// ### LSP Extension
|
|
///
|
|
/// This request is an extension to LSP supported by SourceKit-LSP.
|
|
/// It requires the experimental client capability `"workspace/peekDocuments"` to use.
|
|
/// It also needs the client to handle the request and present the "peeked" editor.
|
|
public struct PeekDocumentsRequest: RequestType {
|
|
public static let method: String = "workspace/peekDocuments"
|
|
public typealias Response = PeekDocumentsResponse
|
|
|
|
public var uri: DocumentURI
|
|
public var position: Position
|
|
public var locations: [DocumentURI]
|
|
|
|
public init(
|
|
uri: DocumentURI,
|
|
position: Position,
|
|
locations: [DocumentURI]
|
|
) {
|
|
self.uri = uri
|
|
self.position = position
|
|
self.locations = locations
|
|
}
|
|
}
|
|
|
|
/// Response to indicate the `success` of the `PeekDocumentsRequest`
|
|
public struct PeekDocumentsResponse: ResponseType {
|
|
public var success: Bool
|
|
|
|
public init(success: Bool) {
|
|
self.success = success
|
|
}
|
|
}
|