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

Function extract

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

Source from the content-addressed store, hash-verified

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

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
putMethod · 0.80
push_nodeMethod · 0.80
lenMethod · 0.80
into_vecMethod · 0.80
line_startsFunction · 0.70
unwrapMethod · 0.60
setMethod · 0.45
textMethod · 0.45

Tested by

no test coverage detected