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

Function extract

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

Source from the content-addressed store, hash-verified

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