✨ monaco multi-file diff view
This commit is contained in:
parent
9ee5ca6f48
commit
5eed031db0
9 changed files with 642 additions and 427 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -9,7 +9,8 @@ let sockets: { [url: string]: io.Socket | undefined } = {};
|
|||
|
||||
export let debugPanelWebview: vscode.Webview | undefined;
|
||||
export function getSidebarContent(
|
||||
panel: vscode.WebviewPanel | vscode.WebviewView
|
||||
panel: vscode.WebviewPanel | vscode.WebviewView,
|
||||
page: string | undefined = undefined
|
||||
): string {
|
||||
debugPanelWebview = panel.webview;
|
||||
panel.onDidDispose(() => {
|
||||
|
|
@ -135,6 +136,21 @@ export function getSidebarContent(
|
|||
ideProtocolClient.openFile(data.filepath);
|
||||
break;
|
||||
}
|
||||
case "readRangeInFile": {
|
||||
vscode.workspace.openTextDocument(data.filepath).then((document) => {
|
||||
let start = new vscode.Position(0, 0);
|
||||
let end = new vscode.Position(5, 0);
|
||||
let range = new vscode.Range(start, end);
|
||||
|
||||
let contents = document.getText(range);
|
||||
panel.webview.postMessage({
|
||||
type: "readRangeInFile",
|
||||
messageId: data.messageId,
|
||||
contents,
|
||||
});
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "showLines": {
|
||||
ideProtocolClient.highlightCode(
|
||||
{
|
||||
|
|
|
|||
63
gui/package-lock.json
generated
63
gui/package-lock.json
generated
|
|
@ -9,6 +9,7 @@
|
|||
"dependencies": {
|
||||
"@headlessui/react": "^1.7.17",
|
||||
"@heroicons/react": "^2.0.18",
|
||||
"@monaco-editor/react": "^4.6.0",
|
||||
"@reduxjs/toolkit": "^1.9.3",
|
||||
"@types/vscode-webview": "^1.57.1",
|
||||
"@uiw/react-markdown-preview": "^4.1.13",
|
||||
|
|
@ -862,6 +863,30 @@
|
|||
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz",
|
||||
"integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw=="
|
||||
},
|
||||
"node_modules/@monaco-editor/loader": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@monaco-editor/loader/-/loader-1.4.0.tgz",
|
||||
"integrity": "sha512-00ioBig0x642hytVspPl7DbQyaSWRaolYie/UFNjoTdvoKPzo6xrXLhTk9ixgIKcLH5b5vDOjVNiGyY+uDCUlg==",
|
||||
"dependencies": {
|
||||
"state-local": "^1.0.6"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"monaco-editor": ">= 0.21.0 < 1"
|
||||
}
|
||||
},
|
||||
"node_modules/@monaco-editor/react": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@monaco-editor/react/-/react-4.6.0.tgz",
|
||||
"integrity": "sha512-RFkU9/i7cN2bsq/iTkurMWOEErmYcY6JiQI3Jn+WeR/FGISH8JbHERjpS9oRuSOPvDMJI0Z8nJeKkbOs9sBYQw==",
|
||||
"dependencies": {
|
||||
"@monaco-editor/loader": "^1.4.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"monaco-editor": ">= 0.25.0 < 1",
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
||||
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@nodelib/fs.scandir": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
||||
|
|
@ -3568,6 +3593,12 @@
|
|||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/monaco-editor": {
|
||||
"version": "0.44.0",
|
||||
"resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.44.0.tgz",
|
||||
"integrity": "sha512-5SmjNStN6bSuSE5WPT2ZV+iYn1/yI9sd4Igtk23ChvqB7kDk9lZbB9F5frsuvpB+2njdIeGGFf2G4gbE6rCC9Q==",
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/mri": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
|
||||
|
|
@ -4682,6 +4713,11 @@
|
|||
"url": "https://github.com/sponsors/wooorm"
|
||||
}
|
||||
},
|
||||
"node_modules/state-local": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/state-local/-/state-local-1.0.7.tgz",
|
||||
"integrity": "sha512-HTEHMNieakEnoe33shBYcZ7NX83ACUjCu8c40iOGEZsngj9zRnkqS9j1pqQPXwobB0ZcVTk27REb7COQ0UR59w=="
|
||||
},
|
||||
"node_modules/style-to-object": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/style-to-object/-/style-to-object-0.4.1.tgz",
|
||||
|
|
@ -5778,6 +5814,22 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"@monaco-editor/loader": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@monaco-editor/loader/-/loader-1.4.0.tgz",
|
||||
"integrity": "sha512-00ioBig0x642hytVspPl7DbQyaSWRaolYie/UFNjoTdvoKPzo6xrXLhTk9ixgIKcLH5b5vDOjVNiGyY+uDCUlg==",
|
||||
"requires": {
|
||||
"state-local": "^1.0.6"
|
||||
}
|
||||
},
|
||||
"@monaco-editor/react": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@monaco-editor/react/-/react-4.6.0.tgz",
|
||||
"integrity": "sha512-RFkU9/i7cN2bsq/iTkurMWOEErmYcY6JiQI3Jn+WeR/FGISH8JbHERjpS9oRuSOPvDMJI0Z8nJeKkbOs9sBYQw==",
|
||||
"requires": {
|
||||
"@monaco-editor/loader": "^1.4.0"
|
||||
}
|
||||
},
|
||||
"@nodelib/fs.scandir": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
||||
|
|
@ -7615,6 +7667,12 @@
|
|||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
},
|
||||
"monaco-editor": {
|
||||
"version": "0.44.0",
|
||||
"resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.44.0.tgz",
|
||||
"integrity": "sha512-5SmjNStN6bSuSE5WPT2ZV+iYn1/yI9sd4Igtk23ChvqB7kDk9lZbB9F5frsuvpB+2njdIeGGFf2G4gbE6rCC9Q==",
|
||||
"peer": true
|
||||
},
|
||||
"mri": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
|
||||
|
|
@ -8360,6 +8418,11 @@
|
|||
"resolved": "https://registry.npmjs.org/space-separated-tokens/-/space-separated-tokens-2.0.2.tgz",
|
||||
"integrity": "sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q=="
|
||||
},
|
||||
"state-local": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/state-local/-/state-local-1.0.7.tgz",
|
||||
"integrity": "sha512-HTEHMNieakEnoe33shBYcZ7NX83ACUjCu8c40iOGEZsngj9zRnkqS9j1pqQPXwobB0ZcVTk27REb7COQ0UR59w=="
|
||||
},
|
||||
"style-to-object": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/style-to-object/-/style-to-object-0.4.1.tgz",
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
"dependencies": {
|
||||
"@headlessui/react": "^1.7.17",
|
||||
"@heroicons/react": "^2.0.18",
|
||||
"@monaco-editor/react": "^4.6.0",
|
||||
"@reduxjs/toolkit": "^1.9.3",
|
||||
"@types/vscode-webview": "^1.57.1",
|
||||
"@uiw/react-markdown-preview": "^4.1.13",
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import Models from "./pages/models";
|
|||
import HelpPage from "./pages/help";
|
||||
import ModelConfig from "./pages/modelconfig";
|
||||
import useSetup from "./hooks/useSetup";
|
||||
import MonacoPage from "./pages/monaco";
|
||||
|
||||
const router = createMemoryRouter([
|
||||
{
|
||||
|
|
@ -23,10 +24,12 @@ const router = createMemoryRouter([
|
|||
{
|
||||
path: "/index.html",
|
||||
element: <GUI />,
|
||||
// element: <MonacoPage />,
|
||||
},
|
||||
{
|
||||
path: "/",
|
||||
element: <GUI />,
|
||||
// element: <MonacoPage />,
|
||||
},
|
||||
{
|
||||
path: "/history",
|
||||
|
|
@ -52,6 +55,10 @@ const router = createMemoryRouter([
|
|||
path: "/modelconfig/:modelName",
|
||||
element: <ModelConfig />,
|
||||
},
|
||||
{
|
||||
path: "/monaco",
|
||||
element: <MonacoPage />,
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
|
|
|||
108
gui/src/pages/monaco.tsx
Normal file
108
gui/src/pages/monaco.tsx
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
import React, { useEffect } from "react";
|
||||
import Editor, { DiffEditor } from "@monaco-editor/react";
|
||||
import { postToIde } from "../vscode";
|
||||
import { v4 } from "uuid";
|
||||
import { secondaryDark } from "../components";
|
||||
import HeaderButtonWithText from "../components/HeaderButtonWithText";
|
||||
import { CheckIcon, XMarkIcon } from "@heroicons/react/24/outline";
|
||||
|
||||
interface EditorFrameProps {
|
||||
filename: string;
|
||||
}
|
||||
|
||||
function EditorFrame(props: EditorFrameProps) {
|
||||
const [contents, setContents] = React.useState(
|
||||
"function sum(a, b) {return a + b;}"
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const messageId = v4();
|
||||
const eventListener = (event: any) => {
|
||||
if (
|
||||
event.data.messageId === messageId &&
|
||||
event.data.type === "readRangeInFile"
|
||||
) {
|
||||
setContents(event.data.contents);
|
||||
}
|
||||
};
|
||||
window.addEventListener("message", eventListener);
|
||||
|
||||
postToIde("readRangeInFile", {
|
||||
filepath: props.filename,
|
||||
messageId: messageId,
|
||||
});
|
||||
|
||||
return () => window.removeEventListener("message", eventListener);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div
|
||||
className="my-2 px-2 py-1 flex justify-between items-center"
|
||||
style={{
|
||||
backgroundColor: secondaryDark,
|
||||
}}
|
||||
>
|
||||
<code
|
||||
className="cursor-pointer"
|
||||
onClick={() => {
|
||||
postToIde("showFile", {
|
||||
filepath: props.filename,
|
||||
});
|
||||
}}
|
||||
>
|
||||
{props.filename.split("/").pop()}
|
||||
</code>
|
||||
<div className="flex items-center">
|
||||
<HeaderButtonWithText text="Reject" onClick={() => {}}>
|
||||
<XMarkIcon width="1.3em" height="1.3em" color="red" />
|
||||
</HeaderButtonWithText>
|
||||
<HeaderButtonWithText text="Accept" onClick={() => {}}>
|
||||
<CheckIcon width="1.3em" height="1.3em" color="lightgreen" />
|
||||
</HeaderButtonWithText>
|
||||
</div>
|
||||
</div>
|
||||
{/* <Editor
|
||||
className="border-gray-600 border border-solid rounded-md overflow-visible p-1 max-w-3xl"
|
||||
height="90px"
|
||||
width="90vw"
|
||||
defaultLanguage="typescript"
|
||||
defaultValue={contents}
|
||||
options={{ theme: "vs-dark", minimap: { enabled: false } }}
|
||||
/> */}
|
||||
<DiffEditor
|
||||
theme="vs-dark"
|
||||
className="overflow-visible p-1"
|
||||
height="90px"
|
||||
options={{
|
||||
minimap: { enabled: false },
|
||||
readOnly: false,
|
||||
scrollbar: {
|
||||
vertical: "hidden",
|
||||
},
|
||||
}}
|
||||
original={contents}
|
||||
modified="function sum(a, b) {return d + c;}"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const FILENAMES = [
|
||||
"/Users/natesesti/Desktop/continue/gui/src/hooks/CustomPostHogProvider.tsx",
|
||||
"/Users/natesesti/Desktop/continue/gui/src/hooks/CustomPostHogProvider.tsx",
|
||||
"/Users/natesesti/Desktop/continue/gui/src/hooks/CustomPostHogProvider.tsx",
|
||||
];
|
||||
|
||||
function MonacoPage() {
|
||||
return (
|
||||
<div>
|
||||
<h1 className="px-4">Multi-File Edit</h1>
|
||||
{FILENAMES.map((filename) => {
|
||||
return <EditorFrame filename={filename} />;
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default MonacoPage;
|
||||
Loading…
Add table
Reference in a new issue