MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / grammar_info

Function grammar_info

codegraph-kernel/src/lib.rs:108–126  ·  view source on GitHub ↗
(language: String)

Source from the content-addressed store, hash-verified

106
107#[napi]
108pub fn grammar_info(language: String) -> Option<GrammarInfo> {
109 let lang = langs::grammar_for(&language)?;
110 let node_kind_count = lang.node_kind_count();
111 let field_count = lang.field_count();
112 let node_kinds = (0..node_kind_count)
113 .map(|i| lang.node_kind_for_id(i as u16).unwrap_or("").to_string())
114 .collect();
115 // Field ids are 1-based in tree-sitter.
116 let field_names = (1..=field_count)
117 .map(|i| lang.field_name_for_id(i as u16).unwrap_or("").to_string())
118 .collect();
119 Some(GrammarInfo {
120 abi_version: lang.abi_version() as u32,
121 node_kind_count: node_kind_count as u32,
122 field_count: field_count as u32,
123 node_kinds,
124 field_names,
125 })
126}
127
128/// One struct node's extent for the cFnPtr sweep (mirror of the TS caller's
129/// `{ id, startLine, endLine }`, with `endLine ?? startLine` applied TS-side).

Callers

nothing calls this directly

Calls 3

grammar_forFunction · 0.85
mapMethod · 0.80
collectMethod · 0.45

Tested by

no test coverage detected