aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/commands.ts')
-rw-r--r--editors/code/src/commands.ts52
1 files changed, 43 insertions, 9 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index 3e96fbad8..694f445bc 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.ts
@@ -9,6 +9,7 @@ import { RunnableQuickPick, selectRunnable, createTask, createArgs } from './run
9import { AstInspector } from './ast_inspector'; 9import { AstInspector } from './ast_inspector';
10import { isRustDocument, sleep, isRustEditor } from './util'; 10import { isRustDocument, sleep, isRustEditor } from './util';
11import { startDebugSession, makeDebugConfig } from './debug'; 11import { startDebugSession, makeDebugConfig } from './debug';
12import { LanguageClient } from 'vscode-languageclient/node';
12 13
13export * from './ast_inspector'; 14export * from './ast_inspector';
14export * from './run'; 15export * from './run';
@@ -455,17 +456,20 @@ export function reloadWorkspace(ctx: Ctx): Cmd {
455 return async () => ctx.client.sendRequest(ra.reloadWorkspace); 456 return async () => ctx.client.sendRequest(ra.reloadWorkspace);
456} 457}
457 458
459async function showReferencesImpl(client: LanguageClient, uri: string, position: lc.Position, locations: lc.Location[]) {
460 if (client) {
461 await vscode.commands.executeCommand(
462 'editor.action.showReferences',
463 vscode.Uri.parse(uri),
464 client.protocol2CodeConverter.asPosition(position),
465 locations.map(client.protocol2CodeConverter.asLocation),
466 );
467 }
468}
469
458export function showReferences(ctx: Ctx): Cmd { 470export function showReferences(ctx: Ctx): Cmd {
459 return async (uri: string, position: lc.Position, locations: lc.Location[]) => { 471 return async (uri: string, position: lc.Position, locations: lc.Location[]) => {
460 const client = ctx.client; 472 await showReferencesImpl(ctx.client, uri, position, locations);
461 if (client) {
462 await vscode.commands.executeCommand(
463 'editor.action.showReferences',
464 vscode.Uri.parse(uri),
465 client.protocol2CodeConverter.asPosition(position),
466 locations.map(client.protocol2CodeConverter.asLocation),
467 );
468 }
469 }; 473 };
470} 474}
471 475
@@ -554,6 +558,36 @@ export function run(ctx: Ctx): Cmd {
554 }; 558 };
555} 559}
556 560
561export function peekTests(ctx: Ctx): Cmd {
562 const client = ctx.client;
563
564 return async () => {
565 const editor = ctx.activeRustEditor;
566 if (!editor || !client) return;
567
568 await vscode.window.withProgress({
569 location: vscode.ProgressLocation.Notification,
570 title: "Looking for tests...",
571 cancellable: false,
572 }, async (_progress, _token) => {
573 const uri = editor.document.uri.toString();
574 const position = client.code2ProtocolConverter.asPosition(
575 editor.selection.active,
576 );
577
578 const tests = await client.sendRequest(ra.relatedTests, {
579 textDocument: { uri: uri },
580 position: position,
581 });
582 const locations: lc.Location[] = tests.map(it =>
583 lc.Location.create(it.runnable.location!.targetUri, it.runnable.location!.targetSelectionRange));
584
585 await showReferencesImpl(client, uri, position, locations);
586 });
587 };
588}
589
590
557export function runSingle(ctx: Ctx): Cmd { 591export function runSingle(ctx: Ctx): Cmd {
558 return async (runnable: ra.Runnable) => { 592 return async (runnable: ra.Runnable) => {
559 const editor = ctx.activeRustEditor; 593 const editor = ctx.activeRustEditor;