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

Function extract

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

Source from the content-addressed store, hash-verified

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