diff options
author | Edwin Cheng <[email protected]> | 2019-11-17 18:47:50 +0000 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2019-11-19 13:49:06 +0000 |
commit | 3ccd05fedc46796f793295901a8619492256468e (patch) | |
tree | 018f46fca85c4d2e0ef4b73fa3971166e65de3e2 /editors/code/src/commands/expand_macro.ts | |
parent | d2782ab1c1ec0b9f2ac2131859a9ee880f97bc12 (diff) |
Add recursive expand in vscode
Diffstat (limited to 'editors/code/src/commands/expand_macro.ts')
-rw-r--r-- | editors/code/src/commands/expand_macro.ts | 45 |
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 @@ | |||
1 | import * as vscode from 'vscode'; | ||
2 | import { Position, TextDocumentIdentifier } from 'vscode-languageclient'; | ||
3 | import { Server } from '../server'; | ||
4 | |||
5 | type ExpandMacroResult = [string, string] | ||
6 | |||
7 | function 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 | |||
13 | export 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 | |||
41 | interface MacroExpandParams { | ||
42 | textDocument: TextDocumentIdentifier; | ||
43 | position: Position; | ||
44 | } | ||
45 | |||