blob: dcb721eee59863d5b52e29066802326b9fae28e3 (
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
|
import * as vscode from 'vscode';
import { TextDocumentIdentifier } from 'vscode-languageclient';
import { Server } from '../server';
export const syntaxTreeUri = vscode.Uri.parse('ra-lsp://syntaxtree');
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 ''; }
const request: SyntaxTreeParams = {
textDocument: { uri: editor.document.uri.toString() },
};
return Server.client.sendRequest<SyntaxTreeResult>('m/syntaxTree', request);
}
get onDidChange(): vscode.Event<vscode.Uri> {
return this.eventEmitter.event;
}
}
interface SyntaxTreeParams {
textDocument: TextDocumentIdentifier;
}
type SyntaxTreeResult = string;
// Opens the virtual file that will show the syntax tree
//
// The contents of the file come from the `TextDocumentContentProvider`
export async function handle() {
const document = await vscode.workspace.openTextDocument(syntaxTreeUri);
return vscode.window.showTextDocument(document, vscode.ViewColumn.Two, true);
}
|