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

Function extract

codegraph-kernel/src/kotlin.rs:230–333  ·  view source on GitHub ↗
(file_path: &str, source: &str)

Source from the content-addressed store, hash-verified

228}
229
230pub fn extract(file_path: &str, source: &str) -> Result<EmitOut, String> {
231 let grammar = crate::langs::grammar_for("kotlin").ok_or("no kotlin grammar")?;
232 let t0 = std::time::Instant::now();
233 let mut parser = Parser::new();
234 parser
235 .set_language(&grammar)
236 .map_err(|e| format!("set_language(kotlin) failed: {e}"))?;
237 let tree = crate::parse_budget::parse(&mut parser, source)?;
238 if tree.root_node().has_error() {
239 // Includes the PHANTOM errors (complete CSTs with hasError set) and
240 // every fun-interface misparse — trust the flag, wasm is canonical.
241 return Err("defer: parse tree contains errors — wasm recovery is canonical".to_string());
242 }
243
244 let mut w = Walker {
245 src: source,
246 file_path,
247 line_starts: util::line_starts(source),
248 arena: Arena::default(),
249 node_id_allocator: ids::NodeIdAllocator::default(),
250 tables: Tables::default(),
251 stack: Vec::new(),
252 node_ids: Vec::new(),
253 nodes_meta: Vec::new(),
254 defined_fn_names: HashSet::new(),
255 imported_names: HashSet::new(),
256 fn_ref_cands: Vec::new(),
257 fs_values: HashMap::new(),
258 fs_value_counts: HashMap::new(),
259 value_scopes: Vec::new(),
260 };
261
262 let line_count = source.bytes().filter(|b| *b == b'\n').count() as u32 + 1;
263 let base_name = file_path.rsplit(['/', '\\']).next().unwrap_or(file_path);
264 let mut flags = BoolFlags::default();
265 flags.set(FLAG_IS_EXPORTED, false);
266 let file_id = w.arena.put(&ids::file_node_id(file_path));
267 let name_ref = w.arena.put(base_name);
268 let qn_ref = w.arena.put(file_path);
269 w.tables.push_node(&NodeRow {
270 kind: node_kind_index("file").unwrap(),
271 visibility: 0,
272 flags,
273 start_line: 1,
274 end_line: line_count,
275 start_column: 0,
276 end_column: 0,
277 name: name_ref,
278 qualified_name: qn_ref,
279 id: file_id,
280 docstring: NONE_STR,
281 signature: NONE_STR,
282 decorators: NONE_STR,
283 type_parameters: NONE_STR,
284 return_type: NONE_STR,
285 extra_json: NONE_STR,
286 });
287 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
bytesMethod · 0.80
nextMethod · 0.80
push_nodeMethod · 0.80
pushMethod · 0.80
lenMethod · 0.80
into_vecMethod · 0.80
parseFunction · 0.70
line_startsFunction · 0.70

Tested by

no test coverage detected