aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands.ts
diff options
context:
space:
mode:
authorvsrs <[email protected]>2021-02-27 17:04:43 +0000
committervsrs <[email protected]>2021-02-27 17:04:43 +0000
commit669e11764430be3a098d6c8fe875d8efbb3547a3 (patch)
tree652dc3728183ea67624116b27f36008677ae9f2a /editors/code/src/commands.ts
parent31f5f816e3747c1a0972d2f0aca25ded9980cd36 (diff)
Add LSP request and VSCode command
Diffstat (limited to 'editors/code/src/commands.ts')
-rw-r--r--editors/code/src/commands.ts51
1 files changed, 42 insertions, 9 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index 283b9a160..3512fefdf 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';
@@ -456,17 +457,20 @@ export function reloadWorkspace(ctx: Ctx): Cmd {
456 return async () => ctx.client.sendRequest(ra.reloadWorkspace); 457 return async () => ctx.client.sendRequest(ra.reloadWorkspace);
457} 458}
458 459
460async function showReferencesImpl(client: LanguageClient, uri: string, position: lc.Position, locations: lc.Location[]) {
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}
470
459export function showReferences(ctx: Ctx): Cmd { 471export function showReferences(ctx: Ctx): Cmd {
460 return async (uri: string, position: lc.Position, locations: lc.Location[]) => { 472 return async (uri: string, position: lc.Position, locations: lc.Location[]) => {
461 const client = ctx.client; 473 await showReferencesImpl(ctx.client, uri, position, locations);
462 if (client) {
463 await vscode.commands.executeCommand(
464 'editor.action.showReferences',
465 vscode.Uri.parse(uri),
466 client.protocol2CodeConverter.asPosition(position),
467 locations.map(client.protocol2CodeConverter.asLocation),
468 );
469 }
470 }; 474 };
471} 475}
472 476
@@ -555,6 +559,35 @@ export function run(ctx: Ctx): Cmd {
555 }; 559 };
556} 560}
557 561
562export function peekTests(ctx: Ctx): Cmd {
563 const client = ctx.client;
564
565 return async () => {
566 const editor = ctx.activeRustEditor;
567 if (!editor || !client) return;
568
569 const uri = editor.document.uri.toString();
570 const position = client.code2ProtocolConverter.asPosition(
571 editor.selection.active,
572 );
573
574 const tests = await client.sendRequest(ra.relatedTests, {
575 textDocument: { uri: uri },
576 position: position,
577 });
578
579 const locations: lc.Location[] = tests.map( it => {
580 return {
581 uri: it.runnable.location!.targetUri,
582 range: it.runnable.location!.targetSelectionRange
583 };
584 });
585
586 await showReferencesImpl(client, uri, position, locations);
587 };
588}
589
590
558export function runSingle(ctx: Ctx): Cmd { 591export function runSingle(ctx: Ctx): Cmd {
559 return async (runnable: ra.Runnable) => { 592 return async (runnable: ra.Runnable) => {
560 const editor = ctx.activeRustEditor; 593 const editor = ctx.activeRustEditor;