@@ -15,23 +15,26 @@ import { SyntaxTreeManager } from '../context/syntaxtree/SyntaxTreeManager';
1515import { NodeSearch } from '../context/syntaxtree/utils/NodeSearch' ;
1616import { NodeType } from '../context/syntaxtree/utils/NodeType' ;
1717import { DocumentManager } from '../document/DocumentManager' ;
18- import { ANALYZE_DIAGNOSTIC } from '../handlers/ExecutionHandler' ;
18+ import { ANALYZE_DIAGNOSTIC , TRACK_CODE_ACTION_ACCEPTED } from '../handlers/ExecutionHandler' ;
1919import { CfnInfraCore } from '../server/CfnInfraCore' ;
2020import { CFN_VALIDATION_SOURCE } from '../stacks/actions/ValidationWorkflow' ;
2121import { LoggerFactory } from '../telemetry/LoggerFactory' ;
22- import { Track } from '../telemetry/TelemetryDecorator' ;
22+ import { ScopedTelemetry } from '../telemetry/ScopedTelemetry' ;
23+ import { Telemetry , Track } from '../telemetry/TelemetryDecorator' ;
2324import { pointToPosition } from '../utils/TypeConverters' ;
2425import { ExtractToParameterProvider } from './extractToParameter/ExtractToParameterProvider' ;
2526
2627export interface CodeActionFix {
2728 title : string ;
2829 kind : string ;
30+ actionType : string ;
2931 diagnostic : Diagnostic ;
3032 textEdits : TextEdit [ ] ;
3133 command ?: Command ;
3234}
3335
3436export class CodeActionService {
37+ @Telemetry ( ) private readonly telemetry ! : ScopedTelemetry ;
3538 private static readonly REMOVE_ERROR_TITLE = 'Hide validation error' ;
3639 private readonly log = LoggerFactory . getLogger ( CodeActionService ) ;
3740
@@ -44,7 +47,9 @@ export class CodeActionService {
4447 private readonly documentManager : DocumentManager ,
4548 private readonly contextManager : ContextManager ,
4649 private readonly extractToParameterProvider ?: ExtractToParameterProvider ,
47- ) { }
50+ ) {
51+ this . initializeCounters ( ) ;
52+ }
4853
4954 /**
5055 * Process diagnostics and generate code actions with fixes
@@ -76,6 +81,13 @@ export class CodeActionService {
7681 return codeActions ;
7782 }
7883
84+ private initializeCounters ( ) : void {
85+ this . telemetry . count ( 'quickfix.cfnLintFixOffered' , 0 ) ;
86+ this . telemetry . count ( 'quickfix.clearDiagnosticOffered' , 0 ) ;
87+ this . telemetry . count ( 'refactor.extractToParameterOffered' , 0 ) ;
88+ this . telemetry . count ( 'refactor.extractAllToParameterOffered' , 0 ) ;
89+ }
90+
7991 /**
8092 * Generate fixes for a specific diagnostic
8193 */
@@ -112,10 +124,12 @@ export class CodeActionService {
112124 * Generate fixes for CFN Validation diagnostics
113125 */
114126 private generateCfnValidationFixes ( diagnostic : Diagnostic , uri : string ) : CodeActionFix [ ] {
127+ this . telemetry . count ( 'quickfix.clearDiagnosticOffered' , 1 )
115128 return [
116129 {
117130 title : CodeActionService . REMOVE_ERROR_TITLE ,
118131 kind : 'quickfix' ,
132+ actionType : 'clearDiagnostic' ,
119133 diagnostic,
120134 textEdits : [ ] ,
121135 command : {
@@ -165,6 +179,8 @@ export class CodeActionService {
165179 }
166180 }
167181
182+ this . telemetry . count ( 'quickfix.cfnLintFixOffered' , fixes . length ) ;
183+
168184 return fixes ;
169185 }
170186
@@ -182,6 +198,7 @@ export class CodeActionService {
182198 fixes . push ( {
183199 title : `Remove invalid property '${ propertyName } '` ,
184200 kind : 'quickfix' ,
201+ actionType : 'removeProperty' ,
185202 diagnostic,
186203 textEdits : [
187204 {
@@ -284,6 +301,7 @@ export class CodeActionService {
284301 fixes . push ( {
285302 title : `Add required property '${ propertyName } '` ,
286303 kind : 'quickfix' ,
304+ actionType : 'addRequiredProperty' ,
287305 diagnostic,
288306 textEdits : [
289307 {
@@ -324,6 +342,12 @@ export class CodeActionService {
324342
325343 if ( fix . command ) {
326344 codeAction . command = fix . command ;
345+ } else {
346+ codeAction . command = {
347+ title : 'Track code action' ,
348+ command : TRACK_CODE_ACTION_ACCEPTED ,
349+ arguments : [ fix . actionType ] ,
350+ } ;
327351 }
328352
329353 return codeAction ;
@@ -520,20 +544,27 @@ export class CodeActionService {
520544 const canExtract = this . extractToParameterProvider . canExtract ( context ) ;
521545
522546 if ( canExtract ) {
523- const extractAction = this . generateExtractToParameterAction ( params , context ) ;
547+ const extractAction = this . telemetry . measure ( 'refactor.extractToParameter' , ( ) =>
548+ this . generateExtractToParameterAction ( params , context )
549+ ) ;
550+
524551 if ( extractAction ) {
525552 refactorActions . push ( extractAction ) ;
553+ this . telemetry . count ( 'refactor.extractToParameterOffered' , 1 ) ;
526554 }
527555
528- const hasMultiple = this . extractToParameterProvider . hasMultipleOccurrences (
529- context ,
530- params . textDocument . uri ,
556+ const hasMultiple = this . telemetry . measure ( 'refactor.hasMultipleOccurrences' , ( ) =>
557+ this . extractToParameterProvider ! . hasMultipleOccurrences ( context , params . textDocument . uri )
531558 ) ;
532559
533560 if ( hasMultiple ) {
534- const extractAllAction = this . generateExtractAllOccurrencesToParameterAction ( params , context ) ;
561+ const extractAllAction = this . telemetry . measure ( 'refactor.extractAllToParameter' , ( ) =>
562+ this . generateExtractAllOccurrencesToParameterAction ( params , context )
563+ ) ;
564+
535565 if ( extractAllAction ) {
536566 refactorActions . push ( extractAllAction ) ;
567+ this . telemetry . count ( 'refactor.extractAllToParameterOffered' , 1 ) ;
537568 }
538569 }
539570 }
@@ -579,7 +610,13 @@ export class CodeActionService {
579610 command : {
580611 title : 'Position cursor in parameter description' ,
581612 command : 'aws.cloudformation.extractToParameter.positionCursor' ,
582- arguments : [ params . textDocument . uri , extractionResult . parameterName , context . documentType ] ,
613+ arguments : [
614+ params . textDocument . uri ,
615+ extractionResult . parameterName ,
616+ context . documentType ,
617+ TRACK_CODE_ACTION_ACCEPTED ,
618+ 'extractToParameter' ,
619+ ] ,
583620 } ,
584621 } ;
585622 } catch ( error ) {
@@ -625,7 +662,13 @@ export class CodeActionService {
625662 command : {
626663 title : 'Position cursor in parameter description' ,
627664 command : 'aws.cloudformation.extractToParameter.positionCursor' ,
628- arguments : [ params . textDocument . uri , extractionResult . parameterName , context . documentType ] ,
665+ arguments : [
666+ params . textDocument . uri ,
667+ extractionResult . parameterName ,
668+ context . documentType ,
669+ TRACK_CODE_ACTION_ACCEPTED ,
670+ 'extractAllToParameter' ,
671+ ] ,
629672 } ,
630673 } ;
631674 } catch ( error ) {
0 commit comments