aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/expand_macro.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/commands/expand_macro.ts')
-rw-r--r--editors/code/src/commands/expand_macro.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/editors/code/src/commands/expand_macro.ts b/editors/code/src/commands/expand_macro.ts
new file mode 100644
index 000000000..bf1923190
--- /dev/null
+++ b/editors/code/src/commands/expand_macro.ts
@@ -0,0 +1,45 @@
1import * as vscode from 'vscode';
2import { Position, TextDocumentIdentifier } from 'vscode-languageclient';
3import { Server } from '../server';
4
5type ExpandMacroResult = [string, string]
6
7function code_format([name, text]: [string, string]): vscode.MarkdownString {
8 const markdown = new vscode.MarkdownString(`#### Recursive expansion of ${name}! macro`);
9 markdown.appendCodeblock(text, 'rust');
10 return markdown;
11}
12
13export class ExpandMacroHoverProvider implements vscode.HoverProvider {
14 public provideHover(
15 document: vscode.TextDocument,
16 position: vscode.Position,
17 token: vscode.CancellationToken,
18 ): Thenable<vscode.Hover | null> | null {
19 async function handle() {
20 const request: MacroExpandParams = {
21 textDocument: { uri: document.uri.toString() },
22 position,
23 };
24 const result = await Server.client.sendRequest<ExpandMacroResult>(
25 'rust-analyzer/expandMacro',
26 request
27 );
28 if (result != null) {
29 const formated = code_format(result);
30 return new vscode.Hover(formated);
31 }
32
33 return null;
34 };
35
36 return handle();
37 }
38}
39
40
41interface MacroExpandParams {
42 textDocument: TextDocumentIdentifier;
43 position: Position;
44}
45