codegraphcontext-rust 0.9.24__cp314-cp314-win_amd64.whl
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.
- codegraphcontext/__init__.py +2 -0
- codegraphcontext/__main__.py +5 -0
- codegraphcontext/_cgc_rust.cp314-win_amd64.pyd +4 -0
- codegraphcontext/cli/__init__.py +1 -0
- codegraphcontext/cli/cli_helpers.py +774 -0
- codegraphcontext/cli/config_manager.py +1051 -0
- codegraphcontext/cli/entry.py +21 -0
- codegraphcontext/cli/main.py +2386 -0
- codegraphcontext/cli/registry_commands.py +404 -0
- codegraphcontext/cli/setup_macos.py +93 -0
- codegraphcontext/cli/setup_wizard.py +991 -0
- codegraphcontext/cli/visualizer.py +50 -0
- codegraphcontext/core/__init__.py +165 -0
- codegraphcontext/core/bundle_registry.py +181 -0
- codegraphcontext/core/cgc_bundle.py +858 -0
- codegraphcontext/core/cgcignore.py +118 -0
- codegraphcontext/core/database.py +273 -0
- codegraphcontext/core/database_falkordb.py +480 -0
- codegraphcontext/core/database_falkordb_remote.py +199 -0
- codegraphcontext/core/database_kuzu.py +636 -0
- codegraphcontext/core/falkor_worker.py +132 -0
- codegraphcontext/core/jobs.py +132 -0
- codegraphcontext/core/watcher.py +260 -0
- codegraphcontext/prompts.py +125 -0
- codegraphcontext/server.py +471 -0
- codegraphcontext/tool_definitions.py +220 -0
- codegraphcontext/tools/__init__.py +0 -0
- codegraphcontext/tools/advanced_language_query_tool.py +103 -0
- codegraphcontext/tools/code_finder.py +1160 -0
- codegraphcontext/tools/graph_builder.py +337 -0
- codegraphcontext/tools/handlers/analysis_handlers.py +114 -0
- codegraphcontext/tools/handlers/indexing_handlers.py +116 -0
- codegraphcontext/tools/handlers/management_handlers.py +339 -0
- codegraphcontext/tools/handlers/query_handlers.py +83 -0
- codegraphcontext/tools/handlers/watcher_handlers.py +83 -0
- codegraphcontext/tools/indexing/__init__.py +1 -0
- codegraphcontext/tools/indexing/angular_routes.py +396 -0
- codegraphcontext/tools/indexing/cgc_wiki_cli.py +1334 -0
- codegraphcontext/tools/indexing/constants.py +70 -0
- codegraphcontext/tools/indexing/context_generator.py +461 -0
- codegraphcontext/tools/indexing/discovery.py +64 -0
- codegraphcontext/tools/indexing/engine.py +114 -0
- codegraphcontext/tools/indexing/execution_flows.py +355 -0
- codegraphcontext/tools/indexing/module_grouping.py +551 -0
- codegraphcontext/tools/indexing/noise_filter.py +131 -0
- codegraphcontext/tools/indexing/op_param_extraction.py +287 -0
- codegraphcontext/tools/indexing/persistence/__init__.py +3 -0
- codegraphcontext/tools/indexing/persistence/duckdb_writer.py +1116 -0
- codegraphcontext/tools/indexing/persistence/parquet_loader.py +643 -0
- codegraphcontext/tools/indexing/persistence/writer.py +1562 -0
- codegraphcontext/tools/indexing/pipeline.py +171 -0
- codegraphcontext/tools/indexing/pre_scan.py +105 -0
- codegraphcontext/tools/indexing/rationale_extraction.py +154 -0
- codegraphcontext/tools/indexing/resolution/__init__.py +8 -0
- codegraphcontext/tools/indexing/resolution/calls.py +253 -0
- codegraphcontext/tools/indexing/resolution/inheritance.py +91 -0
- codegraphcontext/tools/indexing/route_extraction.py +659 -0
- codegraphcontext/tools/indexing/sanitize.py +41 -0
- codegraphcontext/tools/indexing/schema.py +79 -0
- codegraphcontext/tools/indexing/schema_contract.py +44 -0
- codegraphcontext/tools/indexing/scip_pipeline.py +140 -0
- codegraphcontext/tools/languages/c.py +563 -0
- codegraphcontext/tools/languages/cpp.py +616 -0
- codegraphcontext/tools/languages/csharp.py +551 -0
- codegraphcontext/tools/languages/dart.py +378 -0
- codegraphcontext/tools/languages/elixir.py +460 -0
- codegraphcontext/tools/languages/go.py +499 -0
- codegraphcontext/tools/languages/haskell.py +426 -0
- codegraphcontext/tools/languages/java.py +500 -0
- codegraphcontext/tools/languages/javascript.py +589 -0
- codegraphcontext/tools/languages/kotlin.py +640 -0
- codegraphcontext/tools/languages/perl.py +260 -0
- codegraphcontext/tools/languages/php.py +519 -0
- codegraphcontext/tools/languages/python.py +578 -0
- codegraphcontext/tools/languages/ruby.py +537 -0
- codegraphcontext/tools/languages/rust.py +295 -0
- codegraphcontext/tools/languages/scala.py +519 -0
- codegraphcontext/tools/languages/swift.py +491 -0
- codegraphcontext/tools/languages/typescript.py +606 -0
- codegraphcontext/tools/languages/typescriptjsx.py +151 -0
- codegraphcontext/tools/package_resolver.py +472 -0
- codegraphcontext/tools/query_tool_languages/c_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/cpp_toolkit.py +87 -0
- codegraphcontext/tools/query_tool_languages/csharp_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/dart_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/go_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/haskell_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/java_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/javascript_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/perl_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/python_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/ruby_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/rust_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/scala_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/swift_toolkit.py +5 -0
- codegraphcontext/tools/query_tool_languages/typescript_toolkit.py +5 -0
- codegraphcontext/tools/scip_indexer.py +467 -0
- codegraphcontext/tools/scip_pb2.py +2455 -0
- codegraphcontext/tools/system.py +133 -0
- codegraphcontext/tools/tree_sitter_parser.py +103 -0
- codegraphcontext/utils/debug_log.py +90 -0
- codegraphcontext/utils/path_ignore.py +55 -0
- codegraphcontext/utils/repo_path.py +27 -0
- codegraphcontext/utils/tree_sitter_manager.py +285 -0
- codegraphcontext/utils/visualize_graph.py +0 -0
- codegraphcontext/viz/server.py +282 -0
- codegraphcontext_rust-0.9.24.dist-info/METADATA +543 -0
- codegraphcontext_rust-0.9.24.dist-info/RECORD +112 -0
- codegraphcontext_rust-0.9.24.dist-info/WHEEL +4 -0
- codegraphcontext_rust-0.9.24.dist-info/entry_points.txt +4 -0
- codegraphcontext_rust-0.9.24.dist-info/licenses/LICENSE +21 -0
- codegraphcontext_rust-0.9.24.dist-info/sboms/cgc-python.cyclonedx.json +2302 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
"""Angular Router: route tables, lazy-loaded modules and navigation calls.
|
|
2
|
+
|
|
3
|
+
Routes come from `Routes` arrays passed to `RouterModule.forRoot/forChild`
|
|
4
|
+
or `provideRouter`, or exported for `loadChildren`. Full paths are built by
|
|
5
|
+
following `loadChildren: () => import('./x/x.module').then(m => m.XModule)`
|
|
6
|
+
from the root routes into the child module's routing file, so a page gets
|
|
7
|
+
`/home/tabs/tab1` rather than just `tab1`.
|
|
8
|
+
|
|
9
|
+
Navigations are `router.navigate([...])` / `router.navigateByUrl('...')`
|
|
10
|
+
calls, attributed to their enclosing function and matched to a route.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
import re
|
|
17
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
18
|
+
|
|
19
|
+
_ROUTE_ARRAY_DECL = re.compile(
|
|
20
|
+
r"\b(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*(Routes|Route\s*\[\s*\]))?\s*=\s*\["
|
|
21
|
+
)
|
|
22
|
+
_ROUTER_CALL = re.compile(r"\b(?:RouterModule\.(forRoot|forChild)|(provideRouter))\s*\(")
|
|
23
|
+
_IMPORT_SPEC = re.compile(r"import\(\s*['\"]([^'\"]+)['\"]\s*\)")
|
|
24
|
+
_THEN_SYMBOL = re.compile(r"\.then\(\s*\(?\s*(\w+)\s*\)?\s*=>\s*\1\.(\w+)")
|
|
25
|
+
_NAVIGATE = re.compile(r"\b(?:\w+\.)*\w*[Rr]outer\s*\.\s*(navigate|navigateByUrl)\s*\(")
|
|
26
|
+
_TS_EXTS = (".ts", ".tsx", ".js", ".mjs")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# ── Small JS literal parser ──────────────────────────────────────────
|
|
30
|
+
|
|
31
|
+
def _strip_comments(src: str) -> str:
|
|
32
|
+
"""Blank out // and /* */ comments (string-aware, keeps offsets)."""
|
|
33
|
+
out, i, n = [], 0, len(src)
|
|
34
|
+
while i < n:
|
|
35
|
+
c = src[i]
|
|
36
|
+
if c in "'\"`":
|
|
37
|
+
j = i + 1
|
|
38
|
+
while j < n and src[j] != c:
|
|
39
|
+
j += 2 if src[j] == "\\" else 1
|
|
40
|
+
out.append(src[i:j + 1]); i = j + 1
|
|
41
|
+
elif src.startswith("//", i):
|
|
42
|
+
j = src.find("\n", i); j = n if j == -1 else j
|
|
43
|
+
out.append(" " * (j - i)); i = j
|
|
44
|
+
elif src.startswith("/*", i):
|
|
45
|
+
j = src.find("*/", i + 2); j = n if j == -1 else j + 2
|
|
46
|
+
out.append(re.sub(r"[^\n]", " ", src[i:j])); i = j
|
|
47
|
+
else:
|
|
48
|
+
out.append(c); i += 1
|
|
49
|
+
return "".join(out)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _match_close(code: str, i: int) -> int:
|
|
53
|
+
"""Index just past the bracket matching code[i] ('[', '{' or '(')."""
|
|
54
|
+
depth, n = 0, len(code)
|
|
55
|
+
while i < n:
|
|
56
|
+
c = code[i]
|
|
57
|
+
if c in "'\"`":
|
|
58
|
+
j = i + 1
|
|
59
|
+
while j < n and code[j] != c:
|
|
60
|
+
j += 2 if code[j] == "\\" else 1
|
|
61
|
+
i = j + 1
|
|
62
|
+
continue
|
|
63
|
+
if c in "[{(":
|
|
64
|
+
depth += 1
|
|
65
|
+
elif c in "]})":
|
|
66
|
+
depth -= 1
|
|
67
|
+
if depth == 0:
|
|
68
|
+
return i + 1
|
|
69
|
+
i += 1
|
|
70
|
+
return n
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _split_top(code: str, start: int, end: int) -> List[Tuple[int, int]]:
|
|
74
|
+
"""Comma-separated top-level segments of code[start:end]."""
|
|
75
|
+
segs, depth, seg_start, i = [], 0, start, start
|
|
76
|
+
while i < end:
|
|
77
|
+
c = code[i]
|
|
78
|
+
if c in "'\"`":
|
|
79
|
+
j = i + 1
|
|
80
|
+
while j < end and code[j] != c:
|
|
81
|
+
j += 2 if code[j] == "\\" else 1
|
|
82
|
+
i = j + 1
|
|
83
|
+
continue
|
|
84
|
+
if c in "[{(":
|
|
85
|
+
depth += 1
|
|
86
|
+
elif c in "]})":
|
|
87
|
+
depth -= 1
|
|
88
|
+
elif c == "," and depth == 0:
|
|
89
|
+
segs.append((seg_start, i)); seg_start = i + 1
|
|
90
|
+
i += 1
|
|
91
|
+
segs.append((seg_start, end))
|
|
92
|
+
return [(a, b) for a, b in segs if code[a:b].strip()]
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _string_value(text: str) -> Optional[str]:
|
|
96
|
+
m = re.fullmatch(r"\s*(['\"`])(.*?)\1\s*", text, re.S)
|
|
97
|
+
return m.group(2) if m else None
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _parse_object(code: str, start: int, end: int) -> Dict[str, Tuple[str, int]]:
|
|
101
|
+
"""Top-level `key: value` pairs of an object literal code[start:end] ({...})."""
|
|
102
|
+
props = {}
|
|
103
|
+
for a, b in _split_top(code, start + 1, end - 1):
|
|
104
|
+
m = re.match(r"\s*['\"]?(\w+)['\"]?\s*:", code[a:b])
|
|
105
|
+
if m:
|
|
106
|
+
vstart = a + m.end()
|
|
107
|
+
props[m.group(1)] = (code[vstart:b].strip(), vstart + (len(code[vstart:b]) - len(code[vstart:b].lstrip())))
|
|
108
|
+
return props
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _parse_routes(code: str, start: int, end: int) -> List[Dict[str, Any]]:
|
|
112
|
+
"""Parse a routes array code[start:end] ([...]) into route dicts."""
|
|
113
|
+
routes = []
|
|
114
|
+
for a, b in _split_top(code, start + 1, end - 1):
|
|
115
|
+
seg = code[a:b].strip()
|
|
116
|
+
off = a + (len(code[a:b]) - len(code[a:b].lstrip()))
|
|
117
|
+
if seg.startswith("..."): # spread of another routes array
|
|
118
|
+
routes.append({"ref": seg[3:].strip(), "pos": off})
|
|
119
|
+
continue
|
|
120
|
+
if re.fullmatch(r"\w+", seg):
|
|
121
|
+
routes.append({"ref": seg, "pos": off})
|
|
122
|
+
continue
|
|
123
|
+
if not seg.startswith("{"):
|
|
124
|
+
continue
|
|
125
|
+
props = _parse_object(code, off, _match_close(code, off))
|
|
126
|
+
route: Dict[str, Any] = {"pos": off, "path": None}
|
|
127
|
+
if "path" in props:
|
|
128
|
+
route["path"] = _string_value(props["path"][0])
|
|
129
|
+
if "component" in props:
|
|
130
|
+
route["component"] = props["component"][0].strip()
|
|
131
|
+
if "redirectTo" in props:
|
|
132
|
+
route["redirect"] = _string_value(props["redirectTo"][0]) or props["redirectTo"][0]
|
|
133
|
+
for key in ("loadChildren", "loadComponent"):
|
|
134
|
+
if key in props:
|
|
135
|
+
val = props[key][0]
|
|
136
|
+
spec = _IMPORT_SPEC.search(val)
|
|
137
|
+
sym = _THEN_SYMBOL.search(val)
|
|
138
|
+
legacy = _string_value(val) # 'path/to/x.module#XModule'
|
|
139
|
+
if spec:
|
|
140
|
+
route[key] = (spec.group(1), sym.group(2) if sym else None)
|
|
141
|
+
elif legacy and "#" in legacy:
|
|
142
|
+
p, s = legacy.split("#", 1)
|
|
143
|
+
route[key] = (p, s)
|
|
144
|
+
if "children" in props and props["children"][0].startswith("["):
|
|
145
|
+
cstart = props["children"][1]
|
|
146
|
+
route["children"] = _parse_routes(code, cstart, _match_close(code, cstart))
|
|
147
|
+
routes.append(route)
|
|
148
|
+
return routes
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
# ── Per-file route tables ────────────────────────────────────────────
|
|
152
|
+
|
|
153
|
+
def _line_of(code: str, pos: int) -> int:
|
|
154
|
+
return code.count("\n", 0, pos) + 1
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _file_routes(code: str) -> Dict[str, Any]:
|
|
158
|
+
"""Named route arrays and router registrations found in one file."""
|
|
159
|
+
arrays: Dict[str, Dict[str, Any]] = {}
|
|
160
|
+
for m in _ROUTE_ARRAY_DECL.finditer(code):
|
|
161
|
+
start = m.end() - 1
|
|
162
|
+
arrays[m.group(1)] = {
|
|
163
|
+
"routes": _parse_routes(code, start, _match_close(code, start)),
|
|
164
|
+
"typed": bool(m.group(2)),
|
|
165
|
+
}
|
|
166
|
+
registrations = [] # (mode, array name or None, inline routes or None)
|
|
167
|
+
for m in _ROUTER_CALL.finditer(code):
|
|
168
|
+
mode = "root" if (m.group(1) == "forRoot" or m.group(2)) else "child"
|
|
169
|
+
args_start = m.end()
|
|
170
|
+
while args_start < len(code) and code[args_start].isspace():
|
|
171
|
+
args_start += 1
|
|
172
|
+
if args_start < len(code) and code[args_start] == "[":
|
|
173
|
+
registrations.append((mode, None, _parse_routes(code, args_start, _match_close(code, args_start))))
|
|
174
|
+
else:
|
|
175
|
+
ident = re.match(r"(\w+)", code[args_start:])
|
|
176
|
+
if ident:
|
|
177
|
+
registrations.append((mode, ident.group(1), None))
|
|
178
|
+
return {"arrays": arrays, "registrations": registrations}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _resolve_import(from_rel: str, spec: str, known: set) -> Optional[str]:
|
|
182
|
+
if not spec.startswith("."):
|
|
183
|
+
return None
|
|
184
|
+
base = os.path.normpath(os.path.join(os.path.dirname(from_rel), spec))
|
|
185
|
+
for cand in [base] + [base + e for e in _TS_EXTS] + [os.path.join(base, "index" + e) for e in _TS_EXTS]:
|
|
186
|
+
if cand in known:
|
|
187
|
+
return cand
|
|
188
|
+
return None
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def _join(prefix: str, path: Optional[str]) -> str:
|
|
192
|
+
# `path: \`${PREFIX}/x\`` → dynamic segment
|
|
193
|
+
path = re.sub(r"\$\{[^}]*\}", ":param", path or "")
|
|
194
|
+
parts = [p for p in (prefix.strip("/"), path.strip("/")) if p]
|
|
195
|
+
return "/" + "/".join(parts)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def extract_angular_routes(
|
|
199
|
+
parsed_results: List[Dict[str, Any]],
|
|
200
|
+
repo_path: str,
|
|
201
|
+
) -> List[Dict[str, Any]]:
|
|
202
|
+
"""Angular routes with full paths, as route dicts (method PAGE/REDIRECT)."""
|
|
203
|
+
files: Dict[str, Dict[str, Any]] = {}
|
|
204
|
+
codes: Dict[str, str] = {}
|
|
205
|
+
for fd in parsed_results:
|
|
206
|
+
path = fd.get("path", "")
|
|
207
|
+
if fd.get("lang") not in ("typescript", "tsx", "javascript") or not os.path.exists(path):
|
|
208
|
+
continue
|
|
209
|
+
try:
|
|
210
|
+
src = open(path, encoding="utf-8", errors="replace").read()
|
|
211
|
+
except OSError:
|
|
212
|
+
continue
|
|
213
|
+
if "Route" not in src and "provideRouter" not in src:
|
|
214
|
+
continue
|
|
215
|
+
rel = os.path.relpath(path, repo_path)
|
|
216
|
+
code = _strip_comments(src)
|
|
217
|
+
info = _file_routes(code)
|
|
218
|
+
if info["arrays"] or info["registrations"]:
|
|
219
|
+
files[rel] = info
|
|
220
|
+
codes[rel] = code
|
|
221
|
+
if not files:
|
|
222
|
+
return []
|
|
223
|
+
known = {os.path.relpath(fd.get("path", ""), repo_path) for fd in parsed_results}
|
|
224
|
+
|
|
225
|
+
def array_by_name(rel: str, name: str):
|
|
226
|
+
arr = files.get(rel, {}).get("arrays", {}).get(name)
|
|
227
|
+
return arr["routes"] if arr else None
|
|
228
|
+
|
|
229
|
+
def child_tables(target: str, symbol: Optional[str]) -> List[Tuple[str, List]]:
|
|
230
|
+
"""Route tables a lazy `loadChildren` target contributes."""
|
|
231
|
+
out = []
|
|
232
|
+
if target in files:
|
|
233
|
+
if symbol and array_by_name(target, symbol) is not None:
|
|
234
|
+
return [(target, array_by_name(target, symbol))]
|
|
235
|
+
out += [(target, routes) for _, routes in _registered(target)]
|
|
236
|
+
if not out: # the module imports a sibling *-routing.module
|
|
237
|
+
d = os.path.dirname(target)
|
|
238
|
+
for rel in files:
|
|
239
|
+
if os.path.dirname(rel) == d and rel != target and ("routing" in rel or "routes" in rel):
|
|
240
|
+
out += [(rel, routes) for mode, routes in _registered(rel) if mode == "child"]
|
|
241
|
+
return out
|
|
242
|
+
|
|
243
|
+
def _registered(rel: str) -> List[Tuple[str, List]]:
|
|
244
|
+
info = files[rel]
|
|
245
|
+
out = []
|
|
246
|
+
for mode, name, inline in info["registrations"]:
|
|
247
|
+
routes = inline if inline is not None else array_by_name(rel, name) if name else None
|
|
248
|
+
if routes is not None:
|
|
249
|
+
out.append((mode, routes))
|
|
250
|
+
return out
|
|
251
|
+
|
|
252
|
+
results: List[Dict[str, Any]] = []
|
|
253
|
+
emitted = set()
|
|
254
|
+
reached = set() # ids of route lists visited from a root
|
|
255
|
+
|
|
256
|
+
def walk(rel: str, routes: List, prefix: str, depth: int):
|
|
257
|
+
if depth > 12:
|
|
258
|
+
return
|
|
259
|
+
reached.add(id(routes))
|
|
260
|
+
for r in routes:
|
|
261
|
+
if "ref" in r: # ...OTHER_ROUTES / OTHER_ROUTES inside the array
|
|
262
|
+
ref = array_by_name(rel, r["ref"])
|
|
263
|
+
if ref is not None and id(ref) not in reached:
|
|
264
|
+
walk(rel, ref, prefix, depth + 1)
|
|
265
|
+
continue
|
|
266
|
+
full = _join(prefix, r.get("path"))
|
|
267
|
+
line = _line_of(codes[rel], r["pos"])
|
|
268
|
+
handler, method = None, "PAGE"
|
|
269
|
+
if r.get("component"):
|
|
270
|
+
handler = r["component"]
|
|
271
|
+
elif r.get("loadComponent"):
|
|
272
|
+
handler = r["loadComponent"][1] or r["loadComponent"][0]
|
|
273
|
+
elif r.get("loadChildren"):
|
|
274
|
+
handler = r["loadChildren"][1] or r["loadChildren"][0]
|
|
275
|
+
elif r.get("redirect") is not None:
|
|
276
|
+
to = str(r["redirect"])
|
|
277
|
+
handler = "→ " + (to if to.startswith("/") else _join(prefix, to))
|
|
278
|
+
method = "REDIRECT"
|
|
279
|
+
if handler and (method, full, rel, line) not in emitted:
|
|
280
|
+
emitted.add((method, full, rel, line))
|
|
281
|
+
results.append({"method": method, "path": full, "handler": handler,
|
|
282
|
+
"file": rel, "line": line, "framework": "angular"})
|
|
283
|
+
if r.get("children"):
|
|
284
|
+
walk(rel, r["children"], full, depth + 1)
|
|
285
|
+
if r.get("loadChildren"):
|
|
286
|
+
spec, symbol = r["loadChildren"]
|
|
287
|
+
target = _resolve_import(rel, spec, known)
|
|
288
|
+
if target:
|
|
289
|
+
for trel, troutes in child_tables(target, symbol):
|
|
290
|
+
if id(troutes) not in reached:
|
|
291
|
+
walk(trel, troutes, full, depth + 1)
|
|
292
|
+
|
|
293
|
+
for rel in files:
|
|
294
|
+
for mode, routes in _registered(rel):
|
|
295
|
+
if mode == "root":
|
|
296
|
+
walk(rel, routes, "", 0)
|
|
297
|
+
# Child tables never reached from a root (unknown mount point): keep
|
|
298
|
+
# their local paths so the pages are still listed.
|
|
299
|
+
for rel in files:
|
|
300
|
+
for mode, routes in _registered(rel):
|
|
301
|
+
if id(routes) not in reached:
|
|
302
|
+
walk(rel, routes, "", 0)
|
|
303
|
+
return results
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
# ── Navigations ──────────────────────────────────────────────────────
|
|
307
|
+
|
|
308
|
+
def _nav_target(code: str, args_start: int, kind: str) -> Optional[str]:
|
|
309
|
+
"""Target path of a navigate([...]) / navigateByUrl('...') call.
|
|
310
|
+
|
|
311
|
+
Non-literal segments become `:param`; a path is absolute when its first
|
|
312
|
+
literal segment starts with '/'.
|
|
313
|
+
"""
|
|
314
|
+
while args_start < len(code) and code[args_start].isspace():
|
|
315
|
+
args_start += 1
|
|
316
|
+
if kind == "navigate":
|
|
317
|
+
if args_start >= len(code) or code[args_start] != "[":
|
|
318
|
+
return None
|
|
319
|
+
end = _match_close(code, args_start)
|
|
320
|
+
parts, absolute = [], False
|
|
321
|
+
for idx, (a, b) in enumerate(_split_top(code, args_start + 1, end - 1)):
|
|
322
|
+
s = _string_value(code[a:b])
|
|
323
|
+
if s is None:
|
|
324
|
+
parts.append(":param")
|
|
325
|
+
continue
|
|
326
|
+
if idx == 0 and s.startswith("/"):
|
|
327
|
+
absolute = True
|
|
328
|
+
parts += [":param" if "${" in p else p for p in s.split("/") if p]
|
|
329
|
+
return ("/" if absolute else "") + "/".join(parts)
|
|
330
|
+
m = re.match(r"(['\"`])(.*?)\1", code[args_start:args_start + 500], re.S)
|
|
331
|
+
if not m:
|
|
332
|
+
return None
|
|
333
|
+
return re.sub(r"\$\{[^}]*\}", ":param", m.group(2).split("?")[0])
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def _match_route(target: str, routes: List[Dict[str, Any]]) -> Optional[Dict[str, Any]]:
|
|
337
|
+
"""Best route for an absolute target path (literal segments must match)."""
|
|
338
|
+
if not target.startswith("/"):
|
|
339
|
+
return None
|
|
340
|
+
tseg = [s for s in target.strip("/").split("/") if s]
|
|
341
|
+
best, best_score = None, -1
|
|
342
|
+
for r in routes:
|
|
343
|
+
if r["method"] != "PAGE":
|
|
344
|
+
continue
|
|
345
|
+
rseg = [s for s in r["path"].strip("/").split("/") if s]
|
|
346
|
+
if len(rseg) != len(tseg):
|
|
347
|
+
continue
|
|
348
|
+
score = 0
|
|
349
|
+
for a, b in zip(rseg, tseg):
|
|
350
|
+
if a.startswith(":") or b == ":param":
|
|
351
|
+
continue
|
|
352
|
+
if a != b:
|
|
353
|
+
break
|
|
354
|
+
score += 1
|
|
355
|
+
else:
|
|
356
|
+
if score > best_score:
|
|
357
|
+
best, best_score = r, score
|
|
358
|
+
return best
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def extract_navigations(
|
|
362
|
+
parsed_results: List[Dict[str, Any]],
|
|
363
|
+
repo_path: str,
|
|
364
|
+
angular_routes: List[Dict[str, Any]],
|
|
365
|
+
) -> List[Dict[str, Any]]:
|
|
366
|
+
"""router.navigate / navigateByUrl calls with their enclosing function and route."""
|
|
367
|
+
out = []
|
|
368
|
+
for fd in parsed_results:
|
|
369
|
+
path = fd.get("path", "")
|
|
370
|
+
if fd.get("lang") not in ("typescript", "tsx", "javascript") or not os.path.exists(path):
|
|
371
|
+
continue
|
|
372
|
+
try:
|
|
373
|
+
src = open(path, encoding="utf-8", errors="replace").read()
|
|
374
|
+
except OSError:
|
|
375
|
+
continue
|
|
376
|
+
if "navigate" not in src:
|
|
377
|
+
continue
|
|
378
|
+
code = _strip_comments(src)
|
|
379
|
+
rel = os.path.relpath(path, repo_path)
|
|
380
|
+
funcs = [(f.get("line_number", 0), f.get("end_line", 0) or f.get("line_number", 0), f.get("name", ""))
|
|
381
|
+
for f in fd.get("functions", [])]
|
|
382
|
+
for m in _NAVIGATE.finditer(code):
|
|
383
|
+
target = _nav_target(code, m.end(), m.group(1))
|
|
384
|
+
if target is None:
|
|
385
|
+
continue
|
|
386
|
+
line = _line_of(code, m.start())
|
|
387
|
+
enclosing = [f for f in funcs if f[0] <= line <= f[1]]
|
|
388
|
+
caller = max(enclosing, key=lambda f: f[0])[2] if enclosing else ""
|
|
389
|
+
route = _match_route(target, angular_routes)
|
|
390
|
+
out.append({
|
|
391
|
+
"caller_name": caller, "caller_path": rel, "line": line, "target": target,
|
|
392
|
+
"route_path": route["path"] if route else "",
|
|
393
|
+
"route_handler": route["handler"] if route else "",
|
|
394
|
+
"route_file": route["file"] if route else "",
|
|
395
|
+
})
|
|
396
|
+
return out
|