aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/syntaxTree.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/commands/syntaxTree.ts')
-rw-r--r--editors/code/src/commands/syntaxTree.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/editors/code/src/commands/syntaxTree.ts b/editors/code/src/commands/syntaxTree.ts
new file mode 100644
index 000000000..dcb721eee
--- /dev/null
+++ b/editors/code/src/commands/syntaxTree.ts
@@ -0,0 +1,38 @@
1import * as vscode from 'vscode';
2import { TextDocumentIdentifier } from 'vscode-languageclient';
3
4import { Server } from '../server';
5
6export const syntaxTreeUri = vscode.Uri.parse('ra-lsp://syntaxtree');
7
8export class TextDocumentContentProvider implements vscode.TextDocumentContentProvider {
9 public eventEmitter = new vscode.EventEmitter<vscode.Uri>();
10 public syntaxTree: string = 'Not available';
11
12 public provideTextDocumentContent(uri: vscode.Uri): vscode.ProviderResult<string> {
13 const editor = vscode.window.activeTextEditor;
14 if (editor == null) { return ''; }
15 const request: SyntaxTreeParams = {
16 textDocument: { uri: editor.document.uri.toString() },
17 };
18 return Server.client.sendRequest<SyntaxTreeResult>('m/syntaxTree', request);
19 }
20
21 get onDidChange(): vscode.Event<vscode.Uri> {
22 return this.eventEmitter.event;
23 }
24}
25
26interface SyntaxTreeParams {
27 textDocument: TextDocumentIdentifier;
28}
29
30type SyntaxTreeResult = string;
31
32// Opens the virtual file that will show the syntax tree
33//
34// The contents of the file come from the `TextDocumentContentProvider`
35export async function handle() {
36 const document = await vscode.workspace.openTextDocument(syntaxTreeUri);
37 return vscode.window.showTextDocument(document, vscode.ViewColumn.Two, true);
38}