aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiley Bruins <ribru17@hotmail.com>2024-11-08 11:42:09 -0800
committerChristian Clason <ch.clason+github@icloud.com>2024-11-13 13:32:58 +0100
commit36990f324de2cfb96a6d2450e9c3ddfc3fba8afa (patch)
tree1d29fc8d7d2166b0c2f890399d3a275065bc9ec9 /src
parent37f665c504e499c95bc0a88c52dd38ca9f621cdd (diff)
downloadrneovim-36990f324de2cfb96a6d2450e9c3ddfc3fba8afa.tar.gz
rneovim-36990f324de2cfb96a6d2450e9c3ddfc3fba8afa.tar.bz2
rneovim-36990f324de2cfb96a6d2450e9c3ddfc3fba8afa.zip
fix(treesitter): show proper node name error messages
**Problem:** Currently node names with non-alphanumeric, non underscore/hyphen characters (only possible with anonymous nodes) are not given a proper error message. See tree-sitter issue 3892 for more details. **Solution:** Apply a different scanning logic to anonymous nodes to correctly identify the entire node name (i.e., up until the final double quote)
Diffstat (limited to 'src')
-rw-r--r--src/nvim/lua/treesitter.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c
index 9ea55dbd0c..c80e7b7672 100644
--- a/src/nvim/lua/treesitter.c
+++ b/src/nvim/lua/treesitter.c
@@ -1528,10 +1528,25 @@ static void query_err_string(const char *src, int error_offset, TSQueryError err
|| error_type == TSQueryErrorField
|| error_type == TSQueryErrorCapture) {
const char *suffix = src + error_offset;
+ bool is_anonymous = error_type == TSQueryErrorNodeType && suffix[-1] == '"';
int suffix_len = 0;
char c = suffix[suffix_len];
- while (isalnum(c) || c == '_' || c == '-' || c == '.') {
- c = suffix[++suffix_len];
+ if (is_anonymous) {
+ int backslashes = 0;
+ // Stop when we hit an unescaped double quote
+ while (c != '"' || backslashes % 2 != 0) {
+ if (c == '\\') {
+ backslashes += 1;
+ } else {
+ backslashes = 0;
+ }
+ c = suffix[++suffix_len];
+ }
+ } else {
+ // Stop when we hit the end of the identifier
+ while (isalnum(c) || c == '_' || c == '-' || c == '.') {
+ c = suffix[++suffix_len];
+ }
}
snprintf(err, errlen, "\"%.*s\":\n", suffix_len, suffix);
offset = strlen(err);