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

Function extract

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

grammar_forFunction · 0.85
file_node_idFunction · 0.85
node_kind_indexFunction · 0.85
namespace_nameFunction · 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

Tested by

no test coverage detected