aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/lua/treesitter.c19
-rw-r--r--test/functional/treesitter/query_spec.lua20
2 files changed, 36 insertions, 3 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);
diff --git a/test/functional/treesitter/query_spec.lua b/test/functional/treesitter/query_spec.lua
index dfb5eb2685..634f8af83d 100644
--- a/test/functional/treesitter/query_spec.lua
+++ b/test/functional/treesitter/query_spec.lua
@@ -722,7 +722,25 @@ void ui_refresh(void)
eq(exp, pcall_err(exec_lua, "vim.treesitter.query.parse('c', ...)", cquery))
end
- -- Invalid node type
+ -- Invalid node types
+ test(
+ '.../query.lua:0: Query error at 1:2. Invalid node type ">\\">>":\n'
+ .. '">\\">>" @operator\n'
+ .. ' ^',
+ '">\\">>" @operator'
+ )
+ test(
+ '.../query.lua:0: Query error at 1:2. Invalid node type "\\\\":\n'
+ .. '"\\\\" @operator\n'
+ .. ' ^',
+ '"\\\\" @operator'
+ )
+ test(
+ '.../query.lua:0: Query error at 1:2. Invalid node type ">>>":\n'
+ .. '">>>" @operator\n'
+ .. ' ^',
+ '">>>" @operator'
+ )
test(
'.../query.lua:0: Query error at 1:2. Invalid node type "dentifier":\n'
.. '(dentifier) @variable\n'