mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
vscode: refactor analyzer status
This commit is contained in:
parent
eff1b3fe4d
commit
d1721021ef
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)
|
// Shows status of rust-analyzer (for debugging)
|
||||||
export function analyzerStatus(ctx: Ctx): Cmd {
|
export function analyzerStatus(ctx: Ctx): Cmd {
|
||||||
let poller: NodeJS.Timer | null = null;
|
let poller: NodeJS.Timer | undefined = undefined;
|
||||||
const tdcp = new TextDocumentContentProvider(ctx);
|
const tdcp = new TextDocumentContentProvider(ctx);
|
||||||
|
|
||||||
ctx.pushCleanup(
|
ctx.pushCleanup(
|
||||||
|
@ -17,41 +17,32 @@ export function analyzerStatus(ctx: Ctx): Cmd {
|
||||||
|
|
||||||
ctx.pushCleanup({
|
ctx.pushCleanup({
|
||||||
dispose() {
|
dispose() {
|
||||||
if (poller != null) {
|
if (poller !== undefined) {
|
||||||
clearInterval(poller);
|
clearInterval(poller);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return async function handle() {
|
return async () => {
|
||||||
if (poller == null) {
|
if (poller === undefined) {
|
||||||
poller = setInterval(() => tdcp.eventEmitter.fire(tdcp.uri), 1000);
|
poller = setInterval(() => tdcp.eventEmitter.fire(tdcp.uri), 1000);
|
||||||
}
|
}
|
||||||
const document = await vscode.workspace.openTextDocument(tdcp.uri);
|
const document = await vscode.workspace.openTextDocument(tdcp.uri);
|
||||||
return vscode.window.showTextDocument(
|
return vscode.window.showTextDocument(document, vscode.ViewColumn.Two, true);
|
||||||
document,
|
|
||||||
vscode.ViewColumn.Two,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class TextDocumentContentProvider
|
class TextDocumentContentProvider implements vscode.TextDocumentContentProvider {
|
||||||
implements vscode.TextDocumentContentProvider {
|
readonly uri = vscode.Uri.parse('rust-analyzer-status://status');
|
||||||
uri = vscode.Uri.parse('rust-analyzer-status://status');
|
readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>();
|
||||||
eventEmitter = new vscode.EventEmitter<vscode.Uri>();
|
|
||||||
|
|
||||||
constructor(private readonly ctx: Ctx) {
|
constructor(private readonly ctx: Ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
provideTextDocumentContent(
|
provideTextDocumentContent(_uri: vscode.Uri): vscode.ProviderResult<string> {
|
||||||
_uri: vscode.Uri,
|
if (!vscode.window.activeTextEditor) return '';
|
||||||
): vscode.ProviderResult<string> {
|
|
||||||
const editor = vscode.window.activeTextEditor;
|
|
||||||
const client = this.ctx.client;
|
|
||||||
if (!editor || !client) return '';
|
|
||||||
|
|
||||||
return client.sendRequest(ra.analyzerStatus, null);
|
return this.ctx.client.sendRequest(ra.analyzerStatus, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
get onDidChange(): vscode.Event<vscode.Uri> {
|
get onDidChange(): vscode.Event<vscode.Uri> {
|
||||||
|
|
Loading…
Reference in a new issue