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

Function extract

codegraph-kernel/src/php.rs:161–269  ·  view source on GitHub ↗
(file_path: &str, source: &str)

Source from the content-addressed store, hash-verified

159}
160
161pub fn extract(file_path: &str, source: &str) -> Result<EmitOut, String> {
162 let grammar = crate::langs::grammar_for("php").ok_or("no php grammar")?;
163 let t0 = std::time::Instant::now();
164 let mut parser = Parser::new();
165 parser
166 .set_language(&grammar)
167 .map_err(|e| format!("set_language(php) failed: {e}"))?;
168 let tree = crate::parse_budget::parse(&mut parser, source)?;
169 if tree.root_node().has_error() {
170 return Err("defer: parse tree contains errors — wasm recovery is canonical".to_string());
171 }
172
173 let root = tree.root_node();
174 let mut w = Walker {
175 src: source,
176 file_path,
177 line_starts: util::line_starts(source),
178 arena: Arena::default(),
179 node_id_allocator: ids::NodeIdAllocator::default(),
180 tables: Tables::default(),
181 stack: Vec::new(),
182 node_ids: Vec::new(),
183 defined_fn_names: HashSet::new(),
184 imported_names: HashSet::new(),
185 fn_ref_cands: Vec::new(),
186 fs_values: HashMap::new(),
187 fs_value_counts: HashMap::new(),
188 value_scopes: Vec::new(),
189 root,
190 dirname_shadowed: None,
191 };
192
193 let line_count = source.bytes().filter(|b| *b == b'\n').count() as u32 + 1;
194 let base_name = file_path.rsplit(['/', '\\']).next().unwrap_or(file_path);
195 let mut flags = BoolFlags::default();
196 flags.set(FLAG_IS_EXPORTED, false);
197 let file_id = w.arena.put(&ids::file_node_id(file_path));
198 let name_ref = w.arena.put(base_name);
199 let qn_ref = w.arena.put(file_path);
200 w.tables.push_node(&NodeRow {
201 kind: node_kind_index("file").unwrap(),
202 visibility: 0,
203 flags,
204 start_line: 1,
205 end_line: line_count,
206 start_column: 0,
207 end_column: 0,
208 name: name_ref,
209 qualified_name: qn_ref,
210 id: file_id,
211 docstring: NONE_STR,
212 signature: NONE_STR,
213 decorators: NONE_STR,
214 type_parameters: NONE_STR,
215 return_type: NONE_STR,
216 extra_json: NONE_STR,
217 });
218 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