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

64 lines
1.6 KiB
TypeScript
Raw Normal View History

2019-01-23 00:15:03 +03:00
import * as vscode from 'vscode';
2019-12-30 19:07:28 +01:00
2019-12-30 14:53:43 +01:00
import { Ctx, Cmd } 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:53:43 +01:00
export function analyzerStatus(ctx: Ctx): Cmd {
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) {
2019-12-30 18:31:08 +01:00
poller = setInterval(() => tdcp.eventEmitter.fire(tdcp.uri), 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 18:31:08 +01:00
ctx: Ctx;
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
constructor(ctx: Ctx) {
2019-12-30 18:31:08 +01:00
this.ctx = ctx;
2019-12-30 14:42:59 +01:00
}
2019-12-30 12:25:55 +01:00
provideTextDocumentContent(
_uri: vscode.Uri,
): vscode.ProviderResult<string> {
const editor = vscode.window.activeTextEditor;
2019-12-30 16:43:34 +01:00
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;
}
}