@@ -39,7 +39,7 @@ impl ContextFetcher {
3939
4040 let full_path = self . repo_path . join ( file_path) ;
4141 if full_path. exists ( ) {
42- let content = tokio :: fs :: read_to_string ( & full_path) . await ?;
42+ let content = read_file_lossy ( & full_path) . await ?;
4343 let file_lines: Vec < & str > = content. lines ( ) . collect ( ) ;
4444 let merged_ranges = merge_ranges ( lines) ;
4545
@@ -100,7 +100,7 @@ impl ContextFetcher {
100100
101101 for path in matched_paths. into_iter ( ) . take ( max_files) {
102102 let relative_path = path. strip_prefix ( & self . repo_path ) . unwrap_or ( & path) ;
103- let content = tokio :: fs :: read_to_string ( & path) . await ?;
103+ let content = read_file_lossy ( & path) . await ?;
104104 let snippet = content
105105 . lines ( )
106106 . take ( max_lines)
@@ -135,7 +135,7 @@ impl ContextFetcher {
135135 // Search for symbol definitions in the same file first
136136 let full_path = self . repo_path . join ( file_path) ;
137137 if full_path. exists ( ) {
138- if let Ok ( content) = tokio :: fs :: read_to_string ( & full_path) . await {
138+ if let Ok ( content) = read_file_lossy ( & full_path) . await {
139139 let lines: Vec < & str > = content. lines ( ) . collect ( ) ;
140140
141141 for symbol in symbols {
@@ -193,3 +193,13 @@ fn merge_ranges(lines: &[(usize, usize)]) -> Vec<(usize, usize)> {
193193
194194 merged
195195}
196+
197+ async fn read_file_lossy ( path : & Path ) -> Result < String > {
198+ match tokio:: fs:: read_to_string ( path) . await {
199+ Ok ( content) => Ok ( content) ,
200+ Err ( _) => {
201+ let bytes = tokio:: fs:: read ( path) . await ?;
202+ Ok ( String :: from_utf8_lossy ( & bytes) . to_string ( ) )
203+ }
204+ }
205+ }
0 commit comments