aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-03-26 09:49:12 +0000
committerGitHub <[email protected]>2020-03-26 09:49:12 +0000
commitece8fa81bbff7cad8da2e28fb810699ae4045a16 (patch)
tree88df49316a774d45ceeef7fad2cd41244cd866a2 /editors
parent1923f7571ef75867a5333aa9d4c637b6ea26e363 (diff)
parentd1721021ef6c5c2c361319c6ae06de7c330ea71e (diff)
Merge #3726
3726: vscode: refactor analyzer status r=matklad a=Veetaha Co-authored-by: veetaha <[email protected]>
Diffstat (limited to 'editors')
-rw-r--r--editors/code/src/commands/analyzer_status.ts31
1 files changed, 11 insertions, 20 deletions
diff --git a/editors/code/src/commands/analyzer_status.ts b/editors/code/src/commands/analyzer_status.ts
index 1c6ea399b..09daa3402 100644
--- a/editors/code/src/commands/analyzer_status.ts
+++ b/editors/code/src/commands/analyzer_status.ts
@@ -5,7 +5,7 @@ import { Ctx, Cmd } from '../ctx';
5 5
6// Shows status of rust-analyzer (for debugging) 6// Shows status of rust-analyzer (for debugging)
7export function analyzerStatus(ctx: Ctx): Cmd { 7export function analyzerStatus(ctx: Ctx): Cmd {
8 let poller: NodeJS.Timer | null = null; 8 let poller: NodeJS.Timer | undefined = undefined;
9 const tdcp = new TextDocumentContentProvider(ctx); 9 const tdcp = new TextDocumentContentProvider(ctx);
10 10
11 ctx.pushCleanup( 11 ctx.pushCleanup(
@@ -17,41 +17,32 @@ export function analyzerStatus(ctx: Ctx): Cmd {
17 17
18 ctx.pushCleanup({ 18 ctx.pushCleanup({
19 dispose() { 19 dispose() {
20 if (poller != null) { 20 if (poller !== undefined) {
21 clearInterval(poller); 21 clearInterval(poller);
22 } 22 }
23 }, 23 },
24 }); 24 });
25 25
26 return async function handle() { 26 return async () => {
27 if (poller == null) { 27 if (poller === undefined) {
28 poller = setInterval(() => tdcp.eventEmitter.fire(tdcp.uri), 1000); 28 poller = setInterval(() => tdcp.eventEmitter.fire(tdcp.uri), 1000);
29 } 29 }
30 const document = await vscode.workspace.openTextDocument(tdcp.uri); 30 const document = await vscode.workspace.openTextDocument(tdcp.uri);
31 return vscode.window.showTextDocument( 31 return vscode.window.showTextDocument(document, vscode.ViewColumn.Two, true);
32 document,
33 vscode.ViewColumn.Two,
34 true,
35 );
36 }; 32 };
37} 33}
38 34
39class TextDocumentContentProvider 35class TextDocumentContentProvider implements vscode.TextDocumentContentProvider {
40 implements vscode.TextDocumentContentProvider { 36 readonly uri = vscode.Uri.parse('rust-analyzer-status://status');
41 uri = vscode.Uri.parse('rust-analyzer-status://status'); 37 readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>();
42 eventEmitter = new vscode.EventEmitter<vscode.Uri>();
43 38
44 constructor(private readonly ctx: Ctx) { 39 constructor(private readonly ctx: Ctx) {
45 } 40 }
46 41
47 provideTextDocumentContent( 42 provideTextDocumentContent(_uri: vscode.Uri): vscode.ProviderResult<string> {
48 _uri: vscode.Uri, 43 if (!vscode.window.activeTextEditor) return '';
49 ): vscode.ProviderResult<string> {
50 const editor = vscode.window.activeTextEditor;
51 const client = this.ctx.client;
52 if (!editor || !client) return '';
53 44
54 return client.sendRequest(ra.analyzerStatus, null); 45 return this.ctx.client.sendRequest(ra.analyzerStatus, null);
55 } 46 }
56 47
57 get onDidChange(): vscode.Event<vscode.Uri> { 48 get onDidChange(): vscode.Event<vscode.Uri> {