@@ -78,6 +78,7 @@ abstract class TreeSitterLanguage(
7878
7979 private val log = LoggerFactory .getLogger(TreeSitterLanguage ::class .java)
8080 private const val DEF_IDENT_ADV = 0
81+ private const val MAX_INDENT_ADVANCE = 4096
8182 }
8283
8384 fun setupWith (scheme : IDEColorScheme ? ) {
@@ -160,16 +161,21 @@ abstract class TreeSitterLanguage(
160161
161162 if (indents.size == 1 ) {
162163 val indent = indents[0 ]
163- if (indent == TreeSitterIndentProvider .INDENTATION_ERR ) {
164+ if (indent == TreeSitterIndentProvider .INDENTATION_ERR
165+ || indent == TreeSitterIndentProvider .INDENT_AUTO
166+ ) {
164167 return DEF_IDENT_ADV
165168 }
166169
167- return indent - (spaceCountOnLine + (tabCountOnLine * getTabSize()))
170+ return (indent - (spaceCountOnLine + (tabCountOnLine * getTabSize())))
171+ .coerceIn(- MAX_INDENT_ADVANCE , MAX_INDENT_ADVANCE )
168172 }
169173
170174 val (indentLine, indentNxtLine) = indents
171175 if (indentLine == TreeSitterIndentProvider .INDENTATION_ERR
172176 || indentNxtLine == TreeSitterIndentProvider .INDENTATION_ERR
177+ || indentLine == TreeSitterIndentProvider .INDENT_AUTO
178+ || indentNxtLine == TreeSitterIndentProvider .INDENT_AUTO
173179 ) {
174180 log.debug(
175181 " expectedIndent[{}]={}, expectedIndentNextLine[{}]={}, returning default indent advance" ,
@@ -178,7 +184,7 @@ abstract class TreeSitterLanguage(
178184 return DEF_IDENT_ADV
179185 }
180186
181- return indentNxtLine - indentLine
187+ return ( indentNxtLine - indentLine).coerceIn( - MAX_INDENT_ADVANCE , MAX_INDENT_ADVANCE )
182188 } catch (e: Exception ) {
183189 log.error(
184190 " An error occurred computing indentation at line:column::{}:{}" ,
0 commit comments