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.ts57
1 files changed, 45 insertions, 12 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index 283b9a160..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';
@@ -253,11 +254,10 @@ export function ssr(ctx: Ctx): Cmd {
253export function serverVersion(ctx: Ctx): Cmd { 254export function serverVersion(ctx: Ctx): Cmd {
254 return async () => { 255 return async () => {
255 const { stdout } = spawnSync(ctx.serverPath, ["--version"], { encoding: "utf8" }); 256 const { stdout } = spawnSync(ctx.serverPath, ["--version"], { encoding: "utf8" });
256 const commitHash = stdout.slice(`rust-analyzer `.length).trim(); 257 const versionString = stdout.slice(`rust-analyzer `.length).trim();
257 const { releaseTag } = ctx.config.package;
258 258
259 void vscode.window.showInformationMessage( 259 void vscode.window.showInformationMessage(
260 `rust-analyzer version: ${releaseTag ?? "unreleased"} (${commitHash})` 260 `rust-analyzer version: ${versionString}`
261 ); 261 );
262 }; 262 };
263} 263}
@@ -456,17 +456,20 @@ export function reloadWorkspace(ctx: Ctx): Cmd {
456 return async () => ctx.client.sendRequest(ra.reloadWorkspace); 456 return async () => ctx.client.sendRequest(ra.reloadWorkspace);
457} 457}
458 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
459export function showReferences(ctx: Ctx): Cmd { 470export function showReferences(ctx: Ctx): Cmd {
460 return async (uri: string, position: lc.Position, locations: lc.Location[]) => { 471 return async (uri: string, position: lc.Position, locations: lc.Location[]) => {
461 const client = ctx.client; 472 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 }; 473 };
471} 474}
472 475
@@ -555,6 +558,36 @@ export function run(ctx: Ctx): Cmd {
555 }; 558 };
556} 559}
557 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
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;