@@ -1115,7 +1115,7 @@ export class YamlCompletion {
1115
1115
case 'anyOf' : {
1116
1116
let value = propertySchema . default || propertySchema . const ;
1117
1117
if ( value ) {
1118
- if ( type === 'string' ) {
1118
+ if ( type === 'string' || typeof value === 'string' ) {
1119
1119
value = convertToStringValue ( value ) ;
1120
1120
}
1121
1121
insertText += `${ indent } ${ key } : \${${ insertIndex ++ } :${ value } }\n` ;
@@ -1229,7 +1229,7 @@ export class YamlCompletion {
1229
1229
case 'string' : {
1230
1230
let snippetValue = JSON . stringify ( value ) ;
1231
1231
snippetValue = snippetValue . substr ( 1 , snippetValue . length - 2 ) ; // remove quotes
1232
- snippetValue = this . getInsertTextForPlainText ( snippetValue ) ; // escape \ and }
1232
+ snippetValue = getInsertTextForPlainText ( snippetValue ) ; // escape \ and }
1233
1233
if ( type === 'string' ) {
1234
1234
snippetValue = convertToStringValue ( snippetValue ) ;
1235
1235
}
@@ -1242,10 +1242,6 @@ export class YamlCompletion {
1242
1242
return this . getInsertTextForValue ( value , separatorAfter , type ) ;
1243
1243
}
1244
1244
1245
- private getInsertTextForPlainText ( text : string ) : string {
1246
- return text . replace ( / [ \\ $ } ] / g, '\\$&' ) ; // escape $, \ and }
1247
- }
1248
-
1249
1245
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1250
1246
private getInsertTextForValue ( value : any , separatorAfter : string , type : string | string [ ] ) : string {
1251
1247
if ( value === null ) {
@@ -1258,13 +1254,13 @@ export class YamlCompletion {
1258
1254
}
1259
1255
case 'number' :
1260
1256
case 'boolean' :
1261
- return this . getInsertTextForPlainText ( value + separatorAfter ) ;
1257
+ return getInsertTextForPlainText ( value + separatorAfter ) ;
1262
1258
}
1263
1259
type = Array . isArray ( type ) ? type [ 0 ] : type ;
1264
1260
if ( type === 'string' ) {
1265
1261
value = convertToStringValue ( value ) ;
1266
1262
}
1267
- return this . getInsertTextForPlainText ( value + separatorAfter ) ;
1263
+ return getInsertTextForPlainText ( value + separatorAfter ) ;
1268
1264
}
1269
1265
1270
1266
private getInsertTemplateForValue (
@@ -1289,14 +1285,14 @@ export class YamlCompletion {
1289
1285
if ( typeof element === 'object' ) {
1290
1286
valueTemplate = `${ this . getInsertTemplateForValue ( element , indent + this . indentation , navOrder , separatorAfter ) } ` ;
1291
1287
} else {
1292
- valueTemplate = ` \${${ navOrder . index ++ } :${ this . getInsertTextForPlainText ( element + separatorAfter ) } }\n` ;
1288
+ valueTemplate = ` \${${ navOrder . index ++ } :${ getInsertTextForPlainText ( element + separatorAfter ) } }\n` ;
1293
1289
}
1294
1290
insertText += `${ valueTemplate } ` ;
1295
1291
}
1296
1292
}
1297
1293
return insertText ;
1298
1294
}
1299
- return this . getInsertTextForPlainText ( value + separatorAfter ) ;
1295
+ return getInsertTextForPlainText ( value + separatorAfter ) ;
1300
1296
}
1301
1297
1302
1298
private addSchemaValueCompletions (
@@ -1668,6 +1664,13 @@ export class YamlCompletion {
1668
1664
}
1669
1665
}
1670
1666
1667
+ /**
1668
+ * escape $, \ and }
1669
+ */
1670
+ function getInsertTextForPlainText ( text : string ) : string {
1671
+ return text . replace ( / [ \\ $ } ] / g, '\\$&' ) ; //
1672
+ }
1673
+
1671
1674
const isNumberExp = / ^ \d + $ / ;
1672
1675
function convertToStringValue ( param : unknown ) : string {
1673
1676
let value : string ;
@@ -1680,6 +1683,8 @@ function convertToStringValue(param: unknown): string {
1680
1683
return value ;
1681
1684
}
1682
1685
1686
+ value = getInsertTextForPlainText ( value ) ; // escape $, \ and }
1687
+
1683
1688
if ( value === 'true' || value === 'false' || value === 'null' || isNumberExp . test ( value ) ) {
1684
1689
return `"${ value } "` ;
1685
1690
}
0 commit comments