diff options
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/src/commands/expand_macro.ts | 45 | ||||
-rw-r--r-- | editors/code/src/commands/index.ts | 2 | ||||
-rw-r--r-- | editors/code/src/extension.ts | 20 |
3 files changed, 62 insertions, 5 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, |
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index c06928d12..1dfa6046f 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts | |||
@@ -3,6 +3,7 @@ import * as lc from 'vscode-languageclient'; | |||
3 | 3 | ||
4 | import * as commands from './commands'; | 4 | import * as commands from './commands'; |
5 | import { CargoWatchProvider } from './commands/cargo_watch'; | 5 | import { CargoWatchProvider } from './commands/cargo_watch'; |
6 | import { ExpandMacroHoverProvider } from './commands/expand_macro' | ||
6 | import { HintsUpdater } from './commands/inlay_hints'; | 7 | import { HintsUpdater } from './commands/inlay_hints'; |
7 | import { | 8 | import { |
8 | interactivelyStartCargoWatch, | 9 | interactivelyStartCargoWatch, |
@@ -91,11 +92,11 @@ export function activate(context: vscode.ExtensionContext) { | |||
91 | const allNotifications: Iterable< | 92 | const allNotifications: Iterable< |
92 | [string, lc.GenericNotificationHandler] | 93 | [string, lc.GenericNotificationHandler] |
93 | > = [ | 94 | > = [ |
94 | [ | 95 | [ |
95 | 'rust-analyzer/publishDecorations', | 96 | 'rust-analyzer/publishDecorations', |
96 | notifications.publishDecorations.handle | 97 | notifications.publishDecorations.handle |
97 | ] | 98 | ] |
98 | ]; | 99 | ]; |
99 | const syntaxTreeContentProvider = new SyntaxTreeContentProvider(); | 100 | const syntaxTreeContentProvider = new SyntaxTreeContentProvider(); |
100 | 101 | ||
101 | // The events below are plain old javascript events, triggered and handled by vscode | 102 | // The events below are plain old javascript events, triggered and handled by vscode |
@@ -121,6 +122,15 @@ export function activate(context: vscode.ExtensionContext) { | |||
121 | context.subscriptions | 122 | context.subscriptions |
122 | ); | 123 | ); |
123 | 124 | ||
125 | const expandMacroContentProvider = new ExpandMacroHoverProvider(); | ||
126 | |||
127 | disposeOnDeactivation( | ||
128 | vscode.languages.registerHoverProvider( | ||
129 | 'rust', | ||
130 | expandMacroContentProvider | ||
131 | ) | ||
132 | ); | ||
133 | |||
124 | const startServer = () => Server.start(allNotifications); | 134 | const startServer = () => Server.start(allNotifications); |
125 | const reloadCommand = () => reloadServer(startServer); | 135 | const reloadCommand = () => reloadServer(startServer); |
126 | 136 | ||