@@ -93,7 +93,12 @@ export default class AsciidocFoldingRangeProvider implements vscode.FoldingRange
9393    } 
9494  } 
9595
96-   private  static  handleSingleLineCommentFoldingRanges  ( singleLineCommentStartIndexes : any [ ] ,  foldingRanges : any [ ] ,  lineIndex : number ,  lineText : string , 
96+   private  static  handleSingleLineCommentFoldingRanges  ( 
97+     singleLineCommentStartIndexes : any [ ] , 
98+     mixOfMultiAttributesAndSingleLineCommentsIndexes : any [ ] , 
99+     foldingRanges : any [ ] , 
100+     lineIndex : number , 
101+     lineText : string , 
97102    documentLineCount : number )  { 
98103    if  ( lineText . startsWith ( '//' ) )  { 
99104      if  ( singleLineCommentStartIndexes . length  ===  0 )  { 
@@ -102,7 +107,7 @@ export default class AsciidocFoldingRangeProvider implements vscode.FoldingRange
102107      if  ( lineIndex  >=  documentLineCount  -  1 )  { 
103108        // comment on last line of the document 
104109        const  startIndex  =  singleLineCommentStartIndexes . pop ( ) 
105-         if  ( lineIndex  >  startIndex )  { 
110+         if  ( lineIndex  >  startIndex   &&   ! ( lineText . startsWith ( ':' )   &&   mixOfMultiAttributesAndSingleLineCommentsIndexes [ 0 ]   ===   startIndex ) )  { 
106111          foldingRanges . push ( new  vscode . FoldingRange ( 
107112            startIndex , 
108113            lineIndex , 
@@ -114,7 +119,7 @@ export default class AsciidocFoldingRangeProvider implements vscode.FoldingRange
114119      if  ( singleLineCommentStartIndexes . length  !==  0 )  { 
115120        const  startIndex  =  singleLineCommentStartIndexes . pop ( ) 
116121        const  endIndex  =  lineIndex  -  1 
117-         if  ( endIndex  >  startIndex )  { 
122+         if  ( endIndex  >  startIndex   &&   ! ( lineText . startsWith ( ':' )   &&   mixOfMultiAttributesAndSingleLineCommentsIndexes [ 0 ]   ===   startIndex ) )  { 
118123          foldingRanges . push ( new  vscode . FoldingRange ( 
119124            startIndex , 
120125            endIndex , 
@@ -124,15 +129,21 @@ export default class AsciidocFoldingRangeProvider implements vscode.FoldingRange
124129    } 
125130  } 
126131
127-   private  static  handleMultiAttributesFoldingRanges  ( multiAttributesIndexes : any [ ] ,  foldingRanges : any [ ] ,  lineIndex : number ,  lineText : string ,  documentLineCount : number )  { 
132+   private  static  handleMultiAttributesFoldingRanges  ( 
133+     multiAttributesIndexes : any [ ] , 
134+     mixOfMultiAttributesAndSingleLineCommentsIndexes : any [ ] , 
135+     foldingRanges : any [ ] , 
136+     lineIndex : number , 
137+     lineText : string , 
138+     documentLineCount : number )  { 
128139    if  ( lineText . startsWith ( ':' ) )  { 
129140      if  ( multiAttributesIndexes . length  ===  0 )  { 
130141        multiAttributesIndexes . push ( lineIndex ) 
131142      } 
132143      if  ( lineIndex  >=  documentLineCount  -  1 )  { 
133144        // Attribute on last line of the document 
134145        const  startIndex  =  multiAttributesIndexes . pop ( ) 
135-         if  ( lineIndex  >  startIndex )  { 
146+         if  ( lineIndex  >  startIndex   &&   ! ( lineText . startsWith ( '//' )   &&   mixOfMultiAttributesAndSingleLineCommentsIndexes [ 0 ]   ===   startIndex ) )  { 
136147          foldingRanges . push ( new  vscode . FoldingRange ( 
137148            startIndex , 
138149            lineIndex ) 
@@ -143,11 +154,47 @@ export default class AsciidocFoldingRangeProvider implements vscode.FoldingRange
143154      if  ( multiAttributesIndexes . length  !==  0 )  { 
144155        const  startIndex  =  multiAttributesIndexes . pop ( ) 
145156        const  endIndex  =  lineIndex  -  1 
146-         if  ( endIndex  >  startIndex )  { 
157+         if  ( endIndex  >  startIndex  &&  ! ( lineText . startsWith ( '//' )  &&  mixOfMultiAttributesAndSingleLineCommentsIndexes [ 0 ]  ===  startIndex ) )  { 
158+           foldingRanges . push ( new  vscode . FoldingRange ( 
159+             startIndex , 
160+             endIndex ) ) 
161+         } 
162+       } 
163+     } 
164+   } 
165+ 
166+   private  static  handleMixOfMultiAttributesAndSingleLineCommentsFoldingRanges  ( 
167+     mixOfMultiAttributesAndSingleLineCommentsIndexes : any [ ] , 
168+     mixOfMultiAttributesAndSingleLineCommentsCharacters : Set < string > , 
169+     foldingRanges : any [ ] , 
170+     lineIndex : number , 
171+     lineText : string , 
172+     documentLineCount : number )  { 
173+     if  ( lineText . startsWith ( ':' )  ||  lineText . startsWith ( '//' ) )  { 
174+       if  ( mixOfMultiAttributesAndSingleLineCommentsIndexes . length  ===  0 )  { 
175+         mixOfMultiAttributesAndSingleLineCommentsIndexes . push ( lineIndex ) 
176+       } 
177+       mixOfMultiAttributesAndSingleLineCommentsCharacters . add ( lineText . charAt ( 0 ) ) 
178+       if  ( lineIndex  >=  documentLineCount  -  1 )  { 
179+         // Attribute on last line of the document 
180+         const  startIndex  =  mixOfMultiAttributesAndSingleLineCommentsIndexes . pop ( ) 
181+         if  ( lineIndex  >  startIndex  &&  mixOfMultiAttributesAndSingleLineCommentsCharacters . size  ===  2 )  { 
182+           foldingRanges . push ( new  vscode . FoldingRange ( 
183+             startIndex , 
184+             lineIndex ) 
185+           ) 
186+         } 
187+       } 
188+     }  else  { 
189+       if  ( mixOfMultiAttributesAndSingleLineCommentsIndexes . length  !==  0 )  { 
190+         const  startIndex  =  mixOfMultiAttributesAndSingleLineCommentsIndexes . pop ( ) 
191+         const  endIndex  =  lineIndex  -  1 
192+         if  ( endIndex  >  startIndex  &&  mixOfMultiAttributesAndSingleLineCommentsCharacters . size  ===  2 )  { 
147193          foldingRanges . push ( new  vscode . FoldingRange ( 
148194            startIndex , 
149195            endIndex ) ) 
150196        } 
197+         mixOfMultiAttributesAndSingleLineCommentsCharacters . clear ( ) 
151198      } 
152199    } 
153200  } 
@@ -158,14 +205,29 @@ export default class AsciidocFoldingRangeProvider implements vscode.FoldingRange
158205    const  commentBlockIndexes  =  [ ] 
159206    const  singleLineCommentStartIndexes  =  [ ] 
160207    const  multiAttributesIndexes  =  [ ] 
208+     const  mixOfMultiAttributesAndSingleLineCommentsIndexes  =  [ ] 
209+     const  mixOfMultiAttributesAndSingleLineCommentsCharacters  =  new  Set < string > ( ) 
161210    const  documentLineCount  =  document . lineCount 
162211    for  ( let  lineIndex  =  0 ;  lineIndex  <  documentLineCount ;  lineIndex ++ )  { 
163212      const  line  =  document . lineAt ( lineIndex ) 
164213      const  lineText  =  line . text 
165214      this . handleOpenBlockFoldingRanges ( openBlockIndexes ,  foldingRanges ,  lineIndex ,  lineText ,  documentLineCount ) 
166215      this . handleCommentBlockFoldingRanges ( commentBlockIndexes ,  foldingRanges ,  lineIndex ,  lineText ,  documentLineCount ) 
167-       this . handleSingleLineCommentFoldingRanges ( singleLineCommentStartIndexes ,  foldingRanges ,  lineIndex ,  lineText ,  documentLineCount ) 
168-       this . handleMultiAttributesFoldingRanges ( multiAttributesIndexes ,  foldingRanges ,  lineIndex ,  lineText ,  documentLineCount ) 
216+       this . handleSingleLineCommentFoldingRanges ( 
217+         singleLineCommentStartIndexes , 
218+         mixOfMultiAttributesAndSingleLineCommentsIndexes , 
219+         foldingRanges , 
220+         lineIndex , 
221+         lineText , 
222+         documentLineCount ) 
223+       this . handleMultiAttributesFoldingRanges ( multiAttributesIndexes ,  mixOfMultiAttributesAndSingleLineCommentsIndexes ,  foldingRanges ,  lineIndex ,  lineText ,  documentLineCount ) 
224+       this . handleMixOfMultiAttributesAndSingleLineCommentsFoldingRanges ( 
225+         mixOfMultiAttributesAndSingleLineCommentsIndexes , 
226+         mixOfMultiAttributesAndSingleLineCommentsCharacters , 
227+         foldingRanges , 
228+         lineIndex , 
229+         lineText , 
230+         documentLineCount ) 
169231    } 
170232    return  foldingRanges 
171233  } 
0 commit comments