updates
This commit is contained in:
parent
77c51f4268
commit
1f5389f070
2 changed files with 17 additions and 49 deletions
|
|
@ -1,10 +1,11 @@
|
|||
import { Core } from "core/core";
|
||||
import { DataLogger } from "core/data/log";
|
||||
import { myersDiff } from "core/diff/myers";
|
||||
|
||||
import { ContinueGUIWebviewViewProvider } from "../ContinueGUIWebviewViewProvider";
|
||||
import { editOutcomeTracker } from "../extension/EditOutcomeTracker";
|
||||
import { createPrettyPatch, normalizeContent } from "../util/diffUtils";
|
||||
import { VsCodeIde } from "../VsCodeIde";
|
||||
|
||||
import { VerticalDiffManager } from "./vertical/manager";
|
||||
|
||||
export async function processDiff(
|
||||
|
|
@ -62,16 +63,24 @@ export async function processDiff(
|
|||
|
||||
// Detect autoformatting by comparing normalized content
|
||||
let autoFormattingDiff: string | undefined;
|
||||
const normalizedPreSave = normalizeContent(preSaveContent);
|
||||
const normalizedPostSave = normalizeContent(postSaveContent);
|
||||
const normalizedPreSave = preSaveContent.trim();
|
||||
const normalizedPostSave = postSaveContent.trim();
|
||||
|
||||
if (normalizedPreSave !== normalizedPostSave) {
|
||||
// Auto-formatting was applied by the editor
|
||||
autoFormattingDiff = createPrettyPatch(
|
||||
newOrCurrentUri,
|
||||
preSaveContent,
|
||||
postSaveContent,
|
||||
);
|
||||
const diffLines = myersDiff(preSaveContent, postSaveContent);
|
||||
autoFormattingDiff = diffLines
|
||||
.map(line => {
|
||||
switch (line.type) {
|
||||
case "old":
|
||||
return `-${line.line}`;
|
||||
case "new":
|
||||
return `+${line.line}`;
|
||||
case "same":
|
||||
return ` ${line.line}`;
|
||||
}
|
||||
})
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
await sidebar.webviewProtocol.request("updateApplyState", {
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
import { myersDiff } from "core/diff/myers";
|
||||
|
||||
/**
|
||||
* Creates a pretty patch diff string similar to unified diff format
|
||||
* Uses Continue's existing myersDiff function for diff calculation
|
||||
*/
|
||||
export function createPrettyPatch(
|
||||
filename: string = "file",
|
||||
oldStr: string = "",
|
||||
newStr: string = "",
|
||||
): string {
|
||||
if (oldStr === newStr) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const diffLines = myersDiff(oldStr, newStr);
|
||||
const patchLines: string[] = [];
|
||||
|
||||
for (const diffLine of diffLines) {
|
||||
switch (diffLine.type) {
|
||||
case "old":
|
||||
patchLines.push(`-${diffLine.line}`);
|
||||
break;
|
||||
case "new":
|
||||
patchLines.push(`+${diffLine.line}`);
|
||||
break;
|
||||
case "same":
|
||||
patchLines.push(` ${diffLine.line}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return patchLines.join("\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes content by trimming whitespace for comparison
|
||||
*/
|
||||
export function normalizeContent(content: string): string {
|
||||
return content.trim();
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue