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

Function extract

codegraph-kernel/src/ruby.rs:136–207  ·  view source on GitHub ↗
(file_path: &str, source: &str)

Source from the content-addressed store, hash-verified

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

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
bytesMethod · 0.80
nextMethod · 0.80
push_nodeMethod · 0.80
pushMethod · 0.80
lenMethod · 0.80
into_vecMethod · 0.80
parseFunction · 0.70
line_startsFunction · 0.70

Tested by

no test coverage detected