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

Function extract

codegraph-kernel/src/go.rs:107–180  ·  view source on GitHub ↗
(file_path: &str, source: &str)

Source from the content-addressed store, hash-verified

105}
106
107pub fn extract(file_path: &str, source: &str) -> Result<EmitOut, String> {
108 let grammar = crate::langs::grammar_for("go").ok_or("no go grammar")?;
109 let t0 = std::time::Instant::now();
110 let mut parser = Parser::new();
111 parser
112 .set_language(&grammar)
113 .map_err(|e| format!("set_language(go) failed: {e}"))?;
114 let tree = crate::parse_budget::parse(&mut parser, source)?;
115 if tree.root_node().has_error() {
116 return Err("defer: parse tree contains errors — wasm recovery is canonical".to_string());
117 }
118
119 let mut w = Walker {
120 src: source,
121 file_path,
122 line_starts: util::line_starts(source),
123 arena: Arena::default(),
124 node_id_allocator: ids::NodeIdAllocator::default(),
125 tables: Tables::default(),
126 stack: Vec::new(),
127 nodes_meta: Vec::new(),
128 node_ids: Vec::new(),
129 defined_fn_names: HashSet::new(),
130 imported_names: HashSet::new(),
131 fn_ref_cands: Vec::new(),
132 fs_values: HashMap::new(),
133 fs_value_counts: HashMap::new(),
134 value_scopes: Vec::new(),
135 };
136
137 let line_count = source.bytes().filter(|b| *b == b'\n').count() as u32 + 1;
138 let base_name = file_path.rsplit(['/', '\\']).next().unwrap_or(file_path);
139 let mut flags = BoolFlags::default();
140 flags.set(FLAG_IS_EXPORTED, false);
141 let file_id = w.arena.put(&ids::file_node_id(file_path));
142 let name_ref = w.arena.put(base_name);
143 let qn_ref = w.arena.put(file_path);
144 w.tables.push_node(&NodeRow {
145 kind: node_kind_index("file").unwrap(),
146 visibility: 0,
147 flags,
148 start_line: 1,
149 end_line: line_count,
150 start_column: 0,
151 end_column: 0,
152 name: name_ref,
153 qualified_name: qn_ref,
154 id: file_id,
155 docstring: NONE_STR,
156 signature: NONE_STR,
157 decorators: NONE_STR,
158 type_parameters: NONE_STR,
159 return_type: NONE_STR,
160 extra_json: NONE_STR,
161 });
162 w.nodes_meta.push(NodeMeta { kind: "file", name: base_name.to_string() });
163 w.node_ids.push(ids::file_node_id(file_path));
164 w.stack.push(Scope { row: 0, kind: "file", name: base_name.to_string() });

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