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