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