diff options
Diffstat (limited to 'editors/code/src')
-rw-r--r-- | editors/code/src/commands.ts | 52 | ||||
-rw-r--r-- | editors/code/src/lsp_ext.ts | 6 | ||||
-rw-r--r-- | editors/code/src/main.ts | 1 |
3 files changed, 50 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 | |||
9 | import { AstInspector } from './ast_inspector'; | 9 | import { AstInspector } from './ast_inspector'; |
10 | import { isRustDocument, sleep, isRustEditor } from './util'; | 10 | import { isRustDocument, sleep, isRustEditor } from './util'; |
11 | import { startDebugSession, makeDebugConfig } from './debug'; | 11 | import { startDebugSession, makeDebugConfig } from './debug'; |
12 | import { LanguageClient } from 'vscode-languageclient/node'; | ||
12 | 13 | ||
13 | export * from './ast_inspector'; | 14 | export * from './ast_inspector'; |
14 | export * from './run'; | 15 | export * 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 | ||
459 | async 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 | |||
458 | export function showReferences(ctx: Ctx): Cmd { | 470 | export 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 | ||
561 | export 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 | |||
557 | export function runSingle(ctx: Ctx): Cmd { | 591 | export 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; |
diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index 2de1e427d..52de29e04 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts | |||
@@ -72,6 +72,12 @@ export interface Runnable { | |||
72 | } | 72 | } |
73 | export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>("experimental/runnables"); | 73 | export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>("experimental/runnables"); |
74 | 74 | ||
75 | export interface TestInfo { | ||
76 | runnable: Runnable; | ||
77 | } | ||
78 | |||
79 | export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, TestInfo[], void>("rust-analyzer/relatedTests"); | ||
80 | |||
75 | export type InlayHint = InlayHint.TypeHint | InlayHint.ParamHint | InlayHint.ChainingHint; | 81 | export type InlayHint = InlayHint.TypeHint | InlayHint.ParamHint | InlayHint.ChainingHint; |
76 | 82 | ||
77 | export namespace InlayHint { | 83 | export namespace InlayHint { |
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 1be4f1758..925103f56 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -113,6 +113,7 @@ async function tryActivate(context: vscode.ExtensionContext) { | |||
113 | ctx.registerCommand('newDebugConfig', commands.newDebugConfig); | 113 | ctx.registerCommand('newDebugConfig', commands.newDebugConfig); |
114 | ctx.registerCommand('openDocs', commands.openDocs); | 114 | ctx.registerCommand('openDocs', commands.openDocs); |
115 | ctx.registerCommand('openCargoToml', commands.openCargoToml); | 115 | ctx.registerCommand('openCargoToml', commands.openCargoToml); |
116 | ctx.registerCommand('peekTests', commands.peekTests); | ||
116 | 117 | ||
117 | defaultOnEnter.dispose(); | 118 | defaultOnEnter.dispose(); |
118 | ctx.registerCommand('onEnter', commands.onEnter); | 119 | ctx.registerCommand('onEnter', commands.onEnter); |