@@ -2,7 +2,8 @@ import { setInterval, clearInterval } from 'timers';
22import * as vscode from 'vscode' ;
33import { AnalyticsProvider , CodeObjectSummary , MethodCodeObjectSummary } from './analyticsProvider' ;
44import { Logger } from "./logger" ;
5- import { SymbolProvider , Token , TokenType } from './languages/symbolProvider' ;
5+ import { SymbolProvider } from './languages/symbolProvider' ;
6+ import { Token , TokenType } from './languages/tokens' ;
67import { Dictionary , Future } from './utils' ;
78import { EndpointInfo , SpanInfo , SymbolInfo , CodeObjectInfo } from './languages/extractors' ;
89import { InstrumentationInfo } from './EditorHelper' ;
@@ -84,33 +85,38 @@ export class DocumentInfoProvider implements vscode.Disposable
8485 private async addOrUpdateDocumentInfo ( doc : vscode . TextDocument ) : Promise < DocumentInfo | undefined >
8586 {
8687 const docRelativePath = doc . uri . toModulePath ( ) ;
87- if ( ! docRelativePath || ! this . symbolProvider . supportsDocument ( doc ) )
88+ if ( ! docRelativePath || ! this . symbolProvider . supportsDocument ( doc ) ) {
8889 return undefined ;
90+ }
8991
9092 let document = this . _documents [ docRelativePath ] ;
91- if ( ! document )
92- {
93+ if ( ! document ) {
9394 document = this . _documents [ docRelativePath ] = new DocumentInfoContainer ( ) ;
9495 }
9596
9697 let latestVersionInfo = document . versions [ doc . version ] ;
97- if ( ! latestVersionInfo )
98- {
98+ if ( ! latestVersionInfo ) {
9999 latestVersionInfo = document . versions [ doc . version ] = new Future < DocumentInfo > ( ) ;
100100
101- try
102- {
101+ try {
103102 Logger . trace ( `Starting building DocumentInfo for "${ docRelativePath } " v${ doc . version } ` ) ;
104- const symbolInfos = await this . symbolProvider . getMethods ( doc ) ;
103+ const symbolTrees = await this . symbolProvider . getSymbolTree ( doc ) ;
104+ const symbolInfos = await this . symbolProvider . getMethods ( doc , symbolTrees ) ;
105105 const tokens = await this . symbolProvider . getTokens ( doc ) ;
106- const endpoints = await this . symbolProvider . getEndpoints ( doc , symbolInfos , tokens ) ;
106+ const endpoints = await this . symbolProvider . getEndpoints ( doc , symbolInfos , tokens , symbolTrees , this ) ;
107107 const spans = await this . symbolProvider . getSpans ( doc , symbolInfos , tokens ) ;
108- const methods = this . createMethodInfos ( doc , symbolInfos , tokens , spans , endpoints ) ;
109- const summaries = new CodeObjectSummeryAccessor ( await this . analyticsProvider . getSummaries ( methods . map ( s => s . idWithType ) . concat ( endpoints . map ( e => e . idWithType ) ) . concat ( spans . map ( s => s . idWithType ) ) ) ) ;
110- const lines = this . createLineInfos ( doc , summaries , methods ) ;
108+ const methodInfos = this . createMethodInfos ( doc , symbolInfos , tokens , spans , endpoints ) ;
109+ const summaries = new CodeObjectSummaryAccessor (
110+ await this . analyticsProvider . getSummaries (
111+ methodInfos . map ( s => s . idWithType )
112+ . concat ( endpoints . map ( e => e . idWithType ) )
113+ . concat ( spans . map ( s => s . idWithType ) )
114+ )
115+ ) ;
116+ const lines = this . createLineInfos ( doc , summaries , methodInfos ) ;
111117 latestVersionInfo . value = {
112118 summaries,
113- methods,
119+ methods : methodInfos ,
114120 lines,
115121 tokens,
116122 endpoints,
@@ -119,10 +125,9 @@ export class DocumentInfoProvider implements vscode.Disposable
119125 } ;
120126 Logger . trace ( `Finished building DocumentInfo for "${ docRelativePath } " v${ doc . version } ` ) ;
121127 }
122- catch ( e )
123- {
128+ catch ( e ) {
124129 latestVersionInfo . value = {
125- summaries : new CodeObjectSummeryAccessor ( [ ] ) ,
130+ summaries : new CodeObjectSummaryAccessor ( [ ] ) ,
126131 methods : [ ] ,
127132 lines : [ ] ,
128133 tokens : [ ] ,
@@ -136,19 +141,21 @@ export class DocumentInfoProvider implements vscode.Disposable
136141
137142 return latestVersionInfo . value ;
138143 }
139- else
140- {
144+ else {
141145 return await latestVersionInfo . wait ( ) ;
142146 }
143147 }
144148
145- private createMethodInfos ( document : vscode . TextDocument , symbols : SymbolInfo [ ] , tokens : Token [ ] ,
146- spans : SpanInfo [ ] , endpoints : EndpointInfo [ ] ) : MethodInfo [ ]
147- {
149+ private createMethodInfos (
150+ document : vscode . TextDocument ,
151+ symbols : SymbolInfo [ ] ,
152+ tokens : Token [ ] ,
153+ spans : SpanInfo [ ] ,
154+ endpoints : EndpointInfo [ ] ,
155+ ) : MethodInfo [ ] {
148156 let methods : MethodInfo [ ] = [ ] ;
149157
150- for ( let symbol of symbols )
151- {
158+ for ( let symbol of symbols ) {
152159 const method = new MethodInfo (
153160 symbol . id ,
154161 symbol . name ,
@@ -164,22 +171,22 @@ export class DocumentInfoProvider implements vscode.Disposable
164171 methods . push ( method ) ;
165172
166173 const methodTokens = tokens . filter ( t => symbol . range . contains ( t . range . start ) ) ;
167- for ( let token of methodTokens )
168- {
174+ for ( let token of methodTokens ) {
169175 const name = token . text ; // document.getText(token.range);
170176
171- if ( ( token . type === TokenType . method || token . type == TokenType . function )
172- && ! method . nameRange
173- && name === symbol . name )
174- {
177+ if (
178+ ( token . type === TokenType . method || token . type === TokenType . function || token . type === TokenType . member )
179+ && ! method . nameRange
180+ && name === symbol . name
181+ ) {
175182 method . nameRange = token . range ;
176183 }
177184
178- if ( token . type == TokenType . parameter )
179- {
180- if ( method . parameters . any ( p => p . name == name ) )
185+ if ( token . type === TokenType . parameter ) {
186+ if ( method . parameters . any ( p => p . name === name ) ) {
181187 continue ;
182-
188+ }
189+
183190 method . parameters . push ( { name, range : token . range , token } ) ;
184191 }
185192 }
@@ -188,7 +195,7 @@ export class DocumentInfoProvider implements vscode.Disposable
188195 return methods ;
189196 }
190197
191- public createLineInfos ( document : vscode . TextDocument , codeObjectSummaries : CodeObjectSummeryAccessor , methods : MethodInfo [ ] ) : LineInfo [ ]
198+ public createLineInfos ( document : vscode . TextDocument , codeObjectSummaries : CodeObjectSummaryAccessor , methods : MethodInfo [ ] ) : LineInfo [ ]
192199 {
193200 const lineInfos : LineInfo [ ] = [ ] ;
194201 for ( let method of methods )
@@ -258,15 +265,15 @@ class DocumentInfoContainer
258265
259266export interface DocumentInfo
260267{
261- summaries : CodeObjectSummeryAccessor ;
268+ summaries : CodeObjectSummaryAccessor ;
262269 methods : MethodInfo [ ] ;
263270 lines : LineInfo [ ] ;
264271 tokens : Token [ ] ;
265272 endpoints : EndpointInfo [ ] ;
266273 spans : SpanInfo [ ] ;
267274 uri : vscode . Uri ;
268275}
269- export class CodeObjectSummeryAccessor {
276+ export class CodeObjectSummaryAccessor {
270277 constructor ( private _codeObejctSummeries : CodeObjectSummary [ ] ) { }
271278
272279 public get < T extends CodeObjectSummary > ( type : { new ( ) : T ; } , codeObjectId : string ) : T | undefined
0 commit comments