@@ -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