mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Add recursive expand in vscode
This commit is contained in:
parent
d2782ab1c1
commit
3ccd05fedc
8 changed files with 210 additions and 5 deletions
45
editors/code/src/commands/expand_macro.ts
Normal file
45
editors/code/src/commands/expand_macro.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import * as vscode from 'vscode';
|
||||
import { Position, TextDocumentIdentifier } from 'vscode-languageclient';
|
||||
import { Server } from '../server';
|
||||
|
||||
type ExpandMacroResult = [string, string]
|
||||
|
||||
function code_format([name, text]: [string, string]): vscode.MarkdownString {
|
||||
const markdown = new vscode.MarkdownString(`#### Recursive expansion of ${name}! macro`);
|
||||
markdown.appendCodeblock(text, '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<ExpandMacroResult>(
|
||||
'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;
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import * as analyzerStatus from './analyzer_status';
|
||||
import * as applySourceChange from './apply_source_change';
|
||||
import * as expandMacro from './expand_macro';
|
||||
import * as inlayHints from './inlay_hints';
|
||||
import * as joinLines from './join_lines';
|
||||
import * as matchingBrace from './matching_brace';
|
||||
|
@ -11,6 +12,7 @@ import * as syntaxTree from './syntaxTree';
|
|||
export {
|
||||
analyzerStatus,
|
||||
applySourceChange,
|
||||
expandMacro,
|
||||
joinLines,
|
||||
matchingBrace,
|
||||
parentModule,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue