Skip to content

Commit 697eb01

Browse files
author
wangjichao
committed
fix: standardize path handling to use Path objects consistently and fix critical bug in code_retrieval
1 parent 9983470 commit 697eb01

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

codebase_rag/graph_updater.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def _is_dependency_file(self, file_name: str, filepath: Path) -> bool:
262262
)
263263

264264
def run(self) -> None:
265-
absolute_path = self.repo_path.absolute().as_posix()
265+
absolute_path = str(self.repo_path.absolute())
266266

267267
self.ingestor.ensure_node_batch(
268268
cs.NODE_PROJECT,

codebase_rag/parsers/class_ingest/cpp_modules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _process_export_module(
8383
{
8484
cs.KEY_QUALIFIED_NAME: interface_qn,
8585
cs.KEY_NAME: module_name,
86-
cs.KEY_PATH: str(file_path.relative_to(repo_path)),
86+
cs.KEY_PATH: file_path.relative_to(repo_path).as_posix(),
8787
cs.KEY_MODULE_TYPE: cs.CPP_MODULE_TYPE_INTERFACE,
8888
},
8989
)
@@ -117,7 +117,7 @@ def _process_module_implementation(
117117
{
118118
cs.KEY_QUALIFIED_NAME: impl_qn,
119119
cs.KEY_NAME: f"{module_name}{cs.CPP_IMPL_SUFFIX}",
120-
cs.KEY_PATH: str(file_path.relative_to(repo_path)),
120+
cs.KEY_PATH: file_path.relative_to(repo_path).as_posix(),
121121
cs.KEY_IMPLEMENTS_MODULE: module_name,
122122
cs.KEY_MODULE_TYPE: cs.CPP_MODULE_TYPE_IMPLEMENTATION,
123123
},

codebase_rag/tools/code_retrieval.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,36 @@ async def find_code_snippet(self, qualified_name: str) -> CodeSnippet:
3939
)
4040

4141
res = results[0]
42-
absolute_path_str = res.get("absolute_path")
4342
project_name = res.get("project_name")
44-
file_path_str = res.get("relative_path")
45-
46-
if not absolute_path_str:
47-
logger.warning(ls.NO_ABSOLUTE_PATH_FALLBACK.format(qn=qualified_name))
48-
4943
start_line = res.get("start")
5044
end_line = res.get("end")
5145

52-
file_path_to_read = absolute_path_str or (
53-
str(self.project_root.as_posix() / file_path_str)
54-
if file_path_str
55-
else ""
56-
)
46+
absolute_path_str = res.get("absolute_path")
47+
relative_path_str = res.get("relative_path")
48+
49+
if absolute_path_str:
50+
file_path_obj = Path(absolute_path_str)
51+
elif relative_path_str:
52+
file_path_obj = self.project_root / relative_path_str
53+
logger.warning(ls.NO_ABSOLUTE_PATH_FALLBACK.format(qn=qualified_name))
54+
else:
55+
file_path_obj = None
5756

58-
if not all([file_path_to_read, start_line, end_line]):
57+
if not (file_path_obj and start_line and end_line):
5958
return CodeSnippet(
6059
qualified_name=qualified_name,
6160
source_code="",
62-
file_path=file_path_to_read or "",
61+
file_path=str(file_path_obj) if file_path_obj else "",
6362
project_name=project_name,
6463
line_start=0,
6564
line_end=0,
6665
found=False,
6766
error_message=te.CODE_MISSING_LOCATION,
6867
)
6968

70-
full_path = Path(file_path_to_read)
71-
with full_path.open("r", encoding=ENCODING_UTF8) as f:
69+
assert file_path_obj is not None
70+
71+
with file_path_obj.open("r", encoding=ENCODING_UTF8) as f:
7272
all_lines = f.readlines()
7373

7474
snippet_lines = all_lines[start_line - 1 : end_line]
@@ -77,7 +77,7 @@ async def find_code_snippet(self, qualified_name: str) -> CodeSnippet:
7777
return CodeSnippet(
7878
qualified_name=qualified_name,
7979
source_code=source_code,
80-
file_path=file_path_to_read,
80+
file_path=str(file_path_obj),
8181
project_name=project_name,
8282
line_start=start_line,
8383
line_end=end_line,

0 commit comments

Comments
 (0)