Skip to content

Commit 13cd4a4

Browse files
authored
Accept Location for workspace/peekDocument (#1716)
1 parent 926a40c commit 13cd4a4

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
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 {
19+
DocumentUri,
20+
Position,
21+
Location,
22+
MessageDirection,
23+
RequestType,
24+
} from "vscode-languageclient";
1925

2026
/** Parameters used to make a {@link PeekDocumentsRequest}. */
2127
export interface PeekDocumentsParams {
@@ -30,9 +36,9 @@ export interface PeekDocumentsParams {
3036
position: Position;
3137

3238
/**
33-
* An array `DocumentUri` of the documents to appear inside the "peeked" editor
39+
* An array `DocumentUri` or `Location` of the documents to appear inside the "peeked" editor
3440
*/
35-
locations: DocumentUri[];
41+
locations: DocumentUri[] | Location[];
3642
}
3743

3844
/** 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)