mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
Prepare to fix diff highlighting
This commit is contained in:
parent
38d31ae737
commit
496c0178de
3 changed files with 13 additions and 10 deletions
|
|
@ -44,9 +44,6 @@ export class DisplayChangesProvider implements vscode.CodeLensProvider {
|
||||||
if (this._weAreEditing)
|
if (this._weAreEditing)
|
||||||
return
|
return
|
||||||
|
|
||||||
// console.log('e.contentChanges', e.contentChanges)
|
|
||||||
// console.log('e.contentChanges[0].text:', e.contentChanges?.[0])
|
|
||||||
|
|
||||||
const docUri = editor.document.uri
|
const docUri = editor.document.uri
|
||||||
const docUriStr = docUri.toString()
|
const docUriStr = docUri.toString()
|
||||||
const diffAreas = this._diffAreasOfDocument[docUriStr] || []
|
const diffAreas = this._diffAreasOfDocument[docUriStr] || []
|
||||||
|
|
@ -142,14 +139,24 @@ export class DisplayChangesProvider implements vscode.CodeLensProvider {
|
||||||
for (const diffArea of diffAreas) {
|
for (const diffArea of diffAreas) {
|
||||||
|
|
||||||
// get code inside of diffArea
|
// 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
|
// compute the diffs
|
||||||
const diffs = getDiffedLines(diffArea.originalCode, currentCode)
|
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]`
|
// add the diffs to `this._diffsOfDocument[docUriStr]`
|
||||||
this.addDiffs(editor.document.uri, diffs)
|
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
|
// update highlighting
|
||||||
|
|
@ -211,7 +218,6 @@ export class DisplayChangesProvider implements vscode.CodeLensProvider {
|
||||||
this._diffidPool += 1
|
this._diffidPool += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('diffs:', this._diffsOfDocument[docUriStr])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// called on void.acceptDiff
|
// called on void.acceptDiff
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import { DiffArea, WebviewMessage } from './shared_types';
|
import { DiffArea, WebviewMessage } from './shared_types';
|
||||||
import { CtrlKCodeLensProvider } from './CtrlKCodeLensProvider';
|
import { CtrlKCodeLensProvider } from './CtrlKCodeLensProvider';
|
||||||
import { getDiffedLines } from './getDiffedLines';
|
|
||||||
import { DisplayChangesProvider } from './DisplayChangesProvider';
|
import { DisplayChangesProvider } from './DisplayChangesProvider';
|
||||||
import { SidebarWebviewProvider } from './SidebarWebviewProvider';
|
import { SidebarWebviewProvider } from './SidebarWebviewProvider';
|
||||||
import { ApiConfig } from './common/sendLLMMessage';
|
import { ApiConfig } from './common/sendLLMMessage';
|
||||||
|
|
||||||
const readFileContentOfUri = async (uri: vscode.Uri) => {
|
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')
|
newStr = newStr.replace(/\r\n/g, '\n')
|
||||||
|
|
||||||
const lineByLineChanges: Change[] = diffLines(oldStr, newStr);
|
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)
|
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
|
} // end for
|
||||||
|
|
||||||
console.debug('Replacements', replacements)
|
|
||||||
|
|
||||||
return replacements
|
return replacements
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue