@@ -1292,7 +1292,7 @@ export class YamlCompletion {
12921292 case 'anyOf' : {
12931293 let value = propertySchema . default || propertySchema . const ;
12941294 if ( value ) {
1295- if ( type === 'string' ) {
1295+ if ( type === 'string' || typeof value === 'string' ) {
12961296 value = convertToStringValue ( value ) ;
12971297 }
12981298 insertText += `${ indent } ${ key } : \${${ insertIndex ++ } :${ value } }\n` ;
@@ -1406,7 +1406,7 @@ export class YamlCompletion {
14061406 case 'string' : {
14071407 let snippetValue = JSON . stringify ( value ) ;
14081408 snippetValue = snippetValue . substr ( 1 , snippetValue . length - 2 ) ; // remove quotes
1409- snippetValue = this . getInsertTextForPlainText ( snippetValue ) ; // escape \ and }
1409+ snippetValue = getInsertTextForPlainText ( snippetValue ) ; // escape \ and }
14101410 if ( type === 'string' ) {
14111411 snippetValue = convertToStringValue ( snippetValue ) ;
14121412 }
@@ -1419,10 +1419,6 @@ export class YamlCompletion {
14191419 return this . getInsertTextForValue ( value , separatorAfter , type ) ;
14201420 }
14211421
1422- private getInsertTextForPlainText ( text : string ) : string {
1423- return text . replace ( / [ \\ $ } ] / g, '\\$&' ) ; // escape $, \ and }
1424- }
1425-
14261422 // eslint-disable-next-line @typescript-eslint/no-explicit-any
14271423 private getInsertTextForValue ( value : any , separatorAfter : string , type : string | string [ ] ) : string {
14281424 if ( value === null ) {
@@ -1435,13 +1431,13 @@ export class YamlCompletion {
14351431 }
14361432 case 'number' :
14371433 case 'boolean' :
1438- return this . getInsertTextForPlainText ( value + separatorAfter ) ;
1434+ return getInsertTextForPlainText ( value + separatorAfter ) ;
14391435 }
14401436 type = Array . isArray ( type ) ? type [ 0 ] : type ;
14411437 if ( type === 'string' ) {
14421438 value = convertToStringValue ( value ) ;
14431439 }
1444- return this . getInsertTextForPlainText ( value + separatorAfter ) ;
1440+ return getInsertTextForPlainText ( value + separatorAfter ) ;
14451441 }
14461442
14471443 private getInsertTemplateForValue (
@@ -1466,14 +1462,14 @@ export class YamlCompletion {
14661462 if ( typeof element === 'object' ) {
14671463 valueTemplate = `${ this . getInsertTemplateForValue ( element , indent + this . indentation , navOrder , separatorAfter ) } ` ;
14681464 } else {
1469- valueTemplate = ` \${${ navOrder . index ++ } :${ this . getInsertTextForPlainText ( element + separatorAfter ) } }\n` ;
1465+ valueTemplate = ` \${${ navOrder . index ++ } :${ getInsertTextForPlainText ( element + separatorAfter ) } }\n` ;
14701466 }
14711467 insertText += `${ valueTemplate } ` ;
14721468 }
14731469 }
14741470 return insertText ;
14751471 }
1476- return this . getInsertTextForPlainText ( value + separatorAfter ) ;
1472+ return getInsertTextForPlainText ( value + separatorAfter ) ;
14771473 }
14781474
14791475 private addSchemaValueCompletions (
@@ -1860,6 +1856,13 @@ export class YamlCompletion {
18601856 }
18611857}
18621858
1859+ /**
1860+ * escape $, \ and }
1861+ */
1862+ function getInsertTextForPlainText ( text : string ) : string {
1863+ return text . replace ( / [ \\ $ } ] / g, '\\$&' ) ; //
1864+ }
1865+
18631866const isNumberExp = / ^ \d + $ / ;
18641867function convertToStringValue ( param : unknown ) : string {
18651868 let value : string ;
@@ -1872,6 +1875,8 @@ function convertToStringValue(param: unknown): string {
18721875 return value ;
18731876 }
18741877
1878+ value = getInsertTextForPlainText ( value ) ; // escape $, \ and }
1879+
18751880 if ( value === 'true' || value === 'false' || value === 'null' || isNumberExp . test ( value ) ) {
18761881 return `"${ value } "` ;
18771882 }
0 commit comments