mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 13:18:47 +00:00
Merge #3726
3726: vscode: refactor analyzer status r=matklad a=Veetaha Co-authored-by: veetaha <veetaha2@gmail.com>
This commit is contained in:
commit
ece8fa81bb
1 changed files with 11 additions and 20 deletions
|
@ -5,7 +5,7 @@ import { Ctx, Cmd } from '../ctx';
|
|||
|
||||
// Shows status of rust-analyzer (for debugging)
|
||||
export function analyzerStatus(ctx: Ctx): Cmd {
|
||||
let poller: NodeJS.Timer | null = null;
|
||||
let poller: NodeJS.Timer | undefined = undefined;
|
||||
const tdcp = new TextDocumentContentProvider(ctx);
|
||||
|
||||
ctx.pushCleanup(
|
||||
|
@ -17,41 +17,32 @@ export function analyzerStatus(ctx: Ctx): Cmd {
|
|||
|
||||
ctx.pushCleanup({
|
||||
dispose() {
|
||||
if (poller != null) {
|
||||
if (poller !== undefined) {
|
||||
clearInterval(poller);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return async function handle() {
|
||||
if (poller == null) {
|
||||
return async () => {
|
||||
if (poller === undefined) {
|
||||
poller = setInterval(() => tdcp.eventEmitter.fire(tdcp.uri), 1000);
|
||||
}
|
||||
const document = await vscode.workspace.openTextDocument(tdcp.uri);
|
||||
return vscode.window.showTextDocument(
|
||||
document,
|
||||
vscode.ViewColumn.Two,
|
||||
true,
|
||||
);
|
||||
return vscode.window.showTextDocument(document, vscode.ViewColumn.Two, true);
|
||||
};
|
||||
}
|
||||
|
||||
class TextDocumentContentProvider
|
||||
implements vscode.TextDocumentContentProvider {
|
||||
uri = vscode.Uri.parse('rust-analyzer-status://status');
|
||||
eventEmitter = new vscode.EventEmitter<vscode.Uri>();
|
||||
class TextDocumentContentProvider implements vscode.TextDocumentContentProvider {
|
||||
readonly uri = vscode.Uri.parse('rust-analyzer-status://status');
|
||||
readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>();
|
||||
|
||||
constructor(private readonly ctx: Ctx) {
|
||||
}
|
||||
|
||||
provideTextDocumentContent(
|
||||
_uri: vscode.Uri,
|
||||
): vscode.ProviderResult<string> {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
const client = this.ctx.client;
|
||||
if (!editor || !client) return '';
|
||||
provideTextDocumentContent(_uri: vscode.Uri): vscode.ProviderResult<string> {
|
||||
if (!vscode.window.activeTextEditor) return '';
|
||||
|
||||
return client.sendRequest(ra.analyzerStatus, null);
|
||||
return this.ctx.client.sendRequest(ra.analyzerStatus, null);
|
||||
}
|
||||
|
||||
get onDidChange(): vscode.Event<vscode.Uri> {
|
||||
|
|
Loading…
Reference in a new issue