Add View Mir command and fix some bugs

This commit is contained in:
hkalbasi 2023-02-26 16:04:41 +03:30
parent a25710b0c0
commit ac04bfd7a7
23 changed files with 876 additions and 122 deletions

View file

@ -405,12 +405,11 @@ export function syntaxTree(ctx: CtxInit): Cmd {
};
}
// Opens the virtual file that will show the HIR of the function containing the cursor position
//
// The contents of the file come from the `TextDocumentContentProvider`
export function viewHir(ctx: CtxInit): Cmd {
function viewHirOrMir(ctx: CtxInit, xir: "hir" | "mir"): Cmd {
const viewXir = xir === "hir" ? "viewHir" : "viewMir";
const requestType = xir === "hir" ? ra.viewHir : ra.viewMir;
const tdcp = new (class implements vscode.TextDocumentContentProvider {
readonly uri = vscode.Uri.parse("rust-analyzer-hir://viewHir/hir.rs");
readonly uri = vscode.Uri.parse(`rust-analyzer-${xir}://${viewXir}/${xir}.rs`);
readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>();
constructor() {
vscode.workspace.onDidChangeTextDocument(
@ -452,7 +451,7 @@ export function viewHir(ctx: CtxInit): Cmd {
),
position: client.code2ProtocolConverter.asPosition(rustEditor.selection.active),
};
return client.sendRequest(ra.viewHir, params, ct);
return client.sendRequest(requestType, params, ct);
}
get onDidChange(): vscode.Event<vscode.Uri> {
@ -461,7 +460,7 @@ export function viewHir(ctx: CtxInit): Cmd {
})();
ctx.pushExtCleanup(
vscode.workspace.registerTextDocumentContentProvider("rust-analyzer-hir", tdcp)
vscode.workspace.registerTextDocumentContentProvider(`rust-analyzer-${xir}`, tdcp)
);
return async () => {
@ -474,6 +473,20 @@ export function viewHir(ctx: CtxInit): Cmd {
};
}
// Opens the virtual file that will show the HIR of the function containing the cursor position
//
// The contents of the file come from the `TextDocumentContentProvider`
export function viewHir(ctx: CtxInit): Cmd {
return viewHirOrMir(ctx, "hir");
}
// Opens the virtual file that will show the MIR of the function containing the cursor position
//
// The contents of the file come from the `TextDocumentContentProvider`
export function viewMir(ctx: CtxInit): Cmd {
return viewHirOrMir(ctx, "mir");
}
export function viewFileText(ctx: CtxInit): Cmd {
const tdcp = new (class implements vscode.TextDocumentContentProvider {
readonly uri = vscode.Uri.parse("rust-analyzer-file-text://viewFileText/file.rs");