Files
rust/editors/code/src/commands/analyzer_status.ts

69 lines
1.7 KiB
TypeScript
Raw Normal View History

2019-01-23 00:15:03 +03:00
import * as vscode from 'vscode';
2019-12-30 14:42:59 +01:00
import { Ctx } from '../ctx';
2019-01-23 00:15:03 +03:00
// Shows status of rust-analyzer (for debugging)
2019-01-25 16:10:34 +03:00
2019-12-30 14:42:59 +01:00
export function analyzerStatus(ctx: Ctx) {
2019-12-30 12:25:55 +01:00
let poller: NodeJS.Timer | null = null;
2019-12-30 14:42:59 +01:00
const tdcp = new TextDocumentContentProvider(ctx);
2019-12-30 12:25:55 +01:00
2019-12-30 14:42:59 +01:00
ctx.pushCleanup(
2019-01-25 16:10:34 +03:00
vscode.workspace.registerTextDocumentContentProvider(
2019-01-28 14:43:07 +03:00
'rust-analyzer-status',
2019-12-30 12:25:55 +01:00
tdcp,
2019-12-09 20:57:55 +02:00
),
2019-01-23 00:15:03 +03:00
);
2019-01-25 16:10:34 +03:00
2019-12-30 14:42:59 +01:00
ctx.pushCleanup({
2019-01-25 16:10:34 +03:00
dispose() {
if (poller != null) {
clearInterval(poller);
}
2019-12-09 20:57:55 +02:00
},
2019-01-25 16:10:34 +03:00
});
return async function handle() {
if (poller == null) {
poller = setInterval(
2019-12-30 12:25:55 +01:00
() => tdcp.eventEmitter.fire(tdcp.uri),
2019-12-09 20:57:55 +02:00
1000,
2019-01-25 16:10:34 +03:00
);
}
2019-12-30 12:25:55 +01:00
const document = await vscode.workspace.openTextDocument(tdcp.uri);
2019-01-25 16:10:34 +03:00
return vscode.window.showTextDocument(
document,
vscode.ViewColumn.Two,
2019-12-09 20:57:55 +02:00
true,
2019-01-25 16:10:34 +03:00
);
};
2019-01-23 00:15:03 +03:00
}
2019-12-30 12:25:55 +01:00
class TextDocumentContentProvider
implements vscode.TextDocumentContentProvider {
2019-12-30 14:42:59 +01:00
2019-12-30 12:25:55 +01:00
uri = vscode.Uri.parse('rust-analyzer-status://status');
eventEmitter = new vscode.EventEmitter<vscode.Uri>();
2019-12-30 14:42:59 +01:00
ctx: Ctx
constructor(ctx: Ctx) {
this.ctx = ctx
}
2019-12-30 12:25:55 +01:00
provideTextDocumentContent(
_uri: vscode.Uri,
): vscode.ProviderResult<string> {
const editor = vscode.window.activeTextEditor;
if (editor == null) {
return '';
}
2019-12-30 14:42:59 +01:00
return this.ctx.client.sendRequest<string>(
2019-12-30 12:25:55 +01:00
'rust-analyzer/analyzerStatus',
null,
);
}
get onDidChange(): vscode.Event<vscode.Uri> {
return this.eventEmitter.event;
}
}