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

Function extract

codegraph-kernel/src/java.rs:141–247  ·  view source on GitHub ↗
(file_path: &str, source: &str)

Source from the content-addressed store, hash-verified

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

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