From 8d68b76ba01dcd190e037e4d61a94d4c9d568bdd Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Jan 2019 16:10:34 +0300 Subject: better stats --- editors/code/src/commands/analyzer_status.ts | 61 +++++++++++++++++++++++++--- editors/code/src/extension.ts | 5 ++- 2 files changed, 59 insertions(+), 7 deletions(-) (limited to 'editors') 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 @@ import * as vscode from 'vscode'; import { Server } from '../server'; +const statusUri = vscode.Uri.parse('ra-lsp-status://status'); + +export class TextDocumentContentProvider + implements vscode.TextDocumentContentProvider { + public eventEmitter = new vscode.EventEmitter(); + public syntaxTree: string = 'Not available'; + + public provideTextDocumentContent( + uri: vscode.Uri + ): vscode.ProviderResult { + const editor = vscode.window.activeTextEditor; + if (editor == null) { + return ''; + } + return Server.client.sendRequest('ra/analyzerStatus', null); + } + + get onDidChange(): vscode.Event { + return this.eventEmitter.event; + } +} + +let poller: NodeJS.Timer | null = null; + // Shows status of rust-analyzer (for debugging) -export async function handle() { - const status = await Server.client.sendRequest( - 'ra/analyzerStatus', - null + +export function makeCommand(context: vscode.ExtensionContext) { + const textDocumentContentProvider = new TextDocumentContentProvider(); + context.subscriptions.push( + vscode.workspace.registerTextDocumentContentProvider( + 'ra-lsp-status', + textDocumentContentProvider + ) ); - const doc = await vscode.workspace.openTextDocument({ content: status }); - await vscode.window.showTextDocument(doc, vscode.ViewColumn.Two); + + context.subscriptions.push({ + dispose() { + if (poller != null) { + clearInterval(poller); + } + } + }); + + return async function handle() { + if (poller == null) { + poller = setInterval( + () => textDocumentContentProvider.eventEmitter.fire(statusUri), + 1000 + ); + } + const document = await vscode.workspace.openTextDocument(statusUri); + return vscode.window.showTextDocument( + document, + vscode.ViewColumn.Two, + true + ); + }; } diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index 288a852aa..3af95c599 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts @@ -45,7 +45,10 @@ export function activate(context: vscode.ExtensionContext) { } // Commands are requests from vscode to the language server - registerCommand('ra-lsp.analyzerStatus', commands.analyzerStatus.handle); + registerCommand( + 'ra-lsp.analyzerStatus', + commands.analyzerStatus.makeCommand(context) + ); registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle); registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle); registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle); -- cgit v1.2.3