Recursively walk the AST and extract nodes/edges.
(
self,
root,
source: bytes,
language: str,
file_path: str,
nodes: list[NodeInfo],
edges: list[EdgeInfo],
enclosing_class: Optional[str] = None,
enclosing_func: Optional[str] = None,
import_map: Optional[dict[str, str]] = None,
defined_names: Optional[set[str]] = None,
_depth: int = 0,
)
| 2217 | return None |
| 2218 | |
| 2219 | def _extract_from_tree( |
| 2220 | self, |
| 2221 | root, |
| 2222 | source: bytes, |
| 2223 | language: str, |
| 2224 | file_path: str, |
| 2225 | nodes: list[NodeInfo], |
| 2226 | edges: list[EdgeInfo], |
| 2227 | enclosing_class: Optional[str] = None, |
| 2228 | enclosing_func: Optional[str] = None, |
| 2229 | import_map: Optional[dict[str, str]] = None, |
| 2230 | defined_names: Optional[set[str]] = None, |
| 2231 | _depth: int = 0, |
| 2232 | ) -> None: |
| 2233 | """Recursively walk the AST and extract nodes/edges.""" |
| 2234 | if _depth > self._MAX_AST_DEPTH: |
| 2235 | return |
| 2236 | class_types = set(self._class_types.get(language, [])) |
| 2237 | func_types = set(self._function_types.get(language, [])) |
| 2238 | import_types = set(self._import_types.get(language, [])) |
| 2239 | call_types = set(self._call_types.get(language, [])) |
| 2240 | |
| 2241 | for child in root.children: |
| 2242 | node_type = child.type |
| 2243 | |
| 2244 | # --- R-specific constructs --- |
| 2245 | if language == "r" and self._extract_r_constructs( |
| 2246 | child, node_type, source, language, file_path, |
| 2247 | nodes, edges, enclosing_class, enclosing_func, |
| 2248 | import_map, defined_names, |
| 2249 | ): |
| 2250 | continue |
| 2251 | |
| 2252 | # --- Lua/Luau-specific constructs --- |
| 2253 | if language in ("lua", "luau") and self._extract_lua_constructs( |
| 2254 | child, node_type, source, language, file_path, |
| 2255 | nodes, edges, enclosing_class, enclosing_func, |
| 2256 | import_map, defined_names, _depth, |
| 2257 | ): |
| 2258 | continue |
| 2259 | |
| 2260 | # --- Bash-specific constructs --- |
| 2261 | # ``source ./foo.sh`` and ``. ./foo.sh`` are commands in |
| 2262 | # tree-sitter-bash; re-interpret them as IMPORTS_FROM edges so |
| 2263 | # cross-script wiring works the same as in other languages. |
| 2264 | if language == "bash" and node_type == "command": |
| 2265 | if self._extract_bash_source_command( |
| 2266 | child, file_path, edges, |
| 2267 | ): |
| 2268 | continue |
| 2269 | |
| 2270 | # --- Elixir-specific constructs --- |
| 2271 | # Every top-level construct in Elixir is a ``call`` node: |
| 2272 | # defmodule, def/defp/defmacro, alias/import/require/use, and |
| 2273 | # ordinary function invocations all share the same node type. |
| 2274 | # Dispatch via _extract_elixir_constructs so we can tell them |
| 2275 | # apart by the first-identifier text and still recurse into |
| 2276 | # bodies with the correct enclosing scope. See: #112 |
no test coverage detected