Skip to content

Commit ed32ca4

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

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/sourcekit-lsp/LanguageClientConfiguration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function initializationOptions(swiftVersion: Version): any {
4646
options = {
4747
"workspace/peekDocuments": {
4848
supported: true, // workaround for client capability to handle `PeekDocumentsRequest`
49+
"peekLocation": true, // allow SourceKit-LSP to send `Location` instead of `DocumentUri` for the locations to peek.
4950
},
5051
"workspace/getReferenceDocument": {
5152
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: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,16 @@ export function activatePeekDocuments(client: langclient.LanguageClient): vscode
8989
);
9090

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

99104
await openPeekedEditorIn(peekURI, peekPosition, peekLocations);

0 commit comments

Comments
 (0)