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