11import * as vscode from 'vscode' ;
2- import * as lc from 'vscode-languageclient ' ;
2+ import * as ra from '../rust-analyzer-api ' ;
33
44import { Ctx , Cmd } from '../ctx' ;
55
@@ -61,13 +61,8 @@ function afterLs(f: () => void) {
6161 setTimeout ( f , 10 ) ;
6262}
6363
64- interface SyntaxTreeParams {
65- textDocument : lc . TextDocumentIdentifier ;
66- range ?: lc . Range ;
67- }
6864
69- class TextDocumentContentProvider
70- implements vscode . TextDocumentContentProvider {
65+ class TextDocumentContentProvider implements vscode . TextDocumentContentProvider {
7166 uri = vscode . Uri . parse ( 'rust-analyzer://syntaxtree' ) ;
7267 eventEmitter = new vscode . EventEmitter < vscode . Uri > ( ) ;
7368
@@ -79,23 +74,15 @@ class TextDocumentContentProvider
7974 const client = this . ctx . client ;
8075 if ( ! editor || ! client ) return '' ;
8176
82- let range : lc . Range | undefined ;
83-
8477 // When the range based query is enabled we take the range of the selection
85- if ( uri . query === 'range=true' ) {
86- range = editor . selection . isEmpty
87- ? undefined
88- : client . code2ProtocolConverter . asRange ( editor . selection ) ;
89- }
78+ const range = uri . query === 'range=true' && ! editor . selection . isEmpty
79+ ? client . code2ProtocolConverter . asRange ( editor . selection )
80+ : null ;
9081
91- const request : SyntaxTreeParams = {
82+ return client . sendRequest ( ra . syntaxTree , {
9283 textDocument : { uri : editor . document . uri . toString ( ) } ,
9384 range,
94- } ;
95- return client . sendRequest < string > (
96- 'rust-analyzer/syntaxTree' ,
97- request ,
98- ) ;
85+ } ) ;
9986 }
10087
10188 get onDidChange ( ) : vscode . Event < vscode . Uri > {
0 commit comments