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

65 lines
1.8 KiB
TypeScript
Raw Normal View History

2019-01-23 00:15:03 +03:00
import * as vscode from 'vscode';
import { Server } from '../server';
2019-01-28 14:43:07 +03:00
const statusUri = vscode.Uri.parse('rust-analyzer-status://status');
2019-01-25 16:10:34 +03:00
export class TextDocumentContentProvider
implements vscode.TextDocumentContentProvider {
public eventEmitter = new vscode.EventEmitter<vscode.Uri>();
public syntaxTree: string = 'Not available';
public provideTextDocumentContent(
2019-12-09 20:57:55 +02:00
uri: vscode.Uri,
2019-01-25 16:10:34 +03:00
): vscode.ProviderResult<string> {
const editor = vscode.window.activeTextEditor;
if (editor == null) {
return '';
}
2019-01-28 14:43:07 +03:00
return Server.client.sendRequest<string>(
'rust-analyzer/analyzerStatus',
2019-12-09 20:57:55 +02:00
null,
2019-01-28 14:43:07 +03:00
);
2019-01-25 16:10:34 +03:00
}
get onDidChange(): vscode.Event<vscode.Uri> {
return this.eventEmitter.event;
}
}
let poller: NodeJS.Timer | null = null;
2019-01-23 00:15:03 +03:00
// Shows status of rust-analyzer (for debugging)
2019-01-25 16:10:34 +03:00
export function makeCommand(context: vscode.ExtensionContext) {
const textDocumentContentProvider = new TextDocumentContentProvider();
context.subscriptions.push(
vscode.workspace.registerTextDocumentContentProvider(
2019-01-28 14:43:07 +03:00
'rust-analyzer-status',
2019-12-09 20:57:55 +02:00
textDocumentContentProvider,
),
2019-01-23 00:15:03 +03:00
);
2019-01-25 16:10:34 +03:00
context.subscriptions.push({
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(
() => textDocumentContentProvider.eventEmitter.fire(statusUri),
2019-12-09 20:57:55 +02:00
1000,
2019-01-25 16:10:34 +03:00
);
}
const document = await vscode.workspace.openTextDocument(statusUri);
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
}