blob: 3fc3e0391725f7a321e8464206ab3827fde3b059 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
import * as vscode from 'vscode';
import { Position, TextDocumentIdentifier } from 'vscode-languageclient';
import { Server } from '../server';
interface ExpandedMacro {
name: string,
expansion: string,
}
function code_format(expanded: ExpandedMacro): vscode.MarkdownString {
const markdown = new vscode.MarkdownString(
`#### Recursive expansion of ${expanded.name}! macro`
);
markdown.appendCodeblock(expanded.expansion, 'rust');
return markdown;
}
export class ExpandMacroHoverProvider implements vscode.HoverProvider {
public provideHover(
document: vscode.TextDocument,
position: vscode.Position,
token: vscode.CancellationToken
): Thenable<vscode.Hover | null> | null {
async function handle() {
const request: MacroExpandParams = {
textDocument: { uri: document.uri.toString() },
position
};
const result = await Server.client.sendRequest<ExpandedMacro>(
'rust-analyzer/expandMacro',
request
);
if (result != null) {
const formated = code_format(result);
return new vscode.Hover(formated);
}
return null;
}
return handle();
}
}
interface MacroExpandParams {
textDocument: TextDocumentIdentifier;
position: Position;
}
|