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

Function extract

codegraph-kernel/src/scala.rs:169–245  ·  view source on GitHub ↗
(file_path: &str, source: &str)

Source from the content-addressed store, hash-verified

167}
168
169pub fn extract(file_path: &str, source: &str) -> Result<EmitOut, String> {
170 let grammar = crate::langs::grammar_for("scala").ok_or("no scala grammar")?;
171 let t0 = std::time::Instant::now();
172 let mut parser = Parser::new();
173 parser
174 .set_language(&grammar)
175 .map_err(|e| format!("set_language(scala) failed: {e}"))?;
176 let tree = parser
177 .parse(source, None)
178 .ok_or_else(|| "parser returned null tree".to_string())?;
179 if tree.root_node().has_error() {
180 // Includes scala-3 PHANTOMS (flag-true, zero ERROR nodes) — the flag
181 // is the policy, never node-scanning.
182 return Err("defer: parse tree contains errors — wasm recovery is canonical".to_string());
183 }
184
185 let mut w = Walker {
186 src: source,
187 file_path,
188 line_starts: util::line_starts(source),
189 arena: Arena::default(),
190 tables: Tables::default(),
191 stack: Vec::new(),
192 node_ids: Vec::new(),
193 defined_fn_names: HashSet::new(),
194 imported_names: HashSet::new(),
195 fn_ref_cands: Vec::new(),
196 fs_values: HashMap::new(),
197 fs_value_counts: HashMap::new(),
198 value_scopes: Vec::new(),
199 };
200
201 // File node (tree-sitter.ts:508-521).
202 let line_count = source.bytes().filter(|b| *b == b'\n').count() as u32 + 1;
203 let base_name = file_path.rsplit(['/', '\\']).next().unwrap_or(file_path);
204 let mut flags = BoolFlags::default();
205 flags.set(FLAG_IS_EXPORTED, false);
206 let file_id = w.arena.put(&ids::file_node_id(file_path));
207 let name_ref = w.arena.put(base_name);
208 let qn_ref = w.arena.put(file_path);
209 w.tables.push_node(&NodeRow {
210 kind: node_kind_index("file").unwrap(),
211 visibility: 0,
212 flags,
213 start_line: 1,
214 end_line: line_count,
215 start_column: 0,
216 end_column: 0,
217 name: name_ref,
218 qualified_name: qn_ref,
219 id: file_id,
220 docstring: NONE_STR,
221 signature: NONE_STR,
222 decorators: NONE_STR,
223 type_parameters: NONE_STR,
224 return_type: NONE_STR,
225 extra_json: NONE_STR,
226 });

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