mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-21 04:41:16 -05:00
Improvements to apply_diff (#52)
This commit is contained in:
@@ -22,7 +22,7 @@ export async function extractTextFromFile(filePath: string): Promise<string> {
|
||||
default:
|
||||
const isBinary = await isBinaryFile(filePath).catch(() => false)
|
||||
if (!isBinary) {
|
||||
return await fs.readFile(filePath, "utf8")
|
||||
return addLineNumbers(await fs.readFile(filePath, "utf8"))
|
||||
} else {
|
||||
throw new Error(`Cannot read text for file type: ${fileExtension}`)
|
||||
}
|
||||
@@ -32,12 +32,12 @@ export async function extractTextFromFile(filePath: string): Promise<string> {
|
||||
async function extractTextFromPDF(filePath: string): Promise<string> {
|
||||
const dataBuffer = await fs.readFile(filePath)
|
||||
const data = await pdf(dataBuffer)
|
||||
return data.text
|
||||
return addLineNumbers(data.text)
|
||||
}
|
||||
|
||||
async function extractTextFromDOCX(filePath: string): Promise<string> {
|
||||
const result = await mammoth.extractRawText({ path: filePath })
|
||||
return result.value
|
||||
return addLineNumbers(result.value)
|
||||
}
|
||||
|
||||
async function extractTextFromIPYNB(filePath: string): Promise<string> {
|
||||
@@ -51,5 +51,17 @@ async function extractTextFromIPYNB(filePath: string): Promise<string> {
|
||||
}
|
||||
}
|
||||
|
||||
return extractedText
|
||||
return addLineNumbers(extractedText)
|
||||
}
|
||||
|
||||
export function addLineNumbers(content: string): string {
|
||||
const lines = content.split('\n')
|
||||
const maxLineNumberWidth = String(lines.length).length
|
||||
return lines
|
||||
.map((line, index) => {
|
||||
const lineNumber = String(index + 1).padStart(maxLineNumberWidth, ' ')
|
||||
return `${lineNumber} | ${line}`
|
||||
}).join('\n')
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user