mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Merge #7799
7799: Related tests r=matklad a=vsrs  This adds an ability to look for tests for the item under the cursor: function, constant, data type, etc The LSP part is bound to change. But the feature itself already works and I'm looking for a feedback :) Co-authored-by: vsrs <vit@conrlab.com>
This commit is contained in:
commit
7accf6bc37
13 changed files with 471 additions and 28 deletions
|
@ -9,6 +9,7 @@ import { RunnableQuickPick, selectRunnable, createTask, createArgs } from './run
|
|||
import { AstInspector } from './ast_inspector';
|
||||
import { isRustDocument, sleep, isRustEditor } from './util';
|
||||
import { startDebugSession, makeDebugConfig } from './debug';
|
||||
import { LanguageClient } from 'vscode-languageclient/node';
|
||||
|
||||
export * from './ast_inspector';
|
||||
export * from './run';
|
||||
|
@ -455,17 +456,20 @@ export function reloadWorkspace(ctx: Ctx): Cmd {
|
|||
return async () => ctx.client.sendRequest(ra.reloadWorkspace);
|
||||
}
|
||||
|
||||
async function showReferencesImpl(client: LanguageClient, uri: string, position: lc.Position, locations: lc.Location[]) {
|
||||
if (client) {
|
||||
await vscode.commands.executeCommand(
|
||||
'editor.action.showReferences',
|
||||
vscode.Uri.parse(uri),
|
||||
client.protocol2CodeConverter.asPosition(position),
|
||||
locations.map(client.protocol2CodeConverter.asLocation),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function showReferences(ctx: Ctx): Cmd {
|
||||
return async (uri: string, position: lc.Position, locations: lc.Location[]) => {
|
||||
const client = ctx.client;
|
||||
if (client) {
|
||||
await vscode.commands.executeCommand(
|
||||
'editor.action.showReferences',
|
||||
vscode.Uri.parse(uri),
|
||||
client.protocol2CodeConverter.asPosition(position),
|
||||
locations.map(client.protocol2CodeConverter.asLocation),
|
||||
);
|
||||
}
|
||||
await showReferencesImpl(ctx.client, uri, position, locations);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -554,6 +558,36 @@ export function run(ctx: Ctx): Cmd {
|
|||
};
|
||||
}
|
||||
|
||||
export function peekTests(ctx: Ctx): Cmd {
|
||||
const client = ctx.client;
|
||||
|
||||
return async () => {
|
||||
const editor = ctx.activeRustEditor;
|
||||
if (!editor || !client) return;
|
||||
|
||||
await vscode.window.withProgress({
|
||||
location: vscode.ProgressLocation.Notification,
|
||||
title: "Looking for tests...",
|
||||
cancellable: false,
|
||||
}, async (_progress, _token) => {
|
||||
const uri = editor.document.uri.toString();
|
||||
const position = client.code2ProtocolConverter.asPosition(
|
||||
editor.selection.active,
|
||||
);
|
||||
|
||||
const tests = await client.sendRequest(ra.relatedTests, {
|
||||
textDocument: { uri: uri },
|
||||
position: position,
|
||||
});
|
||||
const locations: lc.Location[] = tests.map(it =>
|
||||
lc.Location.create(it.runnable.location!.targetUri, it.runnable.location!.targetSelectionRange));
|
||||
|
||||
await showReferencesImpl(client, uri, position, locations);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function runSingle(ctx: Ctx): Cmd {
|
||||
return async (runnable: ra.Runnable) => {
|
||||
const editor = ctx.activeRustEditor;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue