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

Function extract

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 14

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
visit_nodeMethod · 0.45

Tested by

no test coverage detected