aboutsummaryrefslogtreecommitdiff
path: root/editors/code
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-25 13:17:20 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-25 13:17:20 +0000
commitaaadc4311ac623a75323611aad5579797616cc02 (patch)
tree07aa4db38ba212ab1e2af1b791c409e5407ac53b /editors/code
parent021e691997efc35c983808ee3470a060a3ec3e96 (diff)
parent8d68b76ba01dcd190e037e4d61a94d4c9d568bdd (diff)
Merge #640
640: better stats r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/src/commands/analyzer_status.ts61
-rw-r--r--editors/code/src/extension.ts5
2 files changed, 59 insertions, 7 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}
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) {
45 } 45 }
46 46
47 // Commands are requests from vscode to the language server 47 // Commands are requests from vscode to the language server
48 registerCommand('ra-lsp.analyzerStatus', commands.analyzerStatus.handle); 48 registerCommand(
49 'ra-lsp.analyzerStatus',
50 commands.analyzerStatus.makeCommand(context)
51 );
49 registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle); 52 registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle);
50 registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle); 53 registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle);
51 registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle); 54 registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle);