diff options
Diffstat (limited to 'editors/code/src/commands')
-rw-r--r-- | editors/code/src/commands/expand_macro.ts | 45 | ||||
-rw-r--r-- | editors/code/src/commands/index.ts | 2 |
2 files changed, 47 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 | |||
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index c194bd2ea..2ade6d331 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import * as analyzerStatus from './analyzer_status'; | 1 | import * as analyzerStatus from './analyzer_status'; |
2 | import * as applySourceChange from './apply_source_change'; | 2 | import * as applySourceChange from './apply_source_change'; |
3 | import * as expandMacro from './expand_macro'; | ||
3 | import * as inlayHints from './inlay_hints'; | 4 | import * as inlayHints from './inlay_hints'; |
4 | import * as joinLines from './join_lines'; | 5 | import * as joinLines from './join_lines'; |
5 | import * as matchingBrace from './matching_brace'; | 6 | import * as matchingBrace from './matching_brace'; |
@@ -11,6 +12,7 @@ import * as syntaxTree from './syntaxTree'; | |||
11 | export { | 12 | export { |
12 | analyzerStatus, | 13 | analyzerStatus, |
13 | applySourceChange, | 14 | applySourceChange, |
15 | expandMacro, | ||
14 | joinLines, | 16 | joinLines, |
15 | matchingBrace, | 17 | matchingBrace, |
16 | parentModule, | 18 | parentModule, |