Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 42 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/core/tools/applyDiffTool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path"
import fs from "fs/promises"
import { readFileWithEncoding } from "../../integrations/misc/readFileWithEncoding"

import { TelemetryService } from "@roo-code/telemetry"

Expand Down Expand Up @@ -86,7 +86,7 @@ export async function applyDiffTool(
return
}

let originalContent: string | null = await fs.readFile(absolutePath, "utf-8")
let originalContent: string | null = (await readFileWithEncoding(absolutePath)).content

// Apply the diff to the original content
const diffResult = (await cline.diffStrategy?.applyDiff(
Expand Down
4 changes: 2 additions & 2 deletions src/core/tools/insertContentTool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import delay from "delay"
import fs from "fs/promises"
import { readFileWithEncoding } from "../../integrations/misc/readFileWithEncoding"
import path from "path"

import { getReadablePath } from "../../utils/path"
Expand Down Expand Up @@ -89,7 +89,7 @@ export async function insertContentTool(
cline.consecutiveMistakeCount = 0

// Read the file
const fileContent = await fs.readFile(absolutePath, "utf8")
const fileContent = (await readFileWithEncoding(absolutePath)).content
cline.diffViewProvider.editType = "modify"
cline.diffViewProvider.originalContent = fileContent
const lines = fileContent.split("\n")
Expand Down
4 changes: 2 additions & 2 deletions src/core/tools/searchAndReplaceTool.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Core Node.js imports
import path from "path"
import fs from "fs/promises"
import { readFileWithEncoding } from "../../integrations/misc/readFileWithEncoding"
import delay from "delay"

// Internal imports
Expand Down Expand Up @@ -143,7 +143,7 @@ export async function searchAndReplaceTool(
// Read and process file content
let fileContent: string
try {
fileContent = await fs.readFile(absolutePath, "utf-8")
fileContent = (await readFileWithEncoding(absolutePath)).content
} catch (error) {
cline.consecutiveMistakeCount++
cline.recordToolError("search_and_replace")
Expand Down
3 changes: 2 additions & 1 deletion src/integrations/editor/DiffViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { formatResponse } from "../../core/prompts/responses"
import { diagnosticsToProblemsString, getNewDiagnostics } from "../diagnostics"
import { ClineSayTool } from "../../shared/ExtensionMessage"
import { Task } from "../../core/task/Task"
import { readFileWithEncoding } from "../misc/readFileWithEncoding"

import { DecorationController } from "./DecorationController"

Expand Down Expand Up @@ -59,7 +60,7 @@ export class DiffViewProvider {
this.preDiagnostics = vscode.languages.getDiagnostics()

if (fileExists) {
this.originalContent = await fs.readFile(absolutePath, "utf-8")
this.originalContent = (await readFileWithEncoding(absolutePath)).content
} else {
this.originalContent = ""
}
Expand Down
13 changes: 6 additions & 7 deletions src/integrations/misc/extract-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from "path"
import pdf from "pdf-parse/lib/pdf-parse"
import mammoth from "mammoth"
import fs from "fs/promises"
import { isBinaryFile } from "isbinaryfile"
import { readFileWithEncoding } from "./readFileWithEncoding"

async function extractTextFromPDF(filePath: string): Promise<string> {
const dataBuffer = await fs.readFile(filePath)
Expand Down Expand Up @@ -61,12 +61,11 @@ export async function extractTextFromFile(filePath: string): Promise<string> {
return extractor(filePath)
}

// Handle other files
const isBinary = await isBinaryFile(filePath).catch(() => false)

if (!isBinary) {
return addLineNumbers(await fs.readFile(filePath, "utf8"))
} else {
// Handle other files using readFileWithEncoding with binary detection
try {
const { content } = await readFileWithEncoding(filePath, { acceptTextOnly: true })
return addLineNumbers(content)
} catch (error) {
throw new Error(`Cannot read text for file type: ${fileExtension}`)
}
}
Expand Down
Loading
Loading