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

Method extract_function

atomic-semantic/src/parsers/rust.rs:147–195  ·  view source on GitHub ↗

Extract a function definition.

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

Source from the content-addressed store, hash-verified

145
146 /// Extract a function definition.
147 fn extract_function(
148 &self,
149 node: &Node,
150 source: &str,
151 file_path: &str,
152 in_impl: Option<&str>,
153 ) -> Option<Entity> {
154 let name_node = node.child_by_field_name("name")?;
155 let name = self.node_text(&name_node, source);
156
157 let kind = if in_impl.is_some() {
158 // Check if it takes &self / &mut self / self — then it's a method
159 let has_self = node
160 .child_by_field_name("parameters")
161 .map(|params| {
162 let mut cursor = params.walk();
163 let children: Vec<_> = params.children(&mut cursor).collect();
164 children.iter().any(|c| {
165 c.kind() == "self_parameter" || self.node_text(c, source).contains("self")
166 })
167 })
168 .unwrap_or(false);
169
170 if has_self {
171 EntityKind::Method
172 } else {
173 // Associated function (no self parameter)
174 EntityKind::Function
175 }
176 } else {
177 EntityKind::Function
178 };
179
180 let line = node.start_position().row as u32 + 1;
181 let end_line = node.end_position().row as u32 + 1;
182
183 let exported = self.is_pub(node);
184 let signature = self.build_function_signature(node, source);
185
186 let mut entity = Entity::new(name, kind, file_path, line, end_line);
187 if let Some(sig) = signature {
188 entity = entity.with_signature(sig);
189 }
190 if exported {
191 entity.exported = true;
192 }
193
194 Some(entity)
195 }
196
197 /// Extract a struct definition.
198 fn extract_struct(&self, node: &Node, source: &str, file_path: &str) -> Option<Entity> {

Callers 1

walk_treeMethod · 0.45

Calls 9

walkMethod · 0.80
childrenMethod · 0.80
is_pubMethod · 0.80
with_signatureMethod · 0.80
node_textMethod · 0.45
iterMethod · 0.45
kindMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected