@@ -144,11 +144,11 @@ export class YamlCompletion {
144144
145145 this . arrayPrefixIndentation = '' ;
146146 let overwriteRange : Range = null ;
147+ const isOnlyHyphen = lineContent . match ( / ^ \s * ( - ) \s * $ / ) ;
147148 if ( areOnlySpacesAfterPosition ) {
148149 overwriteRange = Range . create ( position , Position . create ( position . line , lineContent . length ) ) ;
149150 const isOnlyWhitespace = lineContent . trim ( ) . length === 0 ;
150- const isOnlyDash = lineContent . match ( / ^ \s * ( - ) \s * $ / ) ;
151- if ( node && isScalar ( node ) && ! isOnlyWhitespace && ! isOnlyDash ) {
151+ if ( node && isScalar ( node ) && ! isOnlyWhitespace && ! isOnlyHyphen ) {
152152 const lineToPosition = lineContent . substring ( 0 , position . character ) ;
153153 const matches =
154154 // get indentation of unfinished property (between indent and cursor)
@@ -357,6 +357,12 @@ export class YamlCompletion {
357357 if ( node ) {
358358 if ( lineContent . length === 0 ) {
359359 node = currentDoc . internalDocument . contents as Node ;
360+ } else if ( isSeq ( node ) && isOnlyHyphen ) {
361+ const index = this . findItemAtOffset ( node , document , offset ) ;
362+ const item = node . items [ index ] ;
363+ if ( isNode ( item ) ) {
364+ node = item ;
365+ }
360366 } else {
361367 const parent = currentDoc . getParent ( node ) ;
362368 if ( parent ) {
@@ -717,19 +723,19 @@ export class YamlCompletion {
717723 const propertySchema = schemaProperties [ key ] ;
718724
719725 if ( typeof propertySchema === 'object' && ! propertySchema . deprecationMessage && ! propertySchema [ 'doNotSuggest' ] ) {
720- let identCompensation = '' ;
726+ let indentCompensation = '' ;
721727 if ( nodeParent && isSeq ( nodeParent ) && node . items . length <= 1 && ! hasOnlyWhitespace ) {
722- // because there is a slash '-' to prevent the properties generated to have the correct
723- // indent
724- const sourceText = textBuffer . getText ( ) ;
725- const indexOfSlash = sourceText . lastIndexOf ( '-' , node . range [ 0 ] - 1 ) ;
726- if ( indexOfSlash >= 0 ) {
727- // add one space to compensate the '-'
728- const overwriteChars = overwriteRange . end . character - overwriteRange . start . character ;
729- identCompensation = ' ' + sourceText . slice ( indexOfSlash + 1 , node . range [ 1 ] - overwriteChars ) ;
728+ // because there is a slash '-' to prevent the properties generated to have the correct indent
729+ const fromLastHyphenToPosition = lineContent . slice (
730+ lineContent . lastIndexOf ( '-' ) ,
731+ overwriteRange . start . character
732+ ) ;
733+ const hyphenFollowedByEmpty = fromLastHyphenToPosition . match ( / - ( [ \t ] * ) / ) ;
734+ if ( hyphenFollowedByEmpty ) {
735+ indentCompensation = ' ' + hyphenFollowedByEmpty [ 1 ] ;
730736 }
731737 }
732- identCompensation += this . arrayPrefixIndentation ;
738+ indentCompensation += this . arrayPrefixIndentation ;
733739
734740 // if check that current node has last pair with "null" value and key witch match key from schema,
735741 // and if schema has array definition it add completion item for array item creation
@@ -760,7 +766,7 @@ export class YamlCompletion {
760766 key ,
761767 propertySchema ,
762768 separatorAfter ,
763- identCompensation + this . indentation
769+ indentCompensation + this . indentation
764770 ) ;
765771 }
766772 const isNodeNull =
@@ -787,13 +793,13 @@ export class YamlCompletion {
787793 key ,
788794 propertySchema ,
789795 separatorAfter ,
790- identCompensation + this . indentation
796+ indentCompensation + this . indentation
791797 ) ,
792798 insertTextFormat : InsertTextFormat . Snippet ,
793799 documentation : this . fromMarkup ( propertySchema . markdownDescription ) || propertySchema . description || '' ,
794800 parent : {
795801 schema : schema . schema ,
796- indent : identCompensation ,
802+ indent : indentCompensation ,
797803 } ,
798804 } ) ;
799805 }
0 commit comments