@@ -188,6 +188,7 @@ export class LanguageServiceProvider {
188188 getFoldingRanges ( ) : FoldingRange [ ] {
189189 const lineCount = this . model . getLineCount ( ) ;
190190 const result : FoldingRange [ ] = [ ] ;
191+ this . addCommentFolding ( result ) ;
191192
192193 for ( let i = 0 ; i < lineCount ; i ++ ) {
193194 const rootBlock = this . syntaxProvider . getFoldingBlock (
@@ -210,9 +211,66 @@ export class LanguageServiceProvider {
210211 continue ;
211212 }
212213 }
214+
213215 return result ;
214216 }
215217
218+ private addCommentFolding ( result : FoldingRange [ ] ) {
219+ const lineCount = this . model . getLineCount ( ) ;
220+
221+ // Method 1: Try token blocks (works for comments inside code blocks)
222+ if ( this . syntaxProvider . lexer . tknBlks ) {
223+ const tokenBlocks = this . syntaxProvider . lexer . tknBlks ;
224+ for ( let i = 0 ; i < tokenBlocks . length ; i ++ ) {
225+ const block = tokenBlocks [ i ] ;
226+ const isComment =
227+ block . blockComment === true || block . type === "comment" ;
228+ if ( isComment && block . endLine > block . startLine ) {
229+ result . push ( {
230+ startLine : block . startLine ,
231+ endLine : block . endLine ,
232+ kind : "comment" ,
233+ } ) ;
234+ }
235+ }
236+ }
237+
238+ // Method 2: Scan for multiline comments using syntax tokens (for standalone comments)
239+ let inBlockComment = false ;
240+ let commentStartLine = - 1 ;
241+
242+ for ( let lineNum = 0 ; lineNum < lineCount ; lineNum ++ ) {
243+ const line = this . model . getLine ( lineNum ) ;
244+
245+ if ( ! inBlockComment && line . includes ( "/*" ) ) {
246+ const commentStart = line . indexOf ( "/*" ) ;
247+ const commentEnd = line . indexOf ( "*/" , commentStart + 2 ) ;
248+
249+ if ( commentEnd === - 1 ) {
250+ inBlockComment = true ;
251+ commentStartLine = lineNum ;
252+ }
253+ } else if ( inBlockComment && line . includes ( "*/" ) ) {
254+ inBlockComment = false ;
255+ if ( commentStartLine !== - 1 && lineNum > commentStartLine ) {
256+ const isAlreadyCovered = result . some (
257+ ( range ) =>
258+ range . startLine === commentStartLine && range . endLine === lineNum ,
259+ ) ;
260+
261+ if ( ! isAlreadyCovered ) {
262+ result . push ( {
263+ startLine : commentStartLine ,
264+ endLine : lineNum ,
265+ kind : "comment" ,
266+ } ) ;
267+ }
268+ }
269+ commentStartLine = - 1 ;
270+ }
271+ }
272+ }
273+
216274 // DFS
217275 private _flattenFoldingBlockTree ( rootBlock : FoldingBlock ) : FoldingBlock [ ] {
218276 const stack : FoldingBlock [ ] = [ rootBlock ] ;
0 commit comments