tree-sitter-regex
tree-sitter-regex copied to clipboard
hang on 100% CPU usage when editing certain regex
Describe the bug
When trying to edit certain regexes, nvim started hanging on me with 100% CPU usage.
To Reproduce
I've minified the regex to the minimum amount of characters needed to reproduce the bug. Originally, the escape key was there to match ansi sequences.
-
neovim with bash & regex parsers installed:
:e /tmp/x.txt 10lx
Expected behavior
the closing parenthese gets deleted
Syntax tree:
(added x
to the empty group to remove one syntax error)
(pattern ; [0, 9] - [0, 25]
(alternation ; [0, 9] - [0, 25]
(term ; [0, 9] - [0, 12]
(anonymous_capturing_group ; [0, 9] - [0, 12]
(pattern ; [0, 10] - [0, 11]
(term ; [0, 10] - [0, 11]
(pattern_character))))) ; [0, 10] - [0, 11]
(term ; [0, 13] - [0, 25]
(anonymous_capturing_group ; [0, 13] - [0, 25]
(pattern ; [0, 14] - [0, 24]
(term ; [0, 14] - [0, 24]
(end_assertion) ; [0, 14] - [0, 15]
(ERROR) ; [0, 15] - [0, 16]
(pattern_character) ; [0, 16] - [0, 17]
(character_class ; [0, 17] - [0, 20]
(class_character)) ; [0, 18] - [0, 19]
(pattern_character) ; [0, 20] - [0, 21]
(pattern_character) ; [0, 21] - [0, 22]
(pattern_character) ; [0, 22] - [0, 23]
(pattern_character))))))) ; [0, 23] - [0, 24]
In terms of highlighting, the issue is that in bash the regex string can also contain bash variables and their syntax, but the parser doesn't detect that, so it tries to parse it as usual. But the freeze is the real issue.