7799: Related tests r=matklad a=vsrs

![tests](https://user-images.githubusercontent.com/62505555/109397453-a9013680-7947-11eb-8b11-ac03079f7645.gif)
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:
bors[bot] 2021-03-13 13:50:35 +00:00 committed by GitHub
commit 7accf6bc37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 471 additions and 28 deletions

View file

@ -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;