Skip to content

Commit f05fb57

Browse files
committed
Replace PeekMacroRequest with a more generic PeekDocumentsRequest
1 parent 450406d commit f05fb57

File tree

2 files changed

+34
-41
lines changed

2 files changed

+34
-41
lines changed

src/sourcekit-lsp/LanguageClientManager.ts

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { DiagnosticsManager } from "../DiagnosticsManager";
2727
import { LSPLogger, LSPOutputChannel } from "./LSPOutputChannel";
2828
import { SwiftOutputChannel } from "../ui/SwiftOutputChannel";
2929
import { promptForDiagnostics } from "../commands/captureDiagnostics";
30-
import { PeekMacroParams, PeekMacroRequest } from "./lspExtensions";
30+
import { PeekDocumentsParams, PeekDocumentsRequest } from "./lspExtensions";
3131

3232
interface SourceKitLogMessageParams extends langclient.LogMessageParams {
3333
logName?: string;
@@ -620,36 +620,32 @@ export class LanguageClientManager {
620620
this.languageClient = client;
621621
this.cancellationToken = new vscode.CancellationTokenSource();
622622

623-
this.languageClient.onRequest(PeekMacroRequest.method, async (params: PeekMacroParams) => {
624-
const locations = params.macroExpansion.expansionURIs.map(uri => {
625-
const location = new vscode.Location(
626-
vscode.Uri.from({
627-
scheme: "file",
628-
path: new URL(uri).pathname,
629-
}),
630-
new vscode.Position(0, 0)
631-
);
632-
633-
return location;
634-
});
635-
636-
console.log(params.peekLocation);
623+
this.languageClient.onRequest(
624+
PeekDocumentsRequest.method,
625+
async (params: PeekDocumentsParams) => {
626+
const locations = params.locations.map(uri => {
627+
const location = new vscode.Location(
628+
vscode.Uri.from({
629+
scheme: "file",
630+
path: new URL(uri).pathname,
631+
}),
632+
new vscode.Position(0, 0)
633+
);
637634

638-
const peekPosition = new vscode.Position(
639-
params.peekLocation.line,
640-
params.peekLocation.character
641-
);
635+
return location;
636+
});
642637

643-
await vscode.commands.executeCommand(
644-
"editor.action.peekLocations",
645-
vscode.window.activeTextEditor?.document.uri,
646-
peekPosition,
647-
locations,
648-
"peek"
649-
);
638+
await vscode.commands.executeCommand(
639+
"editor.action.peekLocations",
640+
params.uri ?? vscode.window.activeTextEditor?.document.uri,
641+
params.position ?? vscode.window.activeTextEditor?.selection.active,
642+
locations,
643+
params.multiple
644+
);
650645

651-
return { success: true };
652-
});
646+
return { success: true };
647+
}
648+
);
653649

654650
return this.clientReadyPromise;
655651
}

src/sourcekit-lsp/lspExtensions.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,22 @@ import { Position, Uri } from "vscode";
1818

1919
// Definitions for non-standard requests used by sourcekit-lsp
2020

21-
export interface PeekMacroParams {
22-
macroExpansion: MacroExpansion;
23-
peekLocation: Position;
21+
export interface PeekDocumentsParams {
22+
uri?: Uri;
23+
position?: Position;
24+
locations: Uri[];
25+
multiple: string;
2426
}
2527

26-
interface MacroExpansion {
27-
expansionURIs: Uri[];
28-
}
29-
30-
export interface PeekMacroResult {
28+
export interface PeekDocumentsResult {
3129
success: boolean;
32-
failureReason?: string;
3330
}
3431

35-
export const PeekMacroRequest = new langclient.RequestType<
36-
PeekMacroParams,
37-
PeekMacroResult,
32+
export const PeekDocumentsRequest = new langclient.RequestType<
33+
PeekDocumentsParams,
34+
PeekDocumentsResult,
3835
unknown
39-
>("sourcekit-lsp/peekMacro");
36+
>("sourcekit-lsp/peekDocuments");
4037

4138
// Inlay Hints (pre Swift 5.6)
4239
export interface LegacyInlayHintsParams {

0 commit comments

Comments
 (0)