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

Function extract

codegraph-kernel/src/csharp.rs:146–256  ·  view source on GitHub ↗
(file_path: &str, source: &str)

Source from the content-addressed store, hash-verified

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