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