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

Function extract

codegraph-kernel/src/rustlang.rs:136–209  ·  view source on GitHub ↗
(file_path: &str, source: &str)

Source from the content-addressed store, hash-verified

134}
135
136pub fn extract(file_path: &str, source: &str) -> Result<EmitOut, String> {
137 let grammar = crate::langs::grammar_for("rust").ok_or("no rust grammar")?;
138 let t0 = std::time::Instant::now();
139 let mut parser = Parser::new();
140 parser
141 .set_language(&grammar)
142 .map_err(|e| format!("set_language(rust) failed: {e}"))?;
143 let tree = crate::parse_budget::parse(&mut parser, source)?;
144 if tree.root_node().has_error() {
145 return Err("defer: parse tree contains errors — wasm recovery is canonical".to_string());
146 }
147
148 let mut w = Walker {
149 src: source,
150 file_path,
151 line_starts: util::line_starts(source),
152 arena: Arena::default(),
153 node_id_allocator: ids::NodeIdAllocator::default(),
154 tables: Tables::default(),
155 stack: Vec::new(),
156 nodes_meta: Vec::new(),
157 node_ids: Vec::new(),
158 defined_fn_names: HashSet::new(),
159 imported_names: HashSet::new(),
160 fn_ref_cands: Vec::new(),
161 fs_values: HashMap::new(),
162 fs_value_counts: HashMap::new(),
163 value_scopes: Vec::new(),
164 };
165
166 let line_count = source.bytes().filter(|b| *b == b'\n').count() as u32 + 1;
167 let base_name = file_path.rsplit(['/', '\\']).next().unwrap_or(file_path);
168 let mut flags = BoolFlags::default();
169 flags.set(FLAG_IS_EXPORTED, false);
170 let file_id = w.arena.put(&ids::file_node_id(file_path));
171 let name_ref = w.arena.put(base_name);
172 let qn_ref = w.arena.put(file_path);
173 w.tables.push_node(&NodeRow {
174 kind: node_kind_index("file").unwrap(),
175 visibility: 0,
176 flags,
177 start_line: 1,
178 end_line: line_count,
179 start_column: 0,
180 end_column: 0,
181 name: name_ref,
182 qualified_name: qn_ref,
183 id: file_id,
184 docstring: NONE_STR,
185 signature: NONE_STR,
186 decorators: NONE_STR,
187 type_parameters: NONE_STR,
188 return_type: NONE_STR,
189 extra_json: NONE_STR,
190 });
191 w.nodes_meta.push(NodeMeta { kind: "file", name: base_name.to_string() });
192 w.node_ids.push(ids::file_node_id(file_path));
193 w.stack.push(Scope { row: 0, kind: "file", name: base_name.to_string() });

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