mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-23 03:44:23 +00:00
Add "view file text" command to debug sync issues
This commit is contained in:
parent
259182b50b
commit
ec2d023383
8 changed files with 89 additions and 1 deletions
|
@ -432,6 +432,54 @@ export function viewHir(ctx: Ctx): Cmd {
|
|||
};
|
||||
}
|
||||
|
||||
export function viewFileText(ctx: Ctx): Cmd {
|
||||
const tdcp = new class implements vscode.TextDocumentContentProvider {
|
||||
readonly uri = vscode.Uri.parse('rust-analyzer://viewFileText/file.rs');
|
||||
readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>();
|
||||
constructor() {
|
||||
vscode.workspace.onDidChangeTextDocument(this.onDidChangeTextDocument, this, ctx.subscriptions);
|
||||
vscode.window.onDidChangeActiveTextEditor(this.onDidChangeActiveTextEditor, this, ctx.subscriptions);
|
||||
}
|
||||
|
||||
private onDidChangeTextDocument(event: vscode.TextDocumentChangeEvent) {
|
||||
if (isRustDocument(event.document)) {
|
||||
// We need to order this after language server updates, but there's no API for that.
|
||||
// Hence, good old sleep().
|
||||
void sleep(10).then(() => this.eventEmitter.fire(this.uri));
|
||||
}
|
||||
}
|
||||
private onDidChangeActiveTextEditor(editor: vscode.TextEditor | undefined) {
|
||||
if (editor && isRustEditor(editor)) {
|
||||
this.eventEmitter.fire(this.uri);
|
||||
}
|
||||
}
|
||||
|
||||
provideTextDocumentContent(_uri: vscode.Uri, ct: vscode.CancellationToken): vscode.ProviderResult<string> {
|
||||
const rustEditor = ctx.activeRustEditor;
|
||||
const client = ctx.client;
|
||||
if (!rustEditor || !client) return '';
|
||||
|
||||
const params = client.code2ProtocolConverter.asTextDocumentIdentifier(rustEditor.document);
|
||||
return client.sendRequest(ra.viewFileText, params, ct);
|
||||
}
|
||||
|
||||
get onDidChange(): vscode.Event<vscode.Uri> {
|
||||
return this.eventEmitter.event;
|
||||
}
|
||||
};
|
||||
|
||||
ctx.pushCleanup(vscode.workspace.registerTextDocumentContentProvider('rust-analyzer', tdcp));
|
||||
|
||||
return async () => {
|
||||
const document = await vscode.workspace.openTextDocument(tdcp.uri);
|
||||
tdcp.eventEmitter.fire(tdcp.uri);
|
||||
void await vscode.window.showTextDocument(document, {
|
||||
viewColumn: vscode.ViewColumn.Two,
|
||||
preserveFocus: true
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function viewItemTree(ctx: Ctx): Cmd {
|
||||
const tdcp = new class implements vscode.TextDocumentContentProvider {
|
||||
readonly uri = vscode.Uri.parse('rust-analyzer://viewItemTree/itemtree.rs');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue