@@ -151,7 +151,7 @@ export let findCodeActionsInDiagnosticsMessage = ({
151
151
diagnosticMessage . forEach ( ( line , index , array ) => {
152
152
// Because of how actions work, there can only be one per diagnostic. So,
153
153
// halt whenever a code action has been found.
154
- let codeActionEtractors = [
154
+ let codeActionExtractors = [
155
155
simpleTypeMismatches ,
156
156
didYouMeanAction ,
157
157
addUndefinedRecordFieldsV10 ,
@@ -162,7 +162,7 @@ export let findCodeActionsInDiagnosticsMessage = ({
162
162
wrapInSome ,
163
163
] ;
164
164
165
- for ( let extractCodeAction of codeActionEtractors ) {
165
+ for ( let extractCodeAction of codeActionExtractors ) {
166
166
let didFindAction = false ;
167
167
168
168
try {
@@ -319,12 +319,14 @@ let handleUndefinedRecordFieldsAction = ({
319
319
file,
320
320
range,
321
321
diagnostic,
322
+ todoValue
322
323
} : {
323
324
recordFieldNames : string [ ] ;
324
325
codeActions : filesCodeActions ;
325
326
file : string ;
326
327
range : p . Range ;
327
328
diagnostic : p . Diagnostic ;
329
+ todoValue : string
328
330
} ) => {
329
331
if ( recordFieldNames != null ) {
330
332
codeActions [ file ] = codeActions [ file ] || [ ] ;
@@ -373,16 +375,26 @@ let handleUndefinedRecordFieldsAction = ({
373
375
newText += paddingContentRecordField ;
374
376
}
375
377
376
- newText += `${ fieldName } : failwith("TODO") ,\n` ;
378
+ newText += `${ fieldName } : ${ todoValue } ,\n` ;
377
379
} ) ;
378
380
379
381
// Let's put the end brace back where it was (we still have it to the direct right of us).
380
382
newText += `${ paddingContentEndBrace } ` ;
381
383
} else {
382
384
// A single line record definition body is a bit easier - we'll just add the new fields on the same line.
383
- newText += ", " ;
385
+
386
+ // For an empty record (`range.end.character - range.start.character == 2`),
387
+ // we don't want to add an initial trailing comma as that would be invalid syntax.
388
+ //
389
+ // We assume that records that already contain some characters between
390
+ // their braces have at least one field and therefore we need to insert
391
+ // an initial trailing comma.
392
+ if ( range . end . character - range . start . character > 2 ) {
393
+ newText += ", " ;
394
+ }
395
+
384
396
newText += recordFieldNames
385
- . map ( ( fieldName ) => `${ fieldName } : failwith("TODO") ` )
397
+ . map ( ( fieldName ) => `${ fieldName } : ${ todoValue } ` )
386
398
. join ( ", " ) ;
387
399
}
388
400
@@ -440,6 +452,7 @@ let addUndefinedRecordFieldsV10: codeActionExtractor = ({
440
452
diagnostic,
441
453
file,
442
454
range,
455
+ todoValue : `failwith("TODO")`
443
456
} ) ;
444
457
}
445
458
@@ -458,7 +471,7 @@ let addUndefinedRecordFieldsV11: codeActionExtractor = ({
458
471
if ( line . startsWith ( "Some required record fields are missing:" ) ) {
459
472
let theLine = line ;
460
473
if ( theLine . endsWith ( "." ) ) {
461
- theLine = theLine . slice ( 0 , theLine . length - 2 ) ;
474
+ theLine = theLine . slice ( 0 , theLine . length - 1 ) ;
462
475
}
463
476
464
477
let recordFieldNames = theLine
@@ -486,6 +499,7 @@ let addUndefinedRecordFieldsV11: codeActionExtractor = ({
486
499
diagnostic,
487
500
file,
488
501
range,
502
+ todoValue : `%todo`
489
503
} ) ;
490
504
}
491
505
0 commit comments