@@ -20,6 +20,9 @@ export function customFoldInside(node: SyntaxNode, state: EditorState): { from:
2020 return foldMetadataOrModel ( node , state , '@Metadata' ) ;
2121 case 'Models' :
2222 return foldMetadataOrModel ( node , state , '@Model' ) ;
23+ case 'ParameterDeclaration' :
24+ case 'LocalDeclaration' :
25+ return foldVariables ( node , state ) ;
2326 }
2427 return null ;
2528}
@@ -107,6 +110,39 @@ export function foldRequest(requestNode: SyntaxNode, state: EditorState): { from
107110 return { from, to : endRequest } ;
108111}
109112
113+ /**
114+ * Calculate the fold range for a block of variables.
115+ * The fold range starts after the prefix of the block (e.g. "@INPUT_PARAMETERS_BEGIN" or "@LOCALS_BEGIN")
116+ * and ends of the block.
117+ * If the text ends with a line break, the end of the fold range will be adjusted to the start of the line break.
118+ *
119+ * @param containerNode - The node containing the variables (e.g. ParameterDeclaration or LocalDeclaration).
120+ * @param state - The EditorState object.
121+ * @returns A fold range object with "from" and "to" properties.
122+ * Returns null if any of the necessary nodes are not present.
123+ */
124+ export function foldVariables ( containerNode : SyntaxNode , state : EditorState ) : { from : number ; to : number } | null {
125+ // Get all the Variable nodes in the container node
126+ const variablesNodes = containerNode . getChildren ( 'Variable' ) ;
127+
128+ // Calculate the length of the directive (e.g. "@INPUT_PARAMETERS_BEGIN" or "@LOCALS_BEGIN")
129+ const directiveLength = state
130+ . sliceDoc ( containerNode . from , containerNode . to - variablesNodes . length ? getFromAndTo ( [ ...variablesNodes ] ) . from : 0 )
131+ . split ( '\n' ) [ 0 ] . length ;
132+
133+ // Calculate the start of the fold range after the directive
134+ const from = containerNode . from + directiveLength ;
135+
136+ // Calculate the end of the fold range after the last Variable node
137+ let endBlock = getFromAndTo ( [ containerNode ] ) . to ;
138+
139+ // If the text ends with a line break, adjust the end of the fold range to the start of the line break
140+ const text = state . sliceDoc ( containerNode . from + directiveLength , endBlock ) . trimEnd ( ) + '\n' ;
141+ endBlock = from + text . lastIndexOf ( '\n' ) ;
142+
143+ return { from, to : endBlock } ;
144+ }
145+
110146/**
111147 * Calculate the fold range for a Metadata or Model node.
112148 * The fold range starts after the node's prefix (e.g. "@Metadata" or "@Model") and ends after the node.
0 commit comments