Skip to content

Commit 9e02937

Browse files
committed
yeast: Use canonical ID when registering unnamed kinds in Schema
Schema::from_language registered unnamed kinds via or_insert(id), where `id` came from iterating 0..node_kind_count. For names with multiple unnamed IDs (notably "end" in tree-sitter-ruby has IDs 0 and 13, where ID 0 is the reserved error token), this picked the first encountered ID — typically the wrong one. The visitor sets node.kind via language.id_for_node_kind(name, false), which returns the canonical ID. So a query for ("end") would compare node.kind=13 against schema=0 and silently fail to match, with no diagnostic. Use language.id_for_node_kind(name, false) to obtain the canonical ID when registering, mirroring the named-kind path that already does the same with id_for_node_kind(name, true).
1 parent 7b07e10 commit 9e02937

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

shared/yeast/src/schema.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ impl Schema {
6161
}
6262
}
6363
// Import all node kind names, preserving tree-sitter's IDs.
64-
// Track named and unnamed variants separately.
65-
// For named kinds, use the canonical ID from id_for_node_kind(name, true)
66-
// since some languages have multiple IDs for the same named kind.
64+
// Track named and unnamed variants separately. For both named and
65+
// unnamed kinds, use the canonical ID from id_for_node_kind, since
66+
// some languages have multiple IDs for the same name (e.g., the
67+
// reserved error token at ID 0 may share a name with a real token).
6768
for id in 0..language.node_kind_count() as u16 {
6869
if let Some(name) = language.node_kind_for_id(id) {
6970
if !name.is_empty() {
@@ -75,12 +76,13 @@ impl Schema {
7576
schema.kind_names.insert(canonical_id, name);
7677
}
7778
} else {
78-
// For unnamed kinds, only insert if we don't already have one
79-
// (some languages have multiple unnamed IDs for the same text)
80-
schema
81-
.unnamed_kind_ids
82-
.entry(name.to_string())
83-
.or_insert(id);
79+
let canonical_id = language.id_for_node_kind(name, false);
80+
if canonical_id != 0 && !schema.unnamed_kind_ids.contains_key(name) {
81+
schema
82+
.unnamed_kind_ids
83+
.insert(name.to_string(), canonical_id);
84+
schema.kind_names.insert(canonical_id, name);
85+
}
8486
}
8587
// Always track the name for any ID we encounter
8688
schema.kind_names.entry(id).or_insert(name);

0 commit comments

Comments
 (0)