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

Function extract

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

Source from the content-addressed store, hash-verified

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

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