aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/syntax_tree.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/commands/syntax_tree.ts')
-rw-r--r--editors/code/src/commands/syntax_tree.ts27
1 files changed, 7 insertions, 20 deletions
diff --git a/editors/code/src/commands/syntax_tree.ts b/editors/code/src/commands/syntax_tree.ts
index 2887c96c8..7218bfb90 100644
--- a/editors/code/src/commands/syntax_tree.ts
+++ b/editors/code/src/commands/syntax_tree.ts
@@ -1,5 +1,5 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 2import * as ra from '../rust-analyzer-api';
3 3
4import { Ctx, Cmd } from '../ctx'; 4import { Ctx, Cmd } from '../ctx';
5 5
@@ -61,13 +61,8 @@ function afterLs(f: () => void) {
61 setTimeout(f, 10); 61 setTimeout(f, 10);
62} 62}
63 63
64interface SyntaxTreeParams {
65 textDocument: lc.TextDocumentIdentifier;
66 range?: lc.Range;
67}
68 64
69class TextDocumentContentProvider 65class TextDocumentContentProvider implements vscode.TextDocumentContentProvider {
70 implements vscode.TextDocumentContentProvider {
71 uri = vscode.Uri.parse('rust-analyzer://syntaxtree'); 66 uri = vscode.Uri.parse('rust-analyzer://syntaxtree');
72 eventEmitter = new vscode.EventEmitter<vscode.Uri>(); 67 eventEmitter = new vscode.EventEmitter<vscode.Uri>();
73 68
@@ -79,23 +74,15 @@ class TextDocumentContentProvider
79 const client = this.ctx.client; 74 const client = this.ctx.client;
80 if (!editor || !client) return ''; 75 if (!editor || !client) return '';
81 76
82 let range: lc.Range | undefined;
83
84 // When the range based query is enabled we take the range of the selection 77 // When the range based query is enabled we take the range of the selection
85 if (uri.query === 'range=true') { 78 const range = uri.query === 'range=true' && !editor.selection.isEmpty
86 range = editor.selection.isEmpty 79 ? client.code2ProtocolConverter.asRange(editor.selection)
87 ? undefined 80 : null;
88 : client.code2ProtocolConverter.asRange(editor.selection);
89 }
90 81
91 const request: SyntaxTreeParams = { 82 return client.sendRequest(ra.syntaxTree, {
92 textDocument: { uri: editor.document.uri.toString() }, 83 textDocument: { uri: editor.document.uri.toString() },
93 range, 84 range,
94 }; 85 });
95 return client.sendRequest<string>(
96 'rust-analyzer/syntaxTree',
97 request,
98 );
99 } 86 }
100 87
101 get onDidChange(): vscode.Event<vscode.Uri> { 88 get onDidChange(): vscode.Event<vscode.Uri> {