Skip to content

Commit

Permalink
Diff parser TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 committed Nov 19, 2024
1 parent cb2db6e commit 90942b6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions webview-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
22 changes: 22 additions & 0 deletions webview-ui/src/components/ResolutionsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResolutionMessage | null>(null);
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit 90942b6

Please sign in to comment.