aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/analyzer_status.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/commands/analyzer_status.ts')
-rw-r--r--editors/code/src/commands/analyzer_status.ts61
1 files changed, 55 insertions, 6 deletions
diff --git a/editors/code/src/commands/analyzer_status.ts b/editors/code/src/commands/analyzer_status.ts
index 5c56b9c4c..bb46a1990 100644
--- a/editors/code/src/commands/analyzer_status.ts
+++ b/editors/code/src/commands/analyzer_status.ts
@@ -1,12 +1,61 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import { Server } from '../server'; 2import { Server } from '../server';
3 3
4const statusUri = vscode.Uri.parse('ra-lsp-status://status');
5
6export class TextDocumentContentProvider
7 implements vscode.TextDocumentContentProvider {
8 public eventEmitter = new vscode.EventEmitter<vscode.Uri>();
9 public syntaxTree: string = 'Not available';
10
11 public provideTextDocumentContent(
12 uri: vscode.Uri
13 ): vscode.ProviderResult<string> {
14 const editor = vscode.window.activeTextEditor;
15 if (editor == null) {
16 return '';
17 }
18 return Server.client.sendRequest<string>('ra/analyzerStatus', null);
19 }
20
21 get onDidChange(): vscode.Event<vscode.Uri> {
22 return this.eventEmitter.event;
23 }
24}
25
26let poller: NodeJS.Timer | null = null;
27
4// Shows status of rust-analyzer (for debugging) 28// Shows status of rust-analyzer (for debugging)
5export async function handle() { 29
6 const status = await Server.client.sendRequest<string>( 30export function makeCommand(context: vscode.ExtensionContext) {
7 'ra/analyzerStatus', 31 const textDocumentContentProvider = new TextDocumentContentProvider();
8 null 32 context.subscriptions.push(
33 vscode.workspace.registerTextDocumentContentProvider(
34 'ra-lsp-status',
35 textDocumentContentProvider
36 )
9 ); 37 );
10 const doc = await vscode.workspace.openTextDocument({ content: status }); 38
11 await vscode.window.showTextDocument(doc, vscode.ViewColumn.Two); 39 context.subscriptions.push({
40 dispose() {
41 if (poller != null) {
42 clearInterval(poller);
43 }
44 }
45 });
46
47 return async function handle() {
48 if (poller == null) {
49 poller = setInterval(
50 () => textDocumentContentProvider.eventEmitter.fire(statusUri),
51 1000
52 );
53 }
54 const document = await vscode.workspace.openTextDocument(statusUri);
55 return vscode.window.showTextDocument(
56 document,
57 vscode.ViewColumn.Two,
58 true
59 );
60 };
12} 61}