mirror of
https://github.com/hanzoai/code.git
synced 2026-09-30 20:53:35 +00:00
Prepare to fix diff highlighting
This commit is contained in:
@@ -44,9 +44,6 @@ export class DisplayChangesProvider implements vscode.CodeLensProvider {
|
||||
if (this._weAreEditing)
|
||||
return
|
||||
|
||||
// console.log('e.contentChanges', e.contentChanges)
|
||||
// console.log('e.contentChanges[0].text:', e.contentChanges?.[0])
|
||||
|
||||
const docUri = editor.document.uri
|
||||
const docUriStr = docUri.toString()
|
||||
const diffAreas = this._diffAreasOfDocument[docUriStr] || []
|
||||
@@ -142,14 +139,24 @@ export class DisplayChangesProvider implements vscode.CodeLensProvider {
|
||||
for (const diffArea of diffAreas) {
|
||||
|
||||
// get code inside of diffArea
|
||||
const currentCode = editor.document.getText(new vscode.Range(diffArea.startLine, 0, diffArea.endLine, Number.MAX_SAFE_INTEGER))
|
||||
const currentCode = editor.document.getText(new vscode.Range(diffArea.startLine, 0, diffArea.endLine, Number.MAX_SAFE_INTEGER)).replace(/\r\n/g, '\n')
|
||||
|
||||
// compute the diffs
|
||||
const diffs = getDiffedLines(diffArea.originalCode, currentCode)
|
||||
|
||||
// print diffs
|
||||
console.log('!CODEBefore:', JSON.stringify(diffArea.originalCode))
|
||||
console.log('!CODEAfter:', JSON.stringify(currentCode))
|
||||
|
||||
// add the diffs to `this._diffsOfDocument[docUriStr]`
|
||||
this.addDiffs(editor.document.uri, diffs)
|
||||
|
||||
for (const diff of this._diffsOfDocument[docUriStr]) {
|
||||
console.log('originalCodeDiff:', JSON.stringify(diff.originalCode))
|
||||
console.log('greenCodeDiff:', JSON.stringify(editor.document.getText(diff.greenRange).replace(/\r\n/g, '\n')))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// update highlighting
|
||||
@@ -211,7 +218,6 @@ export class DisplayChangesProvider implements vscode.CodeLensProvider {
|
||||
this._diffidPool += 1
|
||||
}
|
||||
|
||||
console.log('diffs:', this._diffsOfDocument[docUriStr])
|
||||
}
|
||||
|
||||
// called on void.acceptDiff
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { DiffArea, WebviewMessage } from './shared_types';
|
||||
import { CtrlKCodeLensProvider } from './CtrlKCodeLensProvider';
|
||||
import { getDiffedLines } from './getDiffedLines';
|
||||
import { DisplayChangesProvider } from './DisplayChangesProvider';
|
||||
import { SidebarWebviewProvider } from './SidebarWebviewProvider';
|
||||
import { ApiConfig } from './common/sendLLMMessage';
|
||||
|
||||
const readFileContentOfUri = async (uri: vscode.Uri) => {
|
||||
return Buffer.from(await vscode.workspace.fs.readFile(uri)).toString('utf8').replace(/\r\n/g, '\n'); // must remove windows \r or every line will appear different because of it
|
||||
return Buffer.from(await vscode.workspace.fs.readFile(uri)).toString('utf8')
|
||||
.replace(/\r\n/g, '\n') // must remove windows \r or every line will appear different because of it
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ export function getDiffedLines(oldStr: string, newStr: string) {
|
||||
newStr = newStr.replace(/\r\n/g, '\n')
|
||||
|
||||
const lineByLineChanges: Change[] = diffLines(oldStr, newStr);
|
||||
console.debug('Line by line changes', lineByLineChanges)
|
||||
|
||||
lineByLineChanges.push({ value: '' }) // add a dummy so we flush any streaks we haven't yet at the very end (!line.added && !line.removed)
|
||||
|
||||
@@ -89,8 +88,6 @@ export function getDiffedLines(oldStr: string, newStr: string) {
|
||||
|
||||
} // end for
|
||||
|
||||
console.debug('Replacements', replacements)
|
||||
|
||||
return replacements
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user