aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-11-17 18:47:50 +0000
committerEdwin Cheng <[email protected]>2019-11-19 13:49:06 +0000
commit3ccd05fedc46796f793295901a8619492256468e (patch)
tree018f46fca85c4d2e0ef4b73fa3971166e65de3e2 /editors/code/src/commands
parentd2782ab1c1ec0b9f2ac2131859a9ee880f97bc12 (diff)
Add recursive expand in vscode
Diffstat (limited to 'editors/code/src/commands')
-rw-r--r--editors/code/src/commands/expand_macro.ts45
-rw-r--r--editors/code/src/commands/index.ts2
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 @@
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
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 @@
1import * as analyzerStatus from './analyzer_status'; 1import * as analyzerStatus from './analyzer_status';
2import * as applySourceChange from './apply_source_change'; 2import * as applySourceChange from './apply_source_change';
3import * as expandMacro from './expand_macro';
3import * as inlayHints from './inlay_hints'; 4import * as inlayHints from './inlay_hints';
4import * as joinLines from './join_lines'; 5import * as joinLines from './join_lines';
5import * as matchingBrace from './matching_brace'; 6import * as matchingBrace from './matching_brace';
@@ -11,6 +12,7 @@ import * as syntaxTree from './syntaxTree';
11export { 12export {
12 analyzerStatus, 13 analyzerStatus,
13 applySourceChange, 14 applySourceChange,
15 expandMacro,
14 joinLines, 16 joinLines,
15 matchingBrace, 17 matchingBrace,
16 parentModule, 18 parentModule,