Skip to content

Commit eb75e98

Browse files
authored
Todo Enhanced (#56)
* Todo enhancement * restore gitignore * Add comment variable to expectation class * Remove log.debug
1 parent 93406d3 commit eb75e98

File tree

3 files changed

+54
-36
lines changed

3 files changed

+54
-36
lines changed

tst/e2e/autocomplete/Autocomplete.test.ts

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -311,19 +311,20 @@ Conditions:
311311
position: { line: 103, character: 25 },
312312
expectation: CompletionExpectationBuilder.create()
313313
.expectContainsItems(['AWS::Region'])
314-
.todo()
315-
// todo: intrinsic functions are being suggested incorrectly!
316-
//[
317-
// "!RefAll",
318-
// "!GetAZs",
319-
// "!Ref",
320-
// "!Equals",
321-
// "!Base64",
322-
// "!GetAtt",
323-
// "!Transform",
324-
// "!EachMemberEquals",
325-
// "!EachMemberIn",
326-
// ]
314+
.todo(
315+
`intrinsic functions are being suggested incorrectly!
316+
[
317+
"!RefAll",
318+
"!GetAZs",
319+
"!Ref",
320+
"!Equals",
321+
"!Base64",
322+
"!GetAtt",
323+
"!Transform",
324+
"!EachMemberEquals",
325+
"!EachMemberIn",
326+
]`,
327+
)
327328
.build(),
328329
},
329330
},
@@ -393,7 +394,7 @@ Rules:
393394
position: { line: 114, character: 45 },
394395
expectation: CompletionExpectationBuilder.create()
395396
.expectContainsItems(['AWS::Region'])
396-
.todo() // todo: no suggestion of pseudo-parameter after AWS:: is typed; needs the R
397+
.todo(`no suggestion of pseudo-parameter after AWS:: is typed; needs the R`)
397398
.build(),
398399
},
399400
},
@@ -406,9 +407,10 @@ Rules:
406407
position: { line: 114, character: 54 },
407408
expectation: CompletionExpectationBuilder.create()
408409
.expectContainsItems(['InstanceType'])
409-
// todo: second level of Mapping not being suggested when using !Ref for first level key
410-
// works using 'us-east-1'
411-
.todo()
410+
.todo(
411+
`second level of Mapping not being suggested when using !Ref for first level key
412+
works using 'us-east-1'`,
413+
)
412414
.build(),
413415
},
414416
},
@@ -864,7 +866,7 @@ Resources:
864866
'VPC',
865867
])
866868
.expectExcludesItems(['AutoScalingGroup'])
867-
.todo() // todo: support autocomplete for Fn::GetAtt
869+
.todo(`support autocomplete for Fn::GetAtt`)
868870
.build(),
869871
},
870872
},
@@ -982,7 +984,7 @@ Resources:
982984
'IsProductionOrStaging',
983985
])
984986
.expectExcludesItems(['ComplexCondition', 'HasMultipleAZs'])
985-
.todo() // todo: not working even when testing not on last line of YAML
987+
.todo(`not working even when testing not on last line of YAML`)
986988
.build(),
987989
},
988990
},
@@ -1002,10 +1004,11 @@ Resources:
10021004
position: { line: 286, character: 40 },
10031005
expectation: CompletionExpectationBuilder.create()
10041006
.expectContainsItems(['Snapshot'])
1005-
// todo: feature to suggest Resource attribute values
1006-
// some values (Snapshot) are based on resource type; see docs below
1007-
// https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-attribute-deletionpolicy.html#aws-attribute-deletionpolicy-options
1008-
.todo()
1007+
.todo(
1008+
`feature to suggest Resource attribute values
1009+
some values (Snapshot) are based on resource type; see docs below
1010+
https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-attribute-deletionpolicy.html#aws-attribute-deletionpolicy-options`,
1011+
)
10091012
.build(),
10101013
},
10111014
},
@@ -1381,9 +1384,13 @@ O`,
13811384
description: 'suggest Mapping second level key in deeply nested intrinsic function',
13821385
verification: {
13831386
position: { line: 471, character: 61 },
1384-
// todo: fix bug in FindInMap completion where using intrinsic in second arg breaks
1385-
// suggestion for third arg
1386-
expectation: CompletionExpectationBuilder.create().expectItems(['AMI']).todo().build(),
1387+
expectation: CompletionExpectationBuilder.create()
1388+
.expectItems(['AMI'])
1389+
.todo(
1390+
`fix bug in FindInMap completion where using intrinsic in second arg breaks
1391+
suggestion for third arg`,
1392+
)
1393+
.build(),
13871394
},
13881395
},
13891396
{
@@ -1400,8 +1407,12 @@ O`,
14001407
description: 'suggest substitution variable in second arg of Fn::Sub based on first arg',
14011408
verification: {
14021409
position: { line: 474, character: 14 },
1403-
// todo: feature to suggest variables authored in Fn::Sub first arg while typing second arg
1404-
expectation: CompletionExpectationBuilder.create().expectItems(['Third']).todo().build(),
1410+
expectation: CompletionExpectationBuilder.create()
1411+
.expectItems(['Third'])
1412+
.todo(
1413+
`feature to suggest variables authored in Fn::Sub first arg while typing second arg`,
1414+
)
1415+
.build(),
14051416
},
14061417
},
14071418
],

tst/e2e/hover/Hover.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,8 @@ Conditions:`,
506506
verification: {
507507
position: { line: 101, character: 25 },
508508
expectation: HoverExpectationBuilder.create()
509-
//todo: hover on condition name reference for !Condition and not just Condition:
510509
.expectContainsText(['**Condition**, IsProductionOrStaging'])
511-
.todo()
510+
.todo(`hover on condition name reference for !Condition and not just Condition:`)
512511
.build(),
513512
},
514513
},
@@ -1088,7 +1087,7 @@ Resources:`,
10881087
expectation: HoverExpectationBuilder.create()
10891088
.expectStartsWith('**Resource:** LaunchTemplate')
10901089
.expectContainsText(['LaunchTemplate', 'AWS::EC2::LaunchTemplate'])
1091-
.todo()
1090+
.todo(`Returns nothing`)
10921091
.build(),
10931092
},
10941093
},
@@ -1116,7 +1115,7 @@ Resources:`,
11161115
expectation: HoverExpectationBuilder.create()
11171116
.expectStartsWith('**Condition:** HasMultipleAZs')
11181117
.expectContainsText(['HasMultipleAZs', '!Not', '!Equals', '!Select'])
1119-
.todo()
1118+
.todo(`Returns nothing`)
11201119
.build(),
11211120
},
11221121
},

tst/utils/TemplateBuilder.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function expectAt(actual: any, position: Position, description?: string) {
3333

3434
class Expectation {
3535
public todo: boolean = false;
36+
public todoComment?: string;
3637
}
3738

3839
class ContextExpectation extends Expectation {
@@ -151,7 +152,11 @@ export class TemplateBuilder {
151152
}
152153

153154
if (step.verification?.expectation?.todo === true && exception === undefined) {
154-
throw new Error(`TODO did not throw exception${step.description ? ` - ${step.description}` : ''}`);
155+
const todoComment = step.verification.expectation.todoComment;
156+
const commentSuffix = todoComment ? ` - TODO: ${todoComment}` : '';
157+
throw new Error(
158+
`TODO did not throw exception${step.description ? ` - ${step.description}` : ''}${commentSuffix}`,
159+
);
155160
} else if (step.verification?.expectation?.todo === false && exception !== undefined) {
156161
throw new Error(`${extractErrorMessage(exception)}${step.description ? ` - ${step.description}` : ''}`);
157162
}
@@ -769,8 +774,9 @@ export class ContextExpectationBuilder {
769774
return this;
770775
}
771776

772-
todo(): ContextExpectationBuilder {
777+
todo(comment: string): ContextExpectationBuilder {
773778
this.expectation.todo = true;
779+
this.expectation.todoComment = comment;
774780
return this;
775781
}
776782

@@ -837,8 +843,9 @@ export class HoverExpectationBuilder {
837843
return this;
838844
}
839845

840-
todo(): HoverExpectationBuilder {
846+
todo(comment: string): HoverExpectationBuilder {
841847
this.expectation.todo = true;
848+
this.expectation.todoComment = comment;
842849
return this;
843850
}
844851

@@ -889,8 +896,9 @@ export class CompletionExpectationBuilder {
889896
return this;
890897
}
891898

892-
todo(): CompletionExpectationBuilder {
899+
todo(comment: string): CompletionExpectationBuilder {
893900
this.expectation.todo = true;
901+
this.expectation.todoComment = comment;
894902
return this;
895903
}
896904

0 commit comments

Comments
 (0)