MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / extract_spec

Method extract_spec

atomic-semantic/src/parsers/go.rs:202–247  ·  view source on GitHub ↗

Extract a single const_spec or var_spec.

(
        &self,
        node: &Node,
        source: &str,
        file_path: &str,
        kind: EntityKind,
    )

Source from the content-addressed store, hash-verified

200
201 /// Extract a single const_spec or var_spec.
202 fn extract_spec(
203 &self,
204 node: &Node,
205 source: &str,
206 file_path: &str,
207 kind: EntityKind,
208 ) -> Option<Entity> {
209 let name_node = node.child_by_field_name("name")?;
210 let name = self.node_text(&name_node, source);
211
212 // Skip the blank identifier
213 if name == "_" {
214 return None;
215 }
216
217 let line = node.start_position().row as u32 + 1;
218 let end_line = node.end_position().row as u32 + 1;
219
220 let exported = name.starts_with(|c: char| c.is_uppercase());
221
222 // Build a signature from the spec text
223 let sig_text = self.node_text(node, source);
224 let sig = sig_text.lines().next().map(|l| {
225 let prefix = if kind == EntityKind::Const {
226 "const"
227 } else {
228 "var"
229 };
230 let trimmed = l.trim();
231 if trimmed.starts_with(prefix) {
232 trimmed.to_string()
233 } else {
234 format!("{} {}", prefix, trimmed)
235 }
236 });
237
238 let mut entity = Entity::new(name, kind, file_path, line, end_line);
239 if let Some(s) = sig {
240 entity = entity.with_signature(s);
241 }
242 if exported {
243 entity.exported = true;
244 }
245
246 Some(entity)
247 }
248
249 /// Extract an import declaration.
250 fn extract_import(&self, node: &Node, source: &str, file_path: &str) -> Option<Entity> {

Callers 1

extract_const_or_varMethod · 0.80

Calls 4

with_signatureMethod · 0.80
node_textMethod · 0.45
nextMethod · 0.45
linesMethod · 0.45

Tested by

no test coverage detected