blob: bb46a1990e0666a27a1b68f9f6480596d05a0913 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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<vscode.Uri>();
public syntaxTree: string = 'Not available';
public provideTextDocumentContent(
uri: vscode.Uri
): vscode.ProviderResult<string> {
const editor = vscode.window.activeTextEditor;
if (editor == null) {
return '';
}
return Server.client.sendRequest<string>('ra/analyzerStatus', null);
}
get onDidChange(): vscode.Event<vscode.Uri> {
return this.eventEmitter.event;
}
}
let poller: NodeJS.Timer | null = null;
// Shows status of rust-analyzer (for debugging)
export function makeCommand(context: vscode.ExtensionContext) {
const textDocumentContentProvider = new TextDocumentContentProvider();
context.subscriptions.push(
vscode.workspace.registerTextDocumentContentProvider(
'ra-lsp-status',
textDocumentContentProvider
)
);
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
);
};
}
|