From 90942b67bd4228439cb17328f8780563c323bb16 Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Tue, 19 Nov 2024 14:54:55 -0500 Subject: [PATCH] Diff parser TODO --- package-lock.json | 10 +++++++++ webview-ui/package.json | 1 + webview-ui/src/components/ResolutionsPage.tsx | 22 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/package-lock.json b/package-lock.json index a8335a3f..7e248c94 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8881,6 +8881,7 @@ "@patternfly/react-core": "6.0.0-prerelease.15", "@patternfly/react-icons": "^5.4.0", "@patternfly/react-table": "^5.4.1", + "diff": "^7.0.0", "vscode-webview": "^1.0.1-beta.1" }, "devDependencies": { @@ -8891,6 +8892,15 @@ "optionalDependencies": { "@rollup/rollup-linux-x64-gnu": "4.9.5" } + }, + "webview-ui/node_modules/diff": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-7.0.0.tgz", + "integrity": "sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw==", + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.3.1" + } } } } diff --git a/webview-ui/package.json b/webview-ui/package.json index 17f36b2e..4163f5a1 100644 --- a/webview-ui/package.json +++ b/webview-ui/package.json @@ -15,6 +15,7 @@ "@patternfly/react-core": "6.0.0-prerelease.15", "@patternfly/react-icons": "^5.4.0", "@patternfly/react-table": "^5.4.1", + "diff": "^7.0.0", "vscode-webview": "^1.0.1-beta.1" }, "devDependencies": { diff --git a/webview-ui/src/components/ResolutionsPage.tsx b/webview-ui/src/components/ResolutionsPage.tsx index e09a71be..8b451f9e 100644 --- a/webview-ui/src/components/ResolutionsPage.tsx +++ b/webview-ui/src/components/ResolutionsPage.tsx @@ -22,6 +22,7 @@ import { CodePreview } from "./CodePreview"; import { Change, ResolutionMessage } from "@editor-extensions/shared"; import { useVscodeMessages } from "../hooks/useVscodeMessages"; import { sendVscodeMessage } from "../utils/vscodeMessaging"; +import { parsePatch } from "diff"; const ResolutionPage: React.FC = () => { const [resolution, setResolution] = useState(null); @@ -95,6 +96,27 @@ const ResolutionPage: React.FC = () => { setIsResolved(true); }; + ////////////////////Diff parsing + + //TODO: Implement the diff parsing logic for the file changes + const parseDiff = (diff: string) => { + const patches = parsePatch(diff); + return patches.map((patch) => ({ + filePath: patch.newFileName || patch.oldFileName, + changes: patch.hunks.map((hunk) => ({ + start: hunk.newStart, + end: hunk.newStart + hunk.newLines - 1, + lines: hunk.lines, + })), + })); + }; + + // Example usage + const parsedDiff = parseDiff(resolution?.solution.changes[0].diff || ""); + console.log(parsedDiff); + + /////////////////////////// + // Display "Changes Applied" when the solution is accepted if (isResolved) { return (