File tree Expand file tree Collapse file tree 8 files changed +793
-40
lines changed Expand file tree Collapse file tree 8 files changed +793
-40
lines changed Original file line number Diff line number Diff line change 11import path from "path"
2- import fs from "fs/promises "
2+ import { readFileWithEncoding } from "../../integrations/misc/readFileWithEncoding "
33
44import { TelemetryService } from "@roo-code/telemetry"
55
@@ -86,7 +86,7 @@ export async function applyDiffTool(
8686 return
8787 }
8888
89- let originalContent : string | null = await fs . readFile ( absolutePath , "utf-8" )
89+ let originalContent : string | null = ( await readFileWithEncoding ( absolutePath ) ) . content
9090
9191 // Apply the diff to the original content
9292 const diffResult = ( await cline . diffStrategy ?. applyDiff (
Original file line number Diff line number Diff line change 11import delay from "delay"
2- import fs from "fs/promises "
2+ import { readFileWithEncoding } from "../../integrations/misc/readFileWithEncoding "
33import path from "path"
44
55import { getReadablePath } from "../../utils/path"
@@ -89,7 +89,7 @@ export async function insertContentTool(
8989 cline . consecutiveMistakeCount = 0
9090
9191 // Read the file
92- const fileContent = await fs . readFile ( absolutePath , "utf8" )
92+ const fileContent = ( await readFileWithEncoding ( absolutePath ) ) . content
9393 cline . diffViewProvider . editType = "modify"
9494 cline . diffViewProvider . originalContent = fileContent
9595 const lines = fileContent . split ( "\n" )
Original file line number Diff line number Diff line change 11// Core Node.js imports
22import path from "path"
3- import fs from "fs/promises "
3+ import { readFileWithEncoding } from "../../integrations/misc/readFileWithEncoding "
44import delay from "delay"
55
66// Internal imports
@@ -143,7 +143,7 @@ export async function searchAndReplaceTool(
143143 // Read and process file content
144144 let fileContent : string
145145 try {
146- fileContent = await fs . readFile ( absolutePath , "utf-8" )
146+ fileContent = ( await readFileWithEncoding ( absolutePath ) ) . content
147147 } catch ( error ) {
148148 cline . consecutiveMistakeCount ++
149149 cline . recordToolError ( "search_and_replace" )
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import { formatResponse } from "../../core/prompts/responses"
1111import { diagnosticsToProblemsString , getNewDiagnostics } from "../diagnostics"
1212import { ClineSayTool } from "../../shared/ExtensionMessage"
1313import { Task } from "../../core/task/Task"
14+ import { readFileWithEncoding } from "../misc/readFileWithEncoding"
1415
1516import { DecorationController } from "./DecorationController"
1617
@@ -59,7 +60,7 @@ export class DiffViewProvider {
5960 this . preDiagnostics = vscode . languages . getDiagnostics ( )
6061
6162 if ( fileExists ) {
62- this . originalContent = await fs . readFile ( absolutePath , "utf-8" )
63+ this . originalContent = ( await readFileWithEncoding ( absolutePath ) ) . content
6364 } else {
6465 this . originalContent = ""
6566 }
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import * as path from "path"
33import pdf from "pdf-parse/lib/pdf-parse"
44import mammoth from "mammoth"
55import fs from "fs/promises"
6- import { isBinaryFile } from "isbinaryfile "
6+ import { readFileWithEncoding } from "./readFileWithEncoding "
77
88async function extractTextFromPDF ( filePath : string ) : Promise < string > {
99 const dataBuffer = await fs . readFile ( filePath )
@@ -61,12 +61,11 @@ export async function extractTextFromFile(filePath: string): Promise<string> {
6161 return extractor ( filePath )
6262 }
6363
64- // Handle other files
65- const isBinary = await isBinaryFile ( filePath ) . catch ( ( ) => false )
66-
67- if ( ! isBinary ) {
68- return addLineNumbers ( await fs . readFile ( filePath , "utf8" ) )
69- } else {
64+ // Handle other files using readFileWithEncoding with binary detection
65+ try {
66+ const { content } = await readFileWithEncoding ( filePath , { acceptTextOnly : true } )
67+ return addLineNumbers ( content )
68+ } catch ( error ) {
7069 throw new Error ( `Cannot read text for file type: ${ fileExtension } ` )
7170 }
7271}
You can’t perform that action at this time.
0 commit comments