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

Function extract

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

Source from the content-addressed store, hash-verified

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

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