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

Function extract

codegraph-kernel/src/dart.rs:226–300  ·  view source on GitHub ↗
(file_path: &str, source: &str)

Source from the content-addressed store, hash-verified

224}
225
226pub fn extract(file_path: &str, source: &str) -> Result<EmitOut, String> {
227 let grammar = crate::langs::grammar_for("dart").ok_or("no dart grammar")?;
228 let t0 = std::time::Instant::now();
229 let mut parser = Parser::new();
230 parser
231 .set_language(&grammar)
232 .map_err(|e| format!("set_language(dart) failed: {e}"))?;
233 let tree = parser
234 .parse(source, None)
235 .ok_or_else(|| "parser returned null tree".to_string())?;
236 if tree.root_node().has_error() {
237 return Err("defer: parse tree contains errors — wasm recovery is canonical".to_string());
238 }
239
240 let mut w = Walker {
241 src: source,
242 file_path,
243 line_starts: util::line_starts(source),
244 arena: Arena::default(),
245 node_id_allocator: ids::NodeIdAllocator::default(),
246 tables: Tables::default(),
247 stack: Vec::new(),
248 node_ids: Vec::new(),
249 defined_fn_names: HashSet::new(),
250 imported_names: HashSet::new(),
251 fn_ref_cands: Vec::new(),
252 fs_values: HashMap::new(),
253 fs_value_counts: HashMap::new(),
254 value_scopes: Vec::new(),
255 };
256
257 // File node (tree-sitter.ts:508-521).
258 let line_count = source.bytes().filter(|b| *b == b'\n').count() as u32 + 1;
259 let base_name = file_path.rsplit(['/', '\\']).next().unwrap_or(file_path);
260 let mut flags = BoolFlags::default();
261 flags.set(FLAG_IS_EXPORTED, false);
262 let file_id = w.arena.put(&ids::file_node_id(file_path));
263 let name_ref = w.arena.put(base_name);
264 let qn_ref = w.arena.put(file_path);
265 w.tables.push_node(&NodeRow {
266 kind: node_kind_index("file").unwrap(),
267 visibility: 0,
268 flags,
269 start_line: 1,
270 end_line: line_count,
271 start_column: 0,
272 end_column: 0,
273 name: name_ref,
274 qualified_name: qn_ref,
275 id: file_id,
276 docstring: NONE_STR,
277 signature: NONE_STR,
278 decorators: NONE_STR,
279 type_parameters: NONE_STR,
280 return_type: NONE_STR,
281 extra_json: NONE_STR,
282 });
283 w.node_ids.push(ids::file_node_id(file_path));

Callers

nothing calls this directly

Calls 15

grammar_forFunction · 0.85
file_node_idFunction · 0.85
node_kind_indexFunction · 0.85
build_metaFunction · 0.85
parseMethod · 0.80
bytesMethod · 0.80
nextMethod · 0.80
push_nodeMethod · 0.80
pushMethod · 0.80
lenMethod · 0.80
into_vecMethod · 0.80
line_startsFunction · 0.70

Tested by

no test coverage detected