@@ -76,6 +76,17 @@ class CodelensProvider implements vscode.CodeLensProvider<vscode.CodeLens>
7676
7777 }
7878
79+ private async getRuntimeDataExistsLens ( methodInfo : MethodInfo ) :Promise < vscode . CodeLens > {
80+ return new vscode . CodeLens ( methodInfo . range , {
81+ title : "Runtime data" ,
82+ tooltip : "Click to see this function's runtime data" ,
83+ command : CodelensProvider . clickCommand ,
84+ arguments : [ methodInfo , this . _state . environment ]
85+
86+
87+ } ) ;
88+ }
89+
7990
8091 private async getCodeLens ( methodInfo : MethodInfo ,
8192 codeObjectInfo :CodeObjectLocationInfo ,
@@ -177,48 +188,50 @@ class CodelensProvider implements vscode.CodeLensProvider<vscode.CodeLens>
177188 public async provideCodeLenses ( document : vscode . TextDocument , token : vscode . CancellationToken ) : Promise < vscode . CodeLens [ ] >
178189 {
179190 if ( ! Settings . enableCodeLens . value )
180- return [ ] ;
191+ { return [ ] ; }
181192
182193 const documentInfo = await this . _documentInfoProvider . getDocumentInfo ( document ) ;
183194 if ( ! documentInfo )
184- return [ ] ;
195+ { return [ ] ; }
185196
186197 const codelens : vscode . CodeLens [ ] = [ ] ;
187198 for ( let methodInfo of documentInfo . methods )
188199 {
200+ const methodCodeLens : vscode . CodeLens [ ] = [ ] ;
201+
189202 for ( let alias of methodInfo . ids ) {
190- const insights = documentInfo . insights . all . filter ( x => x . codeObjectId == alias )
191- . filter ( x => x . scope == "Function" ) ;
203+ const insights = documentInfo . insights . all
204+ . filter ( x => x . codeObjectId == alias ) ;
192205
193- const thisEnvInsights = insights . filter ( x => x . environment == this . _state . environment ) ;
206+ const thisEnvInsights = insights
207+ . filter ( x => x . environment == this . _state . environment ) ;
194208
195- const lenses = await this . getCodeLens ( methodInfo , methodInfo , thisEnvInsights , documentInfo . usageData . getAll ( ) , false ) ;
209+ const lenses = await this . getCodeLens ( methodInfo , methodInfo ,
210+ thisEnvInsights . filter ( x => x . scope == "Function" ) ,
211+ documentInfo . usageData . getAll ( ) , false ) ;
212+
196213 for ( const lens of lenses ) {
197- codelens . push ( lens ) ;
214+ methodCodeLens . push ( lens ) ;
198215 }
199216
200- if ( lenses . length === 0 && thisEnvInsights . length > 0 ) {
201- codelens . push ( new vscode . CodeLens ( methodInfo . range , {
202- title : "Runtime data" ,
203- tooltip : "Click to see this function's runtime data" ,
204- command : CodelensProvider . clickCommand ,
205- arguments : [ methodInfo , this . _state . environment ]
206- } ) ) ;
207-
208-
217+ if ( methodCodeLens . length === 0 && thisEnvInsights . length > 0 ) {
218+ methodCodeLens . push ( await this . getRuntimeDataExistsLens ( methodInfo ) ) ;
209219 }
210220
211221 }
212222
213223 let spans = documentInfo . spans . filter ( e => e . range . intersection ( methodInfo . range ) != undefined ) ;
214- let duplicates = spans . filter ( x => documentInfo . spans . any ( span => span != x && span . name == x . name && span . range != x . range ) ) ;
224+ let duplicates = spans
225+ . filter ( x => documentInfo . spans
226+ . any ( span => span != x && span . name == x . name && span . range != x . range ) ) ;
227+
215228 spans = spans . filter ( span => ! duplicates . includes ( span ) ) ;
216229
217230 if ( duplicates . length > 0 ) {
218231 const lenses = await this . getDuplicateSpanLens ( methodInfo , duplicates ) ;
219232
220233 for ( const lens of lenses ) {
221- codelens . push ( lens ) ;
234+ methodCodeLens . push ( lens ) ;
222235 }
223236
224237 }
@@ -227,8 +240,8 @@ class CodelensProvider implements vscode.CodeLensProvider<vscode.CodeLens>
227240 spans , documentInfo . usageData . getAll ( ) , documentInfo . insights . all . filter ( x => x . scope == "Span" ) ) ;
228241
229242 for ( const lens of lenses ) {
230- codelens . push ( lens ) ;
231- }
243+ methodCodeLens . push ( lens ) ;
244+ }
232245
233246 }
234247
@@ -240,11 +253,8 @@ class CodelensProvider implements vscode.CodeLensProvider<vscode.CodeLens>
240253 uniqueEndpoints , documentInfo . usageData . getAll ( ) , documentInfo . insights . all . filter ( x => x . scope == "EntrySpan" || x . scope == "Span" ) ,
241254 ) ;
242255
243- const uniqueLenses = [ ...new Map ( lenses . map ( item =>
244- [ item . command ! . title , item ] ) ) . values ( ) ] ;
245-
246- for ( const lens of uniqueLenses ) {
247- codelens . push ( lens ) ;
256+ for ( const lens of lenses ) {
257+ methodCodeLens . push ( lens ) ;
248258 }
249259
250260
@@ -263,10 +273,16 @@ class CodelensProvider implements vscode.CodeLensProvider<vscode.CodeLens>
263273 const otherEnvLenses = await this . getCodeLens ( methodInfo , methodInfo , otherEnvsInsights ,
264274 documentInfo . usageData . getAll ( ) , true ) ;
265275 for ( const lens of otherEnvLenses ) {
266- codelens . push ( lens ) ;
276+ methodCodeLens . push ( lens ) ;
267277 }
268278
269279 }
280+
281+ const uniqueLenses = [ ...new Map ( methodCodeLens . map ( item =>
282+ [ item . command ! . title , item ] ) ) . values ( ) ] ;
283+
284+
285+ codelens . push ( ...uniqueLenses ) ;
270286
271287 }
272288
0 commit comments