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

Function extract

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

Source from the content-addressed store, hash-verified

138}
139
140pub fn extract(file_path: &str, source: &str) -> Result<EmitOut, String> {
141 let grammar = crate::langs::grammar_for("dart").ok_or("no dart grammar")?;
142 let t0 = std::time::Instant::now();
143 let mut parser = Parser::new();
144 parser
145 .set_language(&grammar)
146 .map_err(|e| format!("set_language(dart) failed: {e}"))?;
147 let tree = parser
148 .parse(source, None)
149 .ok_or_else(|| "parser returned null tree".to_string())?;
150 if tree.root_node().has_error() {
151 return Err("defer: parse tree contains errors — wasm recovery is canonical".to_string());
152 }
153
154 let mut w = Walker {
155 src: source,
156 file_path,
157 line_starts: util::line_starts(source),
158 arena: Arena::default(),
159 tables: Tables::default(),
160 stack: Vec::new(),
161 node_ids: Vec::new(),
162 defined_fn_names: HashSet::new(),
163 imported_names: HashSet::new(),
164 fn_ref_cands: Vec::new(),
165 fs_values: HashMap::new(),
166 fs_value_counts: HashMap::new(),
167 value_scopes: Vec::new(),
168 };
169
170 // File node (tree-sitter.ts:508-521).
171 let line_count = source.bytes().filter(|b| *b == b'\n').count() as u32 + 1;
172 let base_name = file_path.rsplit(['/', '\\']).next().unwrap_or(file_path);
173 let mut flags = BoolFlags::default();
174 flags.set(FLAG_IS_EXPORTED, false);
175 let file_id = w.arena.put(&ids::file_node_id(file_path));
176 let name_ref = w.arena.put(base_name);
177 let qn_ref = w.arena.put(file_path);
178 w.tables.push_node(&NodeRow {
179 kind: node_kind_index("file").unwrap(),
180 visibility: 0,
181 flags,
182 start_line: 1,
183 end_line: line_count,
184 start_column: 0,
185 end_column: 0,
186 name: name_ref,
187 qualified_name: qn_ref,
188 id: file_id,
189 docstring: NONE_STR,
190 signature: NONE_STR,
191 decorators: NONE_STR,
192 type_parameters: NONE_STR,
193 return_type: NONE_STR,
194 extra_json: NONE_STR,
195 });
196 w.node_ids.push(ids::file_node_id(file_path));
197 w.stack.push(Scope { row: 0, kind: "file", name: base_name.to_string() });

Callers

nothing calls this directly

Calls 14

grammar_forFunction · 0.85
file_node_idFunction · 0.85
node_kind_indexFunction · 0.85
build_metaFunction · 0.85
putMethod · 0.80
push_nodeMethod · 0.80
lenMethod · 0.80
into_vecMethod · 0.80
line_startsFunction · 0.70
unwrapMethod · 0.60
setMethod · 0.45
visitMethod · 0.45

Tested by

no test coverage detected