Skip to content

Commit

Permalink
feat: rust-analyzer.peekTests
Browse files Browse the repository at this point in the history
FYI #256
  • Loading branch information
fannheyward committed Mar 15, 2021
1 parent a149b3a commit c00285d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ You can use these commands by `:CocCommand XYZ`.
- `rust-analyzer.toggleInlayHints`: Toggle inlay hints on/off
- `rust-analyzer.explainError`: Explain the currently hovered error message
- `rust-analyzer.viewHir`: View Hir
- `rust-analyzer.peekTests`: Peek related tests
- `rust-analyzer.upgrade`: Download latest `rust-analyzer` from [GitHub release](https://github.com/rust-analyzer/rust-analyzer/releases)

## Highlight Group
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,11 @@
"title": "Echo Run Command Line",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.peekTests",
"title": "Peek related tests",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.explainError",
"title": "Explain the currently hovered diagnostic",
Expand Down
14 changes: 14 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,17 @@ export function echoRunCommandLine(ctx: Ctx) {
window.showMessage(commandLine);
};
}

export function peekTests(ctx: Ctx): Cmd {
return async () => {
const { document, position } = await workspace.getCurrentState();
if (!isRustDocument(document)) return;

const tests = await ctx.client.sendRequest(ra.relatedTests, {
textDocument: { uri: document.uri },
position,
});
const locations: Location[] = tests.map((it) => Location.create(it.runnable.location!.targetUri, it.runnable.location!.targetSelectionRange));
await commands.executeCommand('editor.action.showReferences', Uri.parse(document.uri), position, locations);
};
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
ctx.registerCommand('viewHir', cmds.viewHir);
ctx.registerCommand('openDocs', cmds.openDocs);
ctx.registerCommand('joinLines', cmds.joinLines);
ctx.registerCommand('peekTests', cmds.peekTests);
ctx.registerCommand('syntaxTree', cmds.syntaxTree);
ctx.registerCommand('memoryUsage', cmds.memoryUsage);
ctx.registerCommand('expandMacro', cmds.expandMacro);
Expand Down
6 changes: 6 additions & 0 deletions src/lsp_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ export interface Runnable {
}
export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>('experimental/runnables');

export interface TestInfo {
runnable: Runnable;
}

export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, TestInfo[], void>('rust-analyzer/relatedTests');

export type InlayHint = InlayHint.TypeHint | InlayHint.ParamHint | InlayHint.ChainingHint;

export namespace InlayHint {
Expand Down

0 comments on commit c00285d

Please sign in to comment.