(language: String)
| 90 | |
| 91 | #[napi] |
| 92 | pub fn grammar_info(language: String) -> Option<GrammarInfo> { |
| 93 | let lang = langs::grammar_for(&language)?; |
| 94 | let node_kind_count = lang.node_kind_count(); |
| 95 | let field_count = lang.field_count(); |
| 96 | let node_kinds = (0..node_kind_count) |
| 97 | .map(|i| lang.node_kind_for_id(i as u16).unwrap_or("").to_string()) |
| 98 | .collect(); |
| 99 | // Field ids are 1-based in tree-sitter. |
| 100 | let field_names = (1..=field_count) |
| 101 | .map(|i| lang.field_name_for_id(i as u16).unwrap_or("").to_string()) |
| 102 | .collect(); |
| 103 | Some(GrammarInfo { |
| 104 | abi_version: lang.abi_version() as u32, |
| 105 | node_kind_count: node_kind_count as u32, |
| 106 | field_count: field_count as u32, |
| 107 | node_kinds, |
| 108 | field_names, |
| 109 | }) |
| 110 | } |
| 111 | |
| 112 | /// One struct node's extent for the cFnPtr sweep (mirror of the TS caller's |
| 113 | /// `{ id, startLine, endLine }`, with `endLine ?? startLine` applied TS-side). |
nothing calls this directly
no test coverage detected