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

Method extract_function

atomic-semantic/src/parsers/swift.rs:203–236  ·  view source on GitHub ↗

Extract a function or method declaration.

(
        &self,
        node: &Node,
        source: &str,
        file_path: &str,
        in_type: Option<&str>,
    )

Source from the content-addressed store, hash-verified

201
202 /// Extract a function or method declaration.
203 fn extract_function(
204 &self,
205 node: &Node,
206 source: &str,
207 file_path: &str,
208 in_type: Option<&str>,
209 ) -> Option<Entity> {
210 // Try named field first, fall back to first `simple_identifier` child
211 let name = if let Some(n) = node.child_by_field_name("name") {
212 self.node_text(&n, source)
213 } else {
214 self.find_first_simple_identifier(node, source)?
215 };
216
217 let kind = if in_type.is_some() {
218 EntityKind::Method
219 } else {
220 EntityKind::Function
221 };
222
223 let line = node.start_position().row as u32 + 1;
224 let end_line = node.end_position().row as u32 + 1;
225
226 let exported = self.is_exported(node, source);
227 let signature = self.build_function_signature(node, source);
228
229 let mut entity = Entity::new(name, kind, file_path, line, end_line);
230 if let Some(sig) = signature {
231 entity = entity.with_signature(sig);
232 }
233 entity.exported = exported;
234
235 Some(entity)
236 }
237
238 /// Extract an `init` declaration.
239 ///

Callers 1

walk_treeMethod · 0.45

Calls 5

is_exportedMethod · 0.80
with_signatureMethod · 0.80
node_textMethod · 0.45

Tested by

no test coverage detected