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

Function extract

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

Source from the content-addressed store, hash-verified

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