devlensio 1.1.1 → 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/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.js +1 -90
- 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.js +12 -0
- package/dist/parser/moduleScope.test.d.ts +1 -0
- package/dist/parser/moduleScope.test.js +174 -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
|
@@ -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