@@ -22,17 +22,19 @@ import { EditorState, Extension } from '@codemirror/state';
2222import { foldService , syntaxTree } from '@codemirror/language' ;
2323import { SyntaxNode } from '@lezer/common' ;
2424
25- function isInStringOrComment ( state : EditorState , pos : number ) : boolean {
25+ function isInStringCommentOrVariable ( state : EditorState , pos : number ) : boolean {
2626 const tree = syntaxTree ( state ) ;
2727 let node : SyntaxNode | null = tree . resolveInner ( pos , 1 ) ;
2828
2929 while ( node ) {
3030 const nodeType = node . type . name ;
3131 // Check if we're in a string, comment, or other non-code context
32+ // Note that 'variableName' correesponds to a quoted name
3233 if ( nodeType === 'String' ||
3334 nodeType === 'Comment' ||
3435 nodeType === 'BlockComment' ||
3536 nodeType === 'LineComment' ||
37+ nodeType === 'variableName' ||
3638 nodeType . toLowerCase ( ) . includes ( 'string' ) ||
3739 nodeType . toLowerCase ( ) . includes ( 'comment' ) ) {
3840 return true ;
@@ -49,9 +51,8 @@ function findMatchingCloseBrace(state: EditorState, openPos: number): number | n
4951
5052 while ( pos < docLength && nest > 0 ) {
5153 const char = state . sliceDoc ( pos , pos + 1 ) ;
52-
53- // Skip if we're in a string or comment
54- if ( ! isInStringOrComment ( state , pos ) ) {
54+ // Skip if we're in a string, comment, or variable
55+ if ( ! isInStringCommentOrVariable ( state , pos ) ) {
5556 if ( char === '{' ) {
5657 nest ++ ;
5758 } else if ( char === '}' ) {
@@ -75,8 +76,8 @@ function computeFoldRange(state: EditorState, lineStart: number, lineEnd: number
7576 if ( char === '{' ) {
7677 const absolutePos = lineStart + i ;
7778
78- // Check if this brace is in a string or comment
79- if ( isInStringOrComment ( state , absolutePos ) ) {
79+ // Check if this brace is in a string, comment, or variable
80+ if ( isInStringCommentOrVariable ( state , absolutePos ) ) {
8081 continue ;
8182 }
8283
0 commit comments