@@ -82,7 +82,7 @@ class TextDocumentContentProvider implements vscode.TextDocumentContentProvider
8282
8383// FIXME: consider implementing this via the Tree View API?
8484// https://code.visualstudio.com/api/extension-guides/tree-view
85- class AstInspector implements vscode . HoverProvider , Disposable {
85+ class AstInspector implements vscode . HoverProvider , vscode . DefinitionProvider , Disposable {
8686 private readonly astDecorationType = vscode . window . createTextEditorDecorationType ( {
8787 borderColor : new vscode . ThemeColor ( 'rust_analyzer.syntaxTreeBorder' ) ,
8888 borderStyle : "solid" ,
@@ -96,8 +96,7 @@ class AstInspector implements vscode.HoverProvider, Disposable {
9696 const astEditor = this . findAstTextEditor ( ) ;
9797 if ( ! this . rustEditor || ! astEditor ) return undefined ;
9898
99- console . time ( "Build goto def index" ) ;
100- let buf : [ vscode . Range , vscode . Range ] [ ] = [ ] ;
99+ const buf : [ vscode . Range , vscode . Range ] [ ] = [ ] ;
101100 for ( let i = 0 ; i < astEditor . document . lineCount ; ++ i ) {
102101 const astLine = astEditor . document . lineAt ( i ) ;
103102
@@ -108,10 +107,8 @@ class AstInspector implements vscode.HoverProvider, Disposable {
108107 const rustRange = this . parseRustTextRange ( this . rustEditor . document , astLine . text ) ;
109108 if ( ! rustRange ) continue ;
110109
111- buf . push ( [ rustRange , this . findAstRange ( astLine ) ] ) ;
110+ buf . push ( [ rustRange , this . findAstNodeRange ( astLine ) ] ) ;
112111 }
113-
114- console . timeEnd ( "Build goto def index" ) ;
115112 return buf ;
116113 } ) ;
117114
@@ -167,9 +164,7 @@ class AstInspector implements vscode.HoverProvider, Disposable {
167164 const astEditor = this . findAstTextEditor ( ) ;
168165 if ( ! astEditor ) return ;
169166
170- console . time ( "Goto def" ) ;
171167 const rust2AstRanges = this . rust2Ast . get ( ) ?. find ( ( [ rustRange , _ ] ) => rustRange . contains ( pos ) ) ;
172- console . timeEnd ( "Goto def" ) ;
173168 if ( ! rust2AstRanges ) return ;
174169
175170 const [ rustFileRange , astFileRange ] = rust2AstRanges ;
@@ -198,12 +193,12 @@ class AstInspector implements vscode.HoverProvider, Disposable {
198193 this . rustEditor . revealRange ( rustFileRange ) ;
199194
200195 const rustSourceCode = this . rustEditor . document . getText ( rustFileRange ) ;
201- const astFileRange = this . findAstRange ( astFileLine ) ;
196+ const astFileRange = this . findAstNodeRange ( astFileLine ) ;
202197
203198 return new vscode . Hover ( [ "```rust\n" + rustSourceCode + "\n```" ] , astFileRange ) ;
204199 }
205200
206- private findAstRange ( astLine : vscode . TextLine ) {
201+ private findAstNodeRange ( astLine : vscode . TextLine ) {
207202 const lineOffset = astLine . range . start ;
208203 const begin = lineOffset . translate ( undefined , astLine . firstNonWhitespaceCharacterIndex ) ;
209204 const end = lineOffset . translate ( undefined , astLine . text . trimEnd ( ) . length ) ;
@@ -223,7 +218,7 @@ class AstInspector implements vscode.HoverProvider, Disposable {
223218class Lazy < T > {
224219 val : undefined | T ;
225220
226- constructor ( private readonly compute : ( ) => undefined | T ) { }
221+ constructor ( private readonly compute : ( ) => undefined | T ) { }
227222
228223 get ( ) {
229224 return this . val ?? ( this . val = this . compute ( ) ) ;
@@ -232,5 +227,4 @@ class Lazy<T> {
232227 reset ( ) {
233228 this . val = undefined ;
234229 }
235-
236230}
0 commit comments