@@ -1292,7 +1292,7 @@ export class YamlCompletion {
1292
1292
case 'anyOf' : {
1293
1293
let value = propertySchema . default || propertySchema . const ;
1294
1294
if ( value ) {
1295
- if ( type === 'string' ) {
1295
+ if ( type === 'string' || typeof value === 'string' ) {
1296
1296
value = convertToStringValue ( value ) ;
1297
1297
}
1298
1298
insertText += `${ indent } ${ key } : \${${ insertIndex ++ } :${ value } }\n` ;
@@ -1406,7 +1406,7 @@ export class YamlCompletion {
1406
1406
case 'string' : {
1407
1407
let snippetValue = JSON . stringify ( value ) ;
1408
1408
snippetValue = snippetValue . substr ( 1 , snippetValue . length - 2 ) ; // remove quotes
1409
- snippetValue = this . getInsertTextForPlainText ( snippetValue ) ; // escape \ and }
1409
+ snippetValue = getInsertTextForPlainText ( snippetValue ) ; // escape \ and }
1410
1410
if ( type === 'string' ) {
1411
1411
snippetValue = convertToStringValue ( snippetValue ) ;
1412
1412
}
@@ -1419,10 +1419,6 @@ export class YamlCompletion {
1419
1419
return this . getInsertTextForValue ( value , separatorAfter , type ) ;
1420
1420
}
1421
1421
1422
- private getInsertTextForPlainText ( text : string ) : string {
1423
- return text . replace ( / [ \\ $ } ] / g, '\\$&' ) ; // escape $, \ and }
1424
- }
1425
-
1426
1422
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1427
1423
private getInsertTextForValue ( value : any , separatorAfter : string , type : string | string [ ] ) : string {
1428
1424
if ( value === null ) {
@@ -1435,13 +1431,13 @@ export class YamlCompletion {
1435
1431
}
1436
1432
case 'number' :
1437
1433
case 'boolean' :
1438
- return this . getInsertTextForPlainText ( value + separatorAfter ) ;
1434
+ return getInsertTextForPlainText ( value + separatorAfter ) ;
1439
1435
}
1440
1436
type = Array . isArray ( type ) ? type [ 0 ] : type ;
1441
1437
if ( type === 'string' ) {
1442
1438
value = convertToStringValue ( value ) ;
1443
1439
}
1444
- return this . getInsertTextForPlainText ( value + separatorAfter ) ;
1440
+ return getInsertTextForPlainText ( value + separatorAfter ) ;
1445
1441
}
1446
1442
1447
1443
private getInsertTemplateForValue (
@@ -1466,14 +1462,14 @@ export class YamlCompletion {
1466
1462
if ( typeof element === 'object' ) {
1467
1463
valueTemplate = `${ this . getInsertTemplateForValue ( element , indent + this . indentation , navOrder , separatorAfter ) } ` ;
1468
1464
} else {
1469
- valueTemplate = ` \${${ navOrder . index ++ } :${ this . getInsertTextForPlainText ( element + separatorAfter ) } }\n` ;
1465
+ valueTemplate = ` \${${ navOrder . index ++ } :${ getInsertTextForPlainText ( element + separatorAfter ) } }\n` ;
1470
1466
}
1471
1467
insertText += `${ valueTemplate } ` ;
1472
1468
}
1473
1469
}
1474
1470
return insertText ;
1475
1471
}
1476
- return this . getInsertTextForPlainText ( value + separatorAfter ) ;
1472
+ return getInsertTextForPlainText ( value + separatorAfter ) ;
1477
1473
}
1478
1474
1479
1475
private addSchemaValueCompletions (
@@ -1860,6 +1856,13 @@ export class YamlCompletion {
1860
1856
}
1861
1857
}
1862
1858
1859
+ /**
1860
+ * escape $, \ and }
1861
+ */
1862
+ function getInsertTextForPlainText ( text : string ) : string {
1863
+ return text . replace ( / [ \\ $ } ] / g, '\\$&' ) ; //
1864
+ }
1865
+
1863
1866
const isNumberExp = / ^ \d + $ / ;
1864
1867
function convertToStringValue ( param : unknown ) : string {
1865
1868
let value : string ;
@@ -1872,6 +1875,8 @@ function convertToStringValue(param: unknown): string {
1872
1875
return value ;
1873
1876
}
1874
1877
1878
+ value = getInsertTextForPlainText ( value ) ; // escape $, \ and }
1879
+
1875
1880
if ( value === 'true' || value === 'false' || value === 'null' || isNumberExp . test ( value ) ) {
1876
1881
return `"${ value } "` ;
1877
1882
}
0 commit comments