Skip to content

Commit 99de177

Browse files
committed
Accept Location for workspace/peekDocument
This allows the peek window to scroll to a position within the peeked document.
1 parent 926a40c commit 99de177

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

src/sourcekit-lsp/LanguageClientConfiguration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function initializationOptions(swiftVersion: Version): any {
4545
options = {
4646
"workspace/peekDocuments": {
4747
supported: true, // workaround for client capability to handle `PeekDocumentsRequest`
48+
peekLocation: true, // allow SourceKit-LSP to send `Location` instead of `DocumentUri` for the locations to peek.
4849
},
4950
"workspace/getReferenceDocument": {
5051
supported: true, // the client can handle URIs with scheme `sourcekit-lsp:`

src/sourcekit-lsp/extensions/PeekDocumentsRequest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// We use namespaces to store request information just like vscode-languageclient
1616
/* eslint-disable @typescript-eslint/no-namespace */
1717

18-
import { DocumentUri, Position, MessageDirection, RequestType } from "vscode-languageclient";
18+
import { DocumentUri, Position, Location, MessageDirection, RequestType } from "vscode-languageclient";
1919

2020
/** Parameters used to make a {@link PeekDocumentsRequest}. */
2121
export interface PeekDocumentsParams {
@@ -30,9 +30,9 @@ export interface PeekDocumentsParams {
3030
position: Position;
3131

3232
/**
33-
* An array `DocumentUri` of the documents to appear inside the "peeked" editor
33+
* An array `DocumentUri` or `Location` of the documents to appear inside the "peeked" editor
3434
*/
35-
locations: DocumentUri[];
35+
locations: DocumentUri[] | Location[];
3636
}
3737

3838
/** Response to indicate the `success` of the {@link PeekDocumentsRequest}. */

src/sourcekit-lsp/peekDocuments.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,16 @@ export function activatePeekDocuments(client: langclient.LanguageClient): vscode
8888
params.position.character
8989
);
9090

91-
const peekLocations = params.locations.map(
92-
location =>
93-
new vscode.Location(
91+
const peekLocations = params.locations.map(location => {
92+
if (typeof location === "string") {
93+
// DocumentUri is a typedef of `string`, so effectively we are checking for DocumentUri here
94+
return new vscode.Location(
9495
client.protocol2CodeConverter.asUri(location),
9596
new vscode.Position(0, 0)
96-
)
97-
);
97+
);
98+
}
99+
return client.protocol2CodeConverter.asLocation(location);
100+
});
98101

99102
await openPeekedEditorIn(peekURI, peekPosition, peekLocations);
100103

0 commit comments

Comments
 (0)