-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Added file encoding detection and reading functions #6841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f5ef6b0
c7c0018
cd41603
ef0a5fa
48a1c62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import path from "path" | |
| import fs from "fs/promises" | ||
|
|
||
| import { TelemetryService } from "@roo-code/telemetry" | ||
| import { readFileWithEncodingDetection } from "../../utils/encoding" | ||
| import { DEFAULT_WRITE_DELAY_MS } from "@roo-code/types" | ||
|
|
||
| import { ClineSayTool } from "../../shared/ExtensionMessage" | ||
|
|
@@ -300,7 +301,7 @@ Original error: ${errorMessage}` | |
|
|
||
| let unified = "" | ||
| try { | ||
| const original = await fs.readFile(opResult.absolutePath!, "utf-8") | ||
| const original = await readFileWithEncodingDetection(opResult.absolutePath!) | ||
| const processed = !cline.api.getModel().id.includes("claude") | ||
| ? (opResult.diffItems || []).map((item) => ({ | ||
| ...item, | ||
|
|
@@ -457,7 +458,7 @@ Original error: ${errorMessage}` | |
| const fileExists = opResult.fileExists! | ||
|
|
||
| try { | ||
| let originalContent: string | null = await fs.readFile(absolutePath, "utf-8") | ||
| let originalContent: string | null = await readFileWithEncodingDetection(absolutePath) | ||
| let beforeContent: string | null = originalContent | ||
| let successCount = 0 | ||
| let formattedError = "" | ||
|
|
@@ -611,7 +612,7 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""} | |
| cline.diffViewProvider.scrollToFirstDiff() | ||
| } else { | ||
| // For direct save, we still need to set originalContent | ||
| cline.diffViewProvider.originalContent = await fs.readFile(absolutePath, "utf-8") | ||
| cline.diffViewProvider.originalContent = await readFileWithEncodingDetection(absolutePath) | ||
| } | ||
|
|
||
| // Ask for approval (same for both flows) | ||
|
|
@@ -646,7 +647,7 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""} | |
| if (isPreventFocusDisruptionEnabled) { | ||
| // Direct file write without diff view or opening the file | ||
| cline.diffViewProvider.editType = "modify" | ||
| cline.diffViewProvider.originalContent = await fs.readFile(absolutePath, "utf-8") | ||
| cline.diffViewProvider.originalContent = await readFileWithEncodingDetection(absolutePath) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also ensure the encoding is preserved when the file is written back? The DiffViewProvider might need to track and use the original encoding when saving files. |
||
| await cline.diffViewProvider.saveDirectly( | ||
| relPath, | ||
| originalContent!, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed is called multiple times for the same file (here and line 560). Could we optimize this by reading the file once and reusing the content? This would improve performance, especially for large files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good Review. Let me make some revisions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's prioritize consistency with the past first. The issue of reading the file repeatedly can be addressed as an optimization for the next issue.