Fix rust connection for graph

This commit is contained in:
2025-11-14 18:30:56 +00:00
parent 304227c5f3
commit a37516c530
2 changed files with 79 additions and 15 deletions
+47 -4
View File
@@ -828,7 +828,7 @@ def parse_go_file_cached(filepath_str: str, file_hash: str) -> tuple:
chunk_text += f"Code:\n{chunk_code}"
# Build comprehensive metadata
metadata = {
parse_rust_file_cached = {
"file": str(filepath),
"name": name,
"type": typ,
@@ -1648,6 +1648,26 @@ def parse_rust_file_cached(filepath_str: str, file_hash: str) -> tuple:
except Exception as e:
logger.warning(f"parse_rust_file failed {filepath}: {e}")
# Very simple call extractor: finds foo(), bar::<T>(), module::foo()
call_re = re.compile(r'([A-Za-z_][A-Za-z0-9_]*)\s*!\s*\(|([A-Za-z_][A-Za-z0-9_:]*)\s*\(', re.MULTILINE)
calls = []
for match in call_re.findall(code):
name1, name2 = match
name = name1 or name2
if "::" in name:
name = name.split("::")[-1]
# filter out keywords and type constructors
if name not in ["if", "for", "match", "while", "loop"]:
calls.append(name)
# attach to every chunk belonging to the file
for c in chunks:
md = dict(c["metadata"])
md["calls"] = calls
c["metadata"] = md
final_result = tuple((c["text"], tuple(c["metadata"].items())) for c in chunks)
logger.info(f"📦 Final result: {len(final_result)} chunks with metadata")
return final_result
@@ -2124,6 +2144,10 @@ def build_indexes():
if not name or node_type == "unknown" or not fpath:
continue
# convert rust defs
if "implements_traits" in m and m["implements_traits"]:
m["implements"] = m["implements_traits"]
# ---- File node ---------------------------------------------
# Keep the same ID (`file::<path>`) but store the full set of
# attributes so that downstream code can rely on `name`, `lang`,
@@ -2194,6 +2218,15 @@ def build_indexes():
param_parts = param.split(':')
if len(param_parts) >= 2:
param_type = param_parts[-1].strip()
param_type = (
param_type
.replace('&', '')
.replace('mut ', '')
.replace('<', '')
.replace('>', '')
.replace(',', '')
.strip()
)
param_type = param_type.replace('&', '').replace('mut ', '').strip()
if (param_type and
param_type not in ['self', '&self', '&mut self', 'mut self'] and
@@ -2222,6 +2255,15 @@ def build_indexes():
param_parts = param.split(':')
if len(param_parts) >= 2:
param_type = param_parts[-1].strip()
param_type = (
param_type
.replace('&', '')
.replace('mut ', '')
.replace('<', '')
.replace('>', '')
.replace(',', '')
.strip()
)
param_type = param_type.replace('&', '').replace('mut ', '').strip()
if (param_type and
param_type not in ['self', '&self', '&mut self', 'mut self'] and
@@ -2286,9 +2328,10 @@ def build_indexes():
graph.add_edge(file_node_id, node_id, "contains")
# ---------- IMPORTS ----------
# The imports metadata might be a list or a comma-separated string
# We need to handle both cases
imports_raw = m.get("imports", [])
if node_type == "import" and "parameters" in m:
imports_raw = m["parameters"] # override metadata pathway
else:
imports_raw = m.get("imports", [])
if isinstance(imports_raw, str):
# Split the string back into a list
imports = [imp.strip() for imp in imports_raw.split(",") if imp.strip()]