devlensio 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extractors/runner.js +1 -0
- package/dist/extractors/types.d.ts +2 -1
- package/dist/graph/buildLookup.d.ts +30 -0
- package/dist/graph/buildLookup.js +36 -1
- package/dist/graph/edges/aliasChain.d.ts +7 -0
- package/dist/graph/edges/aliasChain.js +63 -0
- package/dist/graph/edges/aliasResolution.test.d.ts +1 -0
- package/dist/graph/edges/aliasResolution.test.js +351 -0
- package/dist/graph/edges/callEdges.js +101 -15
- package/dist/graph/edges/callEdges.test.js +119 -0
- package/dist/graph/edges/importEdges.js +124 -0
- package/dist/parser/declarationIds.d.ts +23 -0
- package/dist/parser/declarationIds.js +123 -0
- package/dist/parser/exportsMap.d.ts +9 -0
- package/dist/parser/exportsMap.js +260 -0
- package/dist/parser/exportsMap.test.d.ts +1 -0
- package/dist/parser/exportsMap.test.js +324 -0
- package/dist/parser/extractors/functions.d.ts +11 -0
- package/dist/parser/extractors/functions.js +69 -59
- package/dist/parser/extractors/moduleScope.d.ts +8 -0
- package/dist/parser/extractors/moduleScope.js +80 -0
- package/dist/parser/index.d.ts +2 -1
- package/dist/parser/index.js +45 -0
- package/dist/parser/moduleScope.test.d.ts +1 -0
- package/dist/parser/moduleScope.test.js +174 -0
- package/dist/pipeline/index.d.ts +2 -1
- package/dist/pipeline/index.js +1 -0
- package/dist/storage/fileStorage.d.ts +2 -1
- package/dist/storage/fileStorage.js +5 -1
- package/dist/storage/fileStorage.test.d.ts +1 -0
- package/dist/storage/fileStorage.test.js +112 -0
- package/dist/types.d.ts +4 -0
- package/extractors/go/bin/darwin-amd64/devlens_go_extractor +0 -0
- package/extractors/go/bin/darwin-arm64/devlens_go_extractor +0 -0
- package/extractors/go/bin/linux-amd64/devlens_go_extractor +0 -0
- package/extractors/go/bin/linux-arm64/devlens_go_extractor +0 -0
- package/extractors/go/bin/windows-amd64/devlens_go_extractor.exe +0 -0
- package/extractors/go/calls.go +45 -3
- package/extractors/go/parser.go +81 -36
- package/extractors/java/devlens_java_extractor.jar +0 -0
- package/extractors/java/src/devlens/extractor/Extractor.java +16 -2
- package/extractors/java/src/devlens/extractor/LookupMaps.java +2 -0
- package/extractors/java/src/devlens/extractor/Parser.java +33 -1
- package/extractors/java/src/devlens/extractor/edges/Calls.java +44 -0
- package/extractors/python/devlens_extractors_python/edges/calls.py +173 -33
- package/extractors/python/devlens_extractors_python/edges/imports.py +21 -1
- package/extractors/python/devlens_extractors_python/lookup.py +9 -0
- package/extractors/python/devlens_extractors_python/parser/__init__.py +10 -1
- package/extractors/rust/bin/darwin-amd64/devlens_rust_extractor +0 -0
- package/extractors/rust/bin/darwin-arm64/devlens_rust_extractor +0 -0
- package/extractors/rust/bin/linux-amd64/devlens_rust_extractor +0 -0
- package/extractors/rust/bin/linux-arm64/devlens_rust_extractor +0 -0
- package/extractors/rust/bin/windows-amd64/devlens_rust_extractor.exe +0 -0
- package/extractors/rust/src/calls.rs +32 -0
- package/extractors/rust/src/lookup.rs +66 -0
- package/package.json +1 -1
|
@@ -5,9 +5,16 @@ Consumes the shared LookupMaps (lookup.py). Resolution ladder:
|
|
|
5
5
|
ClassName.method → same-file dotted lookup
|
|
6
6
|
alias.member → lazy [pip]/pkg::member node
|
|
7
7
|
module-alias.walk → submodule walk via module_map
|
|
8
|
-
plain name →
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
plain name → own file → import binding → global name
|
|
9
|
+
|
|
10
|
+
Aliasing (added 2026-10): a name at a call site is not always the name of a
|
|
11
|
+
declaration. `from .http import data as httpResponse` and a barrel that only
|
|
12
|
+
re-exports (`__init__.py: from .http import data`) mean the caller writes
|
|
13
|
+
`httpResponse` while the node is `http.py::data`. Python has no compiler symbol
|
|
14
|
+
table, so the chain is walked here by `_resolve_in_module()`: it asks a module
|
|
15
|
+
for a name, and when the module only *binds* that name from somewhere else, it
|
|
16
|
+
follows the binding — cycle-guarded, depth-capped, memo-free (chains are short
|
|
17
|
+
and every hop is an O(1) dict hit).
|
|
11
18
|
|
|
12
19
|
Overload-aware tiebreak (mirrors src/graph/edges/callEdges.ts): when a lookup
|
|
13
20
|
returns multiple same-name candidates, the call site's argument shape picks
|
|
@@ -16,9 +23,22 @@ legacy closest-by-path heuristic. The edge records matchedBy.
|
|
|
16
23
|
"""
|
|
17
24
|
from __future__ import annotations
|
|
18
25
|
|
|
26
|
+
from dataclasses import dataclass, field
|
|
27
|
+
|
|
19
28
|
from ..lookup import LookupMaps, closest_by_path, module_name
|
|
20
29
|
from ..third_party import ThirdPartyRegistry
|
|
21
30
|
|
|
31
|
+
# Re-export chains are short in practice; the cap exists so a pathological
|
|
32
|
+
# barrel ring cannot loop. Cycles are also caught by `seen`.
|
|
33
|
+
MAX_ALIAS_HOPS = 24
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass
|
|
37
|
+
class _Scoped:
|
|
38
|
+
"""Result of resolving a name against one module's export surface."""
|
|
39
|
+
candidates: list[tuple[str, str]] = field(default_factory=list) # (node_id, rel)
|
|
40
|
+
chain: list[str] = field(default_factory=list) # file::name hops
|
|
41
|
+
|
|
22
42
|
|
|
23
43
|
def _find_in_file(lookup: LookupMaps, rel: str, name: str) -> str | None:
|
|
24
44
|
return lookup.nodes_by_file.get(rel, {}).get(name)
|
|
@@ -30,6 +50,69 @@ def _find_all_in_file(lookup: LookupMaps, rel: str, name: str) -> list[tuple[str
|
|
|
30
50
|
return [(node_id, rel) for node_id in ids]
|
|
31
51
|
|
|
32
52
|
|
|
53
|
+
def _resolve_in_module(lookup: LookupMaps, rel: str, name: str,
|
|
54
|
+
seen: set[tuple[str, str]] | None = None) -> _Scoped:
|
|
55
|
+
"""Resolve `name` against the EXPORT SURFACE of module `rel`.
|
|
56
|
+
|
|
57
|
+
In Python a module's namespace is its declarations PLUS everything it
|
|
58
|
+
imported, so `from pkg import name` works whenever `name` is a module-level
|
|
59
|
+
attribute of `pkg` — including names `pkg` itself imported from elsewhere.
|
|
60
|
+
That is exactly how a package re-exports a symbol (`__init__.py`), and it is
|
|
61
|
+
the phenomenon this resolver models:
|
|
62
|
+
|
|
63
|
+
1. declared here → the node
|
|
64
|
+
2. `Alias.member` where Alias is bound → resolve Alias, then the member
|
|
65
|
+
3. bound by an import → recurse into the binding's target
|
|
66
|
+
4. `from .x import *` sources → recurse with the same name
|
|
67
|
+
"""
|
|
68
|
+
seen = seen if seen is not None else set()
|
|
69
|
+
key = (rel, name)
|
|
70
|
+
if key in seen or len(seen) >= MAX_ALIAS_HOPS:
|
|
71
|
+
return _Scoped()
|
|
72
|
+
seen.add(key)
|
|
73
|
+
|
|
74
|
+
# 1. a declaration in this module (dotted names included: "Class.method")
|
|
75
|
+
declared = _find_all_in_file(lookup, rel, name)
|
|
76
|
+
if declared:
|
|
77
|
+
return _Scoped(declared, [f"{rel}::{name}"])
|
|
78
|
+
|
|
79
|
+
symbols = lookup.symbol_maps.get(rel, {})
|
|
80
|
+
names = lookup.symbol_names.get(rel, {})
|
|
81
|
+
|
|
82
|
+
# 2. member access on a bound name: `US.get` → resolve `US`
|
|
83
|
+
if "." in name:
|
|
84
|
+
root, suffix = name.split(".", 1)
|
|
85
|
+
binding = symbols.get(root)
|
|
86
|
+
if binding and binding.startswith("file::"):
|
|
87
|
+
original = names.get(root, root)
|
|
88
|
+
deeper = _resolve_in_module(lookup, binding[len("file::"):],
|
|
89
|
+
f"{original}.{suffix}", seen)
|
|
90
|
+
if deeper.candidates:
|
|
91
|
+
return _Scoped(deeper.candidates, [f"{rel}::{name}"] + deeper.chain)
|
|
92
|
+
return _Scoped()
|
|
93
|
+
|
|
94
|
+
# 3. a module-level binding created by an import — the re-export hop
|
|
95
|
+
binding = symbols.get(name)
|
|
96
|
+
if binding:
|
|
97
|
+
original = names.get(name, name)
|
|
98
|
+
if binding.startswith("file::"):
|
|
99
|
+
deeper = _resolve_in_module(lookup, binding[len("file::"):], original, seen)
|
|
100
|
+
if deeper.candidates:
|
|
101
|
+
return _Scoped(deeper.candidates, [f"{rel}::{name}"] + deeper.chain)
|
|
102
|
+
return _Scoped()
|
|
103
|
+
# third-party node id or a direct node id — nothing to walk
|
|
104
|
+
origin_rel = lookup.node_by_id.get(binding, {}).get("filePath", rel)
|
|
105
|
+
return _Scoped([(binding, origin_rel)], [f"{rel}::{name}"])
|
|
106
|
+
|
|
107
|
+
# 4. star imports copy public names into this namespace
|
|
108
|
+
for star_rel in lookup.star_imports.get(rel, []):
|
|
109
|
+
deeper = _resolve_in_module(lookup, star_rel, name, seen)
|
|
110
|
+
if deeper.candidates:
|
|
111
|
+
return _Scoped(deeper.candidates, [f"{rel}::{name}"] + deeper.chain)
|
|
112
|
+
|
|
113
|
+
return _Scoped()
|
|
114
|
+
|
|
115
|
+
|
|
33
116
|
def _bound_params(node: dict) -> tuple[list, list]:
|
|
34
117
|
"""(effective_params, effective_parameters) for arity/type matching —
|
|
35
118
|
bound methods hide self/cls from the call site's argument count."""
|
|
@@ -114,9 +197,22 @@ def _pick(candidates: list[tuple[str, str]], node: dict, call_site: dict | None,
|
|
|
114
197
|
return closest_by_path(pool, rel), "name"
|
|
115
198
|
|
|
116
199
|
|
|
117
|
-
def
|
|
200
|
+
def _pick3(candidates: list[tuple[str, str]], node: dict, call_site: dict | None,
|
|
201
|
+
lookup: LookupMaps, rel: str, chain: list[str]) -> tuple[str | None, str, list[str]]:
|
|
202
|
+
"""_pick() plus the alias chain — the shape _resolve() returns."""
|
|
203
|
+
target, matched_by = _pick(candidates, node, call_site, lookup, rel)
|
|
204
|
+
return target, matched_by, chain
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def _walk_module(lookup: LookupMaps, alias_target: str, rest: str,
|
|
208
|
+
root_hint: str | None = None) -> _Scoped:
|
|
118
209
|
"""'user.User' with alias → file::models/__init__.py: consume submodule
|
|
119
|
-
segments via module_map, then
|
|
210
|
+
segments via module_map, then resolve the symbol in the final module's
|
|
211
|
+
export surface (which may itself re-export it).
|
|
212
|
+
|
|
213
|
+
`root_hint` is what the alias was called at the source
|
|
214
|
+
(`from .services import UserService as US` → "UserService"), so a member
|
|
215
|
+
call `US.get()` resolves to the dotted node `UserService.get`."""
|
|
120
216
|
current_rel = alias_target[len("file::"):]
|
|
121
217
|
current_module = module_name(current_rel)
|
|
122
218
|
segments = rest.split(".")
|
|
@@ -130,21 +226,29 @@ def _walk_module(lookup: LookupMaps, alias_target: str, rest: str) -> list[tuple
|
|
|
130
226
|
current_rel, current_module = nxt, candidate
|
|
131
227
|
consumed += 1
|
|
132
228
|
|
|
133
|
-
|
|
229
|
+
tail = ".".join(segments[consumed:])
|
|
230
|
+
if root_hint and consumed == 0 and tail:
|
|
231
|
+
scoped = _resolve_in_module(lookup, current_rel, f"{root_hint}.{tail}")
|
|
232
|
+
if scoped.candidates:
|
|
233
|
+
return scoped
|
|
234
|
+
return _resolve_in_module(lookup, current_rel, tail)
|
|
134
235
|
|
|
135
236
|
|
|
136
237
|
def _resolve(called: str, node: dict, lookup: LookupMaps,
|
|
137
|
-
registry: ThirdPartyRegistry,
|
|
238
|
+
registry: ThirdPartyRegistry,
|
|
239
|
+
call_site: dict | None) -> tuple[str | None, str, list[str]]:
|
|
138
240
|
rel = node["filePath"]
|
|
139
241
|
symbols = lookup.symbol_maps.get(rel, {})
|
|
242
|
+
symbol_names = lookup.symbol_names.get(rel, {})
|
|
140
243
|
|
|
141
244
|
# ── 1. self.x() / cls.x() → method of the enclosing class ──
|
|
142
245
|
if called.startswith(("self.", "cls.")):
|
|
143
246
|
parent_class = node["metadata"].get("parentClass")
|
|
144
247
|
if parent_class:
|
|
145
|
-
return
|
|
146
|
-
|
|
147
|
-
|
|
248
|
+
return _pick3(_find_all_in_file(lookup, rel,
|
|
249
|
+
f"{parent_class}.{called.split('.', 1)[1]}"),
|
|
250
|
+
node, call_site, lookup, rel, [])
|
|
251
|
+
return None, "name", []
|
|
148
252
|
|
|
149
253
|
# ── 2. dotted name ──
|
|
150
254
|
if "." in called:
|
|
@@ -152,40 +256,63 @@ def _resolve(called: str, node: dict, lookup: LookupMaps,
|
|
|
152
256
|
|
|
153
257
|
# 2a. ClassName.method defined in the same file
|
|
154
258
|
if root in lookup.nodes_by_file.get(rel, {}):
|
|
155
|
-
return
|
|
156
|
-
|
|
259
|
+
return _pick3(_find_all_in_file(lookup, rel, called),
|
|
260
|
+
node, call_site, lookup, rel, [])
|
|
157
261
|
|
|
158
|
-
# 2b. member access through an import alias
|
|
159
262
|
alias_target = symbols.get(root)
|
|
160
263
|
if not alias_target:
|
|
161
|
-
|
|
264
|
+
# 2c. the root itself may be re-exported into THIS module
|
|
265
|
+
scoped = _resolve_in_module(lookup, rel, called)
|
|
266
|
+
if scoped.candidates:
|
|
267
|
+
return _pick3(scoped.candidates, node, call_site, lookup, rel, scoped.chain)
|
|
268
|
+
return None, "name", []
|
|
269
|
+
|
|
162
270
|
if alias_target.startswith("[pip]/"):
|
|
163
271
|
# third-party chain: requests.get → lazily create [pip]/requests::get
|
|
164
272
|
pkg = alias_target.split("/", 1)[1]
|
|
165
273
|
if "::" in pkg:
|
|
166
274
|
# chain root is already a named import — current_app.logger.info
|
|
167
275
|
# → [pip]/flask::current_app (the meaningful hop)
|
|
168
|
-
return alias_target, "name"
|
|
276
|
+
return alias_target, "name", []
|
|
169
277
|
member = registry.method_node(pkg, rest.split(".")[0])
|
|
170
|
-
return (member["id"] if member else None), "name"
|
|
171
|
-
if alias_target.startswith("file::"):
|
|
172
|
-
return _pick(_walk_module(lookup, alias_target, rest),
|
|
173
|
-
node, call_site, lookup, rel)
|
|
174
|
-
return None, "name"
|
|
175
|
-
|
|
176
|
-
# ── 3. plain name — global lookup, overload ladder on collision ──
|
|
177
|
-
candidates = lookup.nodes_by_name.get(called)
|
|
178
|
-
if candidates:
|
|
179
|
-
return _pick(candidates, node, call_site, lookup, rel)
|
|
278
|
+
return (member["id"] if member else None), "name", []
|
|
180
279
|
|
|
181
|
-
|
|
280
|
+
if alias_target.startswith("file::"):
|
|
281
|
+
# 2b. member access through an import alias — resolve against the
|
|
282
|
+
# target module's export surface (follows re-export chains)
|
|
283
|
+
scoped = _walk_module(lookup, alias_target, rest, symbol_names.get(root))
|
|
284
|
+
if scoped.candidates:
|
|
285
|
+
return _pick3(scoped.candidates, node, call_site, lookup, rel, scoped.chain)
|
|
286
|
+
return None, "name", []
|
|
287
|
+
|
|
288
|
+
# ── 3. plain name ──
|
|
289
|
+
# 3a. declared in the caller's own file (exact, no guessing)
|
|
290
|
+
local = _find_all_in_file(lookup, rel, called)
|
|
291
|
+
if local:
|
|
292
|
+
return _pick3(local, node, call_site, lookup, rel, [])
|
|
293
|
+
|
|
294
|
+
# 3b. imported into this file → the target module's export surface
|
|
182
295
|
alias_target = symbols.get(called)
|
|
183
296
|
if alias_target:
|
|
184
297
|
if alias_target.startswith("file::"):
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
298
|
+
scoped = _resolve_in_module(lookup, alias_target[len("file::"):], called)
|
|
299
|
+
if scoped.candidates:
|
|
300
|
+
return _pick3(scoped.candidates, node, call_site, lookup, rel, scoped.chain)
|
|
301
|
+
return None, "name", []
|
|
302
|
+
# direct node id ("path.py::Symbol" or a third-party id, e.g. decorators)
|
|
303
|
+
return alias_target, "name", []
|
|
304
|
+
|
|
305
|
+
# 3c. global name — overload ladder on collision
|
|
306
|
+
candidates = lookup.nodes_by_name.get(called)
|
|
307
|
+
if candidates:
|
|
308
|
+
return _pick3(candidates, node, call_site, lookup, rel, [])
|
|
309
|
+
|
|
310
|
+
# 3d. copied into this namespace by `from .x import *`
|
|
311
|
+
scoped = _resolve_in_module(lookup, rel, called)
|
|
312
|
+
if scoped.candidates:
|
|
313
|
+
return _pick3(scoped.candidates, node, call_site, lookup, rel, scoped.chain)
|
|
314
|
+
|
|
315
|
+
return None, "name", []
|
|
189
316
|
|
|
190
317
|
|
|
191
318
|
def resolve_calls(lookup: LookupMaps, registry: ThirdPartyRegistry) -> list[dict]:
|
|
@@ -196,17 +323,30 @@ def resolve_calls(lookup: LookupMaps, registry: ThirdPartyRegistry) -> list[dict
|
|
|
196
323
|
edges: list[dict] = []
|
|
197
324
|
|
|
198
325
|
for node in lookup.node_by_id.values():
|
|
199
|
-
|
|
326
|
+
# FILE nodes are callers for module-scope execution (calls run at
|
|
327
|
+
# import time, attached by parser/__init__.py). TEST leaves excluded.
|
|
328
|
+
if node["type"] not in ("FUNCTION", "METHOD", "FILE"):
|
|
200
329
|
continue
|
|
201
330
|
metadata = node["metadata"]
|
|
202
331
|
sites = metadata.get("callSites") or [{"name": c} for c in metadata.get("calls", [])]
|
|
203
332
|
resolved: list[dict] = []
|
|
204
333
|
for site in sites:
|
|
205
334
|
called = site["name"]
|
|
206
|
-
target, matched_by = _resolve(called, node, lookup, registry, site)
|
|
335
|
+
target, matched_by, chain = _resolve(called, node, lookup, registry, site)
|
|
207
336
|
if target and target != node["id"]:
|
|
337
|
+
edge_meta = {"calledName": called, "matchedBy": matched_by}
|
|
338
|
+
origin = lookup.node_by_id.get(target, {})
|
|
339
|
+
origin_name = origin.get("name")
|
|
340
|
+
if origin_name and origin_name != called:
|
|
341
|
+
# what the graph edge actually points at (alias → origin)
|
|
342
|
+
edge_meta["resolvedName"] = origin_name
|
|
343
|
+
edge_meta["aliased"] = True
|
|
344
|
+
if chain and len(chain) > 1:
|
|
345
|
+
edge_meta["aliasChain"] = chain
|
|
346
|
+
if node["type"] == "FILE":
|
|
347
|
+
edge_meta["scope"] = "module"
|
|
208
348
|
edges.append({"from": node["id"], "to": target, "type": "CALLS",
|
|
209
|
-
"metadata":
|
|
349
|
+
"metadata": edge_meta})
|
|
210
350
|
resolved.append({"name": called, "nodeId": target})
|
|
211
351
|
metadata["resolvedCalls"] = resolved
|
|
212
352
|
|
|
@@ -81,6 +81,14 @@ def resolve_file_imports(parsed: ParsedFile, lookup: LookupMaps,
|
|
|
81
81
|
rel = parsed.rel_path
|
|
82
82
|
file_id = parsed.file_node["id"]
|
|
83
83
|
file_symbols: dict[str, str] = {}
|
|
84
|
+
# local alias → the name it was imported AS in the source module
|
|
85
|
+
# (`from .http import data as httpResponse` → {"httpResponse": "data"}).
|
|
86
|
+
# Without it a re-export chain cannot be followed: symbol_maps only knows
|
|
87
|
+
# the destination file, not what to look for once we get there.
|
|
88
|
+
file_names: dict[str, str] = {}
|
|
89
|
+
# `from .x import *` sources — Python copies public names into the module
|
|
90
|
+
# namespace, so these participate in the export surface.
|
|
91
|
+
star_sources: list[str] = []
|
|
84
92
|
edges: list[dict] = []
|
|
85
93
|
imported_paths: list[str] = []
|
|
86
94
|
module_map = lookup.module_map
|
|
@@ -101,6 +109,7 @@ def resolve_file_imports(parsed: ParsedFile, lookup: LookupMaps,
|
|
|
101
109
|
sub = module_map.get(f"{module}.{item.name}")
|
|
102
110
|
if sub:
|
|
103
111
|
file_symbols[item.alias] = f"file::{sub}"
|
|
112
|
+
file_names[item.alias] = item.alias
|
|
104
113
|
imported_paths.append(sub)
|
|
105
114
|
edges.append({"from": file_id, "to": f"file::{sub}", "type": "IMPORTS",
|
|
106
115
|
"metadata": {"importPath": module, "importedName": item.name}})
|
|
@@ -113,7 +122,10 @@ def resolve_file_imports(parsed: ParsedFile, lookup: LookupMaps,
|
|
|
113
122
|
imported_paths.append(target_rel)
|
|
114
123
|
|
|
115
124
|
if item.is_star:
|
|
116
|
-
# Can't know which names — edge to the module file, tag ambiguous
|
|
125
|
+
# Can't know which names — edge to the module file, tag ambiguous.
|
|
126
|
+
# The source is recorded so name resolution can still fall
|
|
127
|
+
# through to it (Python copies public names into the namespace).
|
|
128
|
+
star_sources.append(target_rel)
|
|
117
129
|
edges.append({"from": file_id, "to": target_file_id, "type": "IMPORTS",
|
|
118
130
|
"metadata": {"importPath": module, "isStarImport": True}})
|
|
119
131
|
continue
|
|
@@ -126,6 +138,10 @@ def resolve_file_imports(parsed: ParsedFile, lookup: LookupMaps,
|
|
|
126
138
|
imported_paths.append(sub)
|
|
127
139
|
|
|
128
140
|
file_symbols[item.alias] = target_file_id
|
|
141
|
+
# What this binding is called inside the target module — the next
|
|
142
|
+
# link of a re-export chain (`from .index import httpResponse`
|
|
143
|
+
# where index.py did `from .http import data as httpResponse`).
|
|
144
|
+
file_names[item.alias] = item.name or item.alias
|
|
129
145
|
edges.append({"from": file_id, "to": target_file_id, "type": "IMPORTS",
|
|
130
146
|
"metadata": {"importPath": module,
|
|
131
147
|
"importedName": item.name}})
|
|
@@ -152,4 +168,8 @@ def resolve_file_imports(parsed: ParsedFile, lookup: LookupMaps,
|
|
|
152
168
|
"importedName": item.name}})
|
|
153
169
|
|
|
154
170
|
symbol_map[rel] = file_symbols
|
|
171
|
+
if file_names:
|
|
172
|
+
lookup.symbol_names[rel] = file_names
|
|
173
|
+
if star_sources:
|
|
174
|
+
lookup.star_imports[rel] = star_sources
|
|
155
175
|
return edges, sorted(set(imported_paths))
|
|
@@ -29,6 +29,15 @@ class LookupMaps:
|
|
|
29
29
|
file_nodes_by_path: dict[str, dict] = field(default_factory=dict)
|
|
30
30
|
# rel_path → {local alias → target id} — import precision (edges.imports writes)
|
|
31
31
|
symbol_maps: dict[str, dict[str, str]] = field(default_factory=dict)
|
|
32
|
+
# rel_path → {local alias → ORIGINAL imported name}. `symbol_maps` says
|
|
33
|
+
# WHERE a name came from; this says WHAT it was called there, which is what
|
|
34
|
+
# makes `from .http import data as httpResponse` chains resolvable
|
|
35
|
+
# (edges.imports writes).
|
|
36
|
+
symbol_names: dict[str, dict[str, str]] = field(default_factory=dict)
|
|
37
|
+
# rel_path → [rel_path] for `from .x import *` sources. Python's star import
|
|
38
|
+
# copies public names into the module namespace, so a barrel that only does
|
|
39
|
+
# `from .inner import *` still re-exports (edges.imports writes).
|
|
40
|
+
star_imports: dict[str, list[str]] = field(default_factory=dict)
|
|
32
41
|
# dotted module name → rel path (imports.build_module_map builds)
|
|
33
42
|
module_map: dict[str, str] = field(default_factory=dict)
|
|
34
43
|
|
|
@@ -12,7 +12,7 @@ from pathlib import Path
|
|
|
12
12
|
|
|
13
13
|
from ..contract import code_hash, file_node
|
|
14
14
|
from .classes import extract_class
|
|
15
|
-
from .functions import extract_function
|
|
15
|
+
from .functions import extract_function, extract_calls_with_sites
|
|
16
16
|
from .overloads import apply_overload_disambiguation
|
|
17
17
|
from .walker import is_test_file, walk_python_files
|
|
18
18
|
|
|
@@ -70,6 +70,15 @@ def parse_file(repo_path: str, rel_path: str) -> ParsedFile:
|
|
|
70
70
|
else:
|
|
71
71
|
file_node_["metadata"]["nodeCount"] = len(children)
|
|
72
72
|
file_node_["metadata"]["childNodeIds"] = [c["id"] for c in children]
|
|
73
|
+
|
|
74
|
+
# Module-scope calls (executed at import time) belong to the FILE node.
|
|
75
|
+
# _walk_scope already refuses to descend into defs/classes/lambdas, so
|
|
76
|
+
# running it on the module body yields exactly the top-level calls.
|
|
77
|
+
module_calls, module_sites = extract_calls_with_sites(tree.body)
|
|
78
|
+
if module_sites:
|
|
79
|
+
file_node_["metadata"]["calls"] = module_calls
|
|
80
|
+
file_node_["metadata"]["callSites"] = module_sites
|
|
81
|
+
|
|
73
82
|
joined = "\n".join(c.get("rawCode", "") for c in children)
|
|
74
83
|
if joined.strip():
|
|
75
84
|
file_node_["codeHash"] = code_hash(joined)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -72,6 +72,28 @@ pub fn detect_calls(
|
|
|
72
72
|
serde_json::Value::from(site.name.clone()),
|
|
73
73
|
);
|
|
74
74
|
meta.insert("matchedBy".to_string(), serde_json::Value::from(matched_by));
|
|
75
|
+
// What the edge actually points at: for a re-exported alias
|
|
76
|
+
// this differs from the name written at the call site.
|
|
77
|
+
if let Some(origin) = lookup.node_by_id.get(&target) {
|
|
78
|
+
// compare the FINAL path segment: `US::get` calling
|
|
79
|
+
// `UserService.get` is a receiver rename, not a symbol
|
|
80
|
+
// rename — only a real alias gets the flag
|
|
81
|
+
let called_leaf = site
|
|
82
|
+
.name
|
|
83
|
+
.rsplit("::")
|
|
84
|
+
.next()
|
|
85
|
+
.unwrap_or(&site.name)
|
|
86
|
+
.rsplit('.')
|
|
87
|
+
.next()
|
|
88
|
+
.unwrap_or(&site.name);
|
|
89
|
+
if origin.name != called_leaf {
|
|
90
|
+
meta.insert(
|
|
91
|
+
"resolvedName".to_string(),
|
|
92
|
+
serde_json::Value::from(origin.name.clone()),
|
|
93
|
+
);
|
|
94
|
+
meta.insert("aliased".to_string(), serde_json::Value::from(true));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
75
97
|
edges.push(edge_with_meta(&from, &target, "CALLS", meta));
|
|
76
98
|
resolved.push(target);
|
|
77
99
|
}
|
|
@@ -153,6 +175,16 @@ pub fn resolve_path_call(
|
|
|
153
175
|
if let Some(res) = lookup.closest_by_path_arity(segs[0], rel_path, arg_count) {
|
|
154
176
|
return Some(res);
|
|
155
177
|
}
|
|
178
|
+
// the name may be a RE-EXPORT, not a declaration:
|
|
179
|
+
// `pub use inner::realOriginal as alias01;` + `alias01()`, or a chain
|
|
180
|
+
// of aliases hopping through many modules. No node is named alias01,
|
|
181
|
+
// so the crate-wide index above cannot see it — walk the bindings.
|
|
182
|
+
let mut seen = std::collections::HashSet::new();
|
|
183
|
+
if let Some(id) = crate::lookup::resolve_bound_name(
|
|
184
|
+
lookup, module_map, rel_path, segs[0], 0, &mut seen,
|
|
185
|
+
) {
|
|
186
|
+
return Some((id, "name"));
|
|
187
|
+
}
|
|
156
188
|
return None;
|
|
157
189
|
}
|
|
158
190
|
|
|
@@ -284,3 +284,69 @@ pub fn build_lookup_maps(files: &[ParsedFile], nodes: &[CodeNode]) -> LookupMaps
|
|
|
284
284
|
}
|
|
285
285
|
l
|
|
286
286
|
}
|
|
287
|
+
|
|
288
|
+
/// Resolve a NAME against a module's export surface, following re-export hops.
|
|
289
|
+
///
|
|
290
|
+
/// Rust re-exports are `pub use inner::realOriginal as alias01;` — the alias is
|
|
291
|
+
/// a binding, not a declaration, so `alias01()` has no node to match by name.
|
|
292
|
+
/// Resolution walks:
|
|
293
|
+
/// 1. a declaration in this module (`module_path::name`)
|
|
294
|
+
/// 2. a `use` binding in this file → resolve its target path, recurse
|
|
295
|
+
/// (`use crate::c20::alias20` → c20.rs's own binding → … → the origin)
|
|
296
|
+
/// 3. glob imports (`use crate::models::*`) → recurse with the same name
|
|
297
|
+
///
|
|
298
|
+
/// Cycle-guarded and depth-capped. V1 has no visibility model, so every `use`
|
|
299
|
+
/// is treated as re-exportable — a superset of the truth that only ever
|
|
300
|
+
/// resolves names the compiler would also accept somewhere in the crate.
|
|
301
|
+
pub fn resolve_bound_name(
|
|
302
|
+
lookup: &LookupMaps,
|
|
303
|
+
module_map: &crate::module_map::ModuleMap,
|
|
304
|
+
rel_path: &str,
|
|
305
|
+
name: &str,
|
|
306
|
+
depth: usize,
|
|
307
|
+
seen: &mut std::collections::HashSet<String>,
|
|
308
|
+
) -> Option<String> {
|
|
309
|
+
const MAX_HOPS: usize = 24;
|
|
310
|
+
if depth > MAX_HOPS {
|
|
311
|
+
return None;
|
|
312
|
+
}
|
|
313
|
+
if !seen.insert(format!("{}::{}", rel_path, name)) {
|
|
314
|
+
return None; // cycle in the re-export chain
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
let module_path = crate::walker::module_path_for_file(rel_path);
|
|
318
|
+
|
|
319
|
+
// 1. declared here
|
|
320
|
+
let key = if module_path.is_empty() {
|
|
321
|
+
name.to_string()
|
|
322
|
+
} else {
|
|
323
|
+
format!("{}::{}", module_path, name)
|
|
324
|
+
};
|
|
325
|
+
if let Some(id) = lookup.item_by_module_name.get(&key) {
|
|
326
|
+
return Some(id.clone());
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// 2. bound by a `use` in this file → follow the target path
|
|
330
|
+
if let Some(target) = lookup.symbol_maps.get(rel_path).and_then(|m| m.get(name)) {
|
|
331
|
+
if let Some((file, rest)) = module_map.resolve_use(target, &module_path) {
|
|
332
|
+
if !rest.is_empty() && !rest.contains("::") {
|
|
333
|
+
if let Some(id) = resolve_bound_name(lookup, module_map, &file, &rest, depth + 1, seen) {
|
|
334
|
+
return Some(id);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// 3. `use crate::x::*;` — names live in the glob source
|
|
341
|
+
if let Some(globs) = lookup.glob_maps.get(rel_path) {
|
|
342
|
+
for g in globs {
|
|
343
|
+
if let Some((file, _)) = module_map.resolve_use(g, &module_path) {
|
|
344
|
+
if let Some(id) = resolve_bound_name(lookup, module_map, &file, name, depth + 1, seen) {
|
|
345
|
+
return Some(id);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
None
|
|
352
|
+
}
|
package/package.json
CHANGED