summaryrefslogtreecommitdiff
path: root/extension
diff options
context:
space:
mode:
Diffstat (limited to 'extension')
-rw-r--r--extension/package.json10
-rw-r--r--extension/react-app/src/components/ComboBox.tsx27
-rw-r--r--extension/react-app/src/components/PillButton.tsx27
-rw-r--r--extension/react-app/src/components/UserInputContainer.tsx4
-rw-r--r--extension/react-app/src/hooks/ContinueGUIClientProtocol.ts2
-rw-r--r--extension/react-app/src/hooks/useContinueGUIProtocol.ts4
-rw-r--r--extension/react-app/src/tabs/gui.tsx6
-rw-r--r--extension/src/commands.ts4
-rw-r--r--extension/src/continueIdeClient.ts38
-rw-r--r--extension/src/diffs.ts114
-rw-r--r--extension/src/lang-server/codeLens.ts40
11 files changed, 218 insertions, 58 deletions
diff --git a/extension/package.json b/extension/package.json
index 52e7f891..d4850671 100644
--- a/extension/package.json
+++ b/extension/package.json
@@ -87,6 +87,16 @@
"title": "Reject Suggestion"
},
{
+ "command": "continue.acceptDiff",
+ "category": "Continue",
+ "title": "Accept Diff"
+ },
+ {
+ "command": "continue.rejectDiff",
+ "category": "Continue",
+ "title": "Reject Diff"
+ },
+ {
"command": "continue.acceptAllSuggestions",
"category": "Continue",
"title": "Accept All Suggestions"
diff --git a/extension/react-app/src/components/ComboBox.tsx b/extension/react-app/src/components/ComboBox.tsx
index 3e1f3e16..97f5b57e 100644
--- a/extension/react-app/src/components/ComboBox.tsx
+++ b/extension/react-app/src/components/ComboBox.tsx
@@ -11,7 +11,12 @@ import CodeBlock from "./CodeBlock";
import { RangeInFile } from "../../../src/client";
import PillButton from "./PillButton";
import HeaderButtonWithText from "./HeaderButtonWithText";
-import { Trash, LockClosed, LockOpen } from "@styled-icons/heroicons-outline";
+import {
+ Trash,
+ LockClosed,
+ LockOpen,
+ Plus,
+} from "@styled-icons/heroicons-outline";
// #region styled components
const mainInputFontSize = 16;
@@ -100,6 +105,8 @@ interface ComboBoxProps {
highlightedCodeSections: (RangeInFile & { contents: string })[];
deleteContextItems: (indices: number[]) => void;
onTogglePin: () => void;
+ onToggleAddContext: () => void;
+ addingHighlightedCode: boolean;
}
const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
@@ -249,6 +256,19 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
</Ul>
</div>
<div className="px-2 flex gap-2 items-center flex-wrap">
+ {highlightedCodeSections.length === 0 && (
+ <HeaderButtonWithText
+ text={
+ props.addingHighlightedCode ? "Adding Context" : "Add Context"
+ }
+ onClick={() => {
+ props.onToggleAddContext();
+ }}
+ inverted={props.addingHighlightedCode}
+ >
+ <Plus size="1.6em" />
+ </HeaderButtonWithText>
+ )}
{highlightedCodeSections.length > 0 && (
<>
<HeaderButtonWithText
@@ -305,9 +325,8 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
))}
<span className="text-trueGray-400 ml-auto mr-4 text-xs">
- Highlight code to include as context.{" "}
- {highlightedCodeSections.length === 0 &&
- "Otherwise using entire currently open file."}
+ Highlight code to include as context. Currently open file included by
+ default. {highlightedCodeSections.length === 0 && ""}
</span>
</div>
<ContextDropdown
diff --git a/extension/react-app/src/components/PillButton.tsx b/extension/react-app/src/components/PillButton.tsx
index 2352c3ad..5a02c6b2 100644
--- a/extension/react-app/src/components/PillButton.tsx
+++ b/extension/react-app/src/components/PillButton.tsx
@@ -15,6 +15,8 @@ const Button = styled.button`
background-color: white;
color: black;
}
+
+ cursor: pointer;
`;
interface PillButtonProps {
@@ -39,26 +41,13 @@ const PillButton = (props: PillButtonProps) => {
props.onHover(false);
}
}}
+ onClick={() => {
+ if (props.onDelete) {
+ props.onDelete();
+ }
+ }}
>
- <div
- style={{ display: "grid", gridTemplateColumns: "1fr auto", gap: "4px" }}
- >
- <span
- style={{
- cursor: "pointer",
- color: "red",
- borderRight: "1px solid black",
- paddingRight: "4px",
- }}
- onClick={() => {
- props.onDelete?.();
- props.onHover?.(false);
- }}
- >
- <XMark style={{ padding: "0px" }} size="1.2em" strokeWidth="2px" />
- </span>
- <span>{props.title}</span>
- </div>
+ {props.title}
</Button>
);
};
diff --git a/extension/react-app/src/components/UserInputContainer.tsx b/extension/react-app/src/components/UserInputContainer.tsx
index 44fdba38..a72f6098 100644
--- a/extension/react-app/src/components/UserInputContainer.tsx
+++ b/extension/react-app/src/components/UserInputContainer.tsx
@@ -14,7 +14,7 @@ interface UserInputContainerProps {
historyNode: HistoryNode;
}
-const StyledDiv = styled.div`
+const StyledDiv = styled.div<{ hidden: boolean }>`
background-color: rgb(50 50 50);
padding: 8px;
padding-left: 16px;
@@ -24,6 +24,8 @@ const StyledDiv = styled.div`
font-size: 13px;
display: flex;
align-items: center;
+ visibility: ${(props) => (props.hidden ? "hidden" : "visible")};
+ height: ${(props) => (props.hidden ? "0px" : "auto")};
`;
const UserInputContainer = (props: UserInputContainerProps) => {
diff --git a/extension/react-app/src/hooks/ContinueGUIClientProtocol.ts b/extension/react-app/src/hooks/ContinueGUIClientProtocol.ts
index 96ea7ab3..f123bb2b 100644
--- a/extension/react-app/src/hooks/ContinueGUIClientProtocol.ts
+++ b/extension/react-app/src/hooks/ContinueGUIClientProtocol.ts
@@ -22,6 +22,8 @@ abstract class AbstractContinueGUIClientProtocol {
abstract deleteAtIndex(index: number): void;
abstract deleteContextAtIndices(indices: number[]): void;
+
+ abstract toggleAddingHighlightedCode(): void;
}
export default AbstractContinueGUIClientProtocol;
diff --git a/extension/react-app/src/hooks/useContinueGUIProtocol.ts b/extension/react-app/src/hooks/useContinueGUIProtocol.ts
index e950387c..49f200ae 100644
--- a/extension/react-app/src/hooks/useContinueGUIProtocol.ts
+++ b/extension/react-app/src/hooks/useContinueGUIProtocol.ts
@@ -74,6 +74,10 @@ class ContinueGUIClientProtocol extends AbstractContinueGUIClientProtocol {
deleteContextAtIndices(indices: number[]) {
this.messenger.send("delete_context_at_indices", { indices });
}
+
+ toggleAddingHighlightedCode(): void {
+ this.messenger.send("toggle_adding_highlighted_code", {});
+ }
}
export default ContinueGUIClientProtocol;
diff --git a/extension/react-app/src/tabs/gui.tsx b/extension/react-app/src/tabs/gui.tsx
index bbf0b126..851045d5 100644
--- a/extension/react-app/src/tabs/gui.tsx
+++ b/extension/react-app/src/tabs/gui.tsx
@@ -71,6 +71,7 @@ function GUI(props: GUIProps) {
const [waitingForSteps, setWaitingForSteps] = useState(false);
const [userInputQueue, setUserInputQueue] = useState<string[]>([]);
const [highlightedRanges, setHighlightedRanges] = useState([]);
+ const [addingHighlightedCode, setAddingHighlightedCode] = useState(false);
const [availableSlashCommands, setAvailableSlashCommands] = useState<
{ name: string; description: string }[]
>([]);
@@ -157,6 +158,7 @@ function GUI(props: GUIProps) {
setHistory(state.history);
setHighlightedRanges(state.highlighted_ranges);
setUserInputQueue(state.user_input_queue);
+ setAddingHighlightedCode(state.adding_highlighted_code);
setAvailableSlashCommands(
state.slash_commands.map((c: any) => {
return {
@@ -361,6 +363,10 @@ function GUI(props: GUIProps) {
onTogglePin={() => {
setPinned((prev: boolean) => !prev);
}}
+ onToggleAddContext={() => {
+ client?.toggleAddingHighlightedCode();
+ }}
+ addingHighlightedCode={addingHighlightedCode}
/>
<ContinueButton onClick={onMainTextInput} />
</TopGUIDiv>
diff --git a/extension/src/commands.ts b/extension/src/commands.ts
index 8072353b..4414a171 100644
--- a/extension/src/commands.ts
+++ b/extension/src/commands.ts
@@ -12,6 +12,8 @@ import {
acceptAllSuggestionsCommand,
rejectAllSuggestionsCommand,
} from "./suggestions";
+
+import { acceptDiffCommand, rejectDiffCommand } from "./diffs";
import * as bridge from "./bridge";
import { debugPanelWebview } from "./debugPanel";
import { sendTelemetryEvent, TelemetryEvent } from "./telemetry";
@@ -51,6 +53,8 @@ const commandsMap: { [command: string]: (...args: any) => any } = {
"continue.suggestionUp": suggestionUpCommand,
"continue.acceptSuggestion": acceptSuggestionCommand,
"continue.rejectSuggestion": rejectSuggestionCommand,
+ "continue.acceptDiff": acceptDiffCommand,
+ "continue.rejectDiff": rejectDiffCommand,
"continue.acceptAllSuggestions": acceptAllSuggestionsCommand,
"continue.rejectAllSuggestions": rejectAllSuggestionsCommand,
"continue.focusContinueInput": async () => {
diff --git a/extension/src/continueIdeClient.ts b/extension/src/continueIdeClient.ts
index b9969858..90547edc 100644
--- a/extension/src/continueIdeClient.ts
+++ b/extension/src/continueIdeClient.ts
@@ -15,6 +15,10 @@ import {
import { FileEditWithFullContents } from "../schema/FileEditWithFullContents";
import fs = require("fs");
import { WebsocketMessenger } from "./util/messenger";
+import * as path from "path";
+import * as os from "os";
+import { diffManager } from "./diffs";
+
class IdeProtocolClient {
private messenger: WebsocketMessenger | null = null;
private readonly context: vscode.ExtensionContext;
@@ -239,40 +243,8 @@ class IdeProtocolClient {
);
}
- contentProvider: vscode.Disposable | null = null;
-
showDiff(filepath: string, replacement: string) {
- const myProvider = new (class
- implements vscode.TextDocumentContentProvider
- {
- onDidChangeEmitter = new vscode.EventEmitter<vscode.Uri>();
- onDidChange = this.onDidChangeEmitter.event;
- provideTextDocumentContent = (uri: vscode.Uri) => {
- return replacement;
- };
- })();
- this.contentProvider = vscode.workspace.registerTextDocumentContentProvider(
- "continueDiff",
- myProvider
- );
-
- // Call the event fire
- const diffFilename = `continueDiff://${filepath}`;
- myProvider.onDidChangeEmitter.fire(vscode.Uri.parse(diffFilename));
-
- const leftUri = vscode.Uri.file(filepath);
- const rightUri = vscode.Uri.parse(diffFilename);
- const title = "Continue Diff";
- vscode.commands
- .executeCommand("vscode.diff", leftUri, rightUri, title)
- .then(
- () => {
- console.log("Diff view opened successfully");
- },
- (error) => {
- console.error("Error opening diff view:", error);
- }
- );
+ diffManager.writeDiff(filepath, replacement);
}
openFile(filepath: string) {
diff --git a/extension/src/diffs.ts b/extension/src/diffs.ts
new file mode 100644
index 00000000..19ec80ab
--- /dev/null
+++ b/extension/src/diffs.ts
@@ -0,0 +1,114 @@
+import * as os from "os";
+import * as path from "path";
+import * as fs from "fs";
+import * as vscode from "vscode";
+
+interface DiffInfo {
+ originalFilepath: string;
+ newFilepath: string;
+ editor?: vscode.TextEditor;
+}
+
+export const DIFF_DIRECTORY = path.join(os.homedir(), ".continue", "diffs");
+
+class DiffManager {
+ // Create a temporary file in the global .continue directory which displays the updated version
+ // Doing this because virtual files are read-only
+ private diffs: Map<string, DiffInfo> = new Map();
+
+ constructor() {
+ // Make sure the diff directory exists
+ if (!fs.existsSync(DIFF_DIRECTORY)) {
+ fs.mkdirSync(DIFF_DIRECTORY, {
+ recursive: true,
+ });
+ }
+ }
+
+ private escapeFilepath(filepath: string): string {
+ return filepath.replace(/\\/g, "_").replace(/\//g, "_");
+ }
+
+ private openDiffEditor(
+ originalFilepath: string,
+ newFilepath: string,
+ newContent: string
+ ): vscode.TextEditor {
+ const rightUri = vscode.Uri.parse(newFilepath);
+ const leftUri = vscode.Uri.file(originalFilepath);
+ const title = "Continue Diff";
+ vscode.commands.executeCommand("vscode.diff", leftUri, rightUri, title);
+
+ const editor = vscode.window.activeTextEditor;
+ if (!editor) {
+ throw new Error("No active text editor found for Continue Diff");
+ }
+ return editor;
+ }
+
+ writeDiff(originalFilepath: string, newContent: string): string {
+ // Create or update existing diff
+ const newFilepath = path.join(
+ DIFF_DIRECTORY,
+ this.escapeFilepath(originalFilepath)
+ );
+ fs.writeFileSync(newFilepath, newContent);
+
+ // Open the diff editor if this is a new diff
+ if (!this.diffs.has(newFilepath)) {
+ const diffInfo: DiffInfo = {
+ originalFilepath,
+ newFilepath,
+ };
+ diffInfo.editor = this.openDiffEditor(
+ originalFilepath,
+ newFilepath,
+ newContent
+ );
+ this.diffs.set(newFilepath, diffInfo);
+ }
+ return newFilepath;
+ }
+
+ cleanUpDiff(diffInfo: DiffInfo) {
+ // Close the editor, remove the record, delete the file
+ if (diffInfo.editor) {
+ vscode.window.showTextDocument(diffInfo.editor.document);
+ vscode.commands.executeCommand("workbench.action.closeActiveEditor");
+ }
+ this.diffs.delete(diffInfo.newFilepath);
+ fs.unlinkSync(diffInfo.newFilepath);
+ }
+
+ acceptDiff(newFilepath: string) {
+ // Get the diff info, copy new file to original, then delete from record and close the corresponding editor
+ const diffInfo = this.diffs.get(newFilepath);
+ if (!diffInfo) {
+ return;
+ }
+ fs.writeFileSync(
+ diffInfo.originalFilepath,
+ fs.readFileSync(diffInfo.newFilepath)
+ );
+ this.cleanUpDiff(diffInfo);
+ }
+
+ rejectDiff(newFilepath: string) {
+ const diffInfo = this.diffs.get(newFilepath);
+ if (!diffInfo) {
+ return;
+ }
+
+ this.cleanUpDiff(diffInfo);
+ }
+}
+
+export const diffManager = new DiffManager();
+
+export async function acceptDiffCommand(newFilepath: string) {
+ diffManager.acceptDiff(newFilepath);
+}
+
+export async function rejectDiffCommand(newFilepath: string) {
+ diffManager.rejectDiff(newFilepath);
+}
diff --git a/extension/src/lang-server/codeLens.ts b/extension/src/lang-server/codeLens.ts
index 3bd4f153..08435a3b 100644
--- a/extension/src/lang-server/codeLens.ts
+++ b/extension/src/lang-server/codeLens.ts
@@ -1,6 +1,8 @@
import * as vscode from "vscode";
import { editorToSuggestions, editorSuggestionsLocked } from "../suggestions";
-
+import * as path from "path";
+import * as os from "os";
+import { DIFF_DIRECTORY } from "../diffs";
class SuggestionsCodeLensProvider implements vscode.CodeLensProvider {
public provideCodeLenses(
document: vscode.TextDocument,
@@ -60,15 +62,51 @@ class SuggestionsCodeLensProvider implements vscode.CodeLensProvider {
}
}
+class DiffViewerCodeLensProvider implements vscode.CodeLensProvider {
+ public provideCodeLenses(
+ document: vscode.TextDocument,
+ token: vscode.CancellationToken
+ ): vscode.CodeLens[] | Thenable<vscode.CodeLens[]> {
+ if (path.dirname(document.uri.fsPath) !== DIFF_DIRECTORY) {
+ return [];
+ } else {
+ const codeLenses: vscode.CodeLens[] = [];
+ const range = new vscode.Range(0, 0, 0, 0);
+ codeLenses.push(
+ new vscode.CodeLens(range, {
+ title: "Accept ✅",
+ command: "continue.acceptDiff",
+ arguments: [document.uri.fsPath],
+ }),
+ new vscode.CodeLens(range, {
+ title: "Reject ❌",
+ command: "continue.rejectDiff",
+ arguments: [document.uri.fsPath],
+ })
+ );
+ return codeLenses;
+ }
+ }
+}
+
+let diffsCodeLensDisposable: vscode.Disposable | undefined = undefined;
let suggestionsCodeLensDisposable: vscode.Disposable | undefined = undefined;
export function registerAllCodeLensProviders(context: vscode.ExtensionContext) {
if (suggestionsCodeLensDisposable) {
suggestionsCodeLensDisposable.dispose();
}
+ if (diffsCodeLensDisposable) {
+ diffsCodeLensDisposable.dispose();
+ }
suggestionsCodeLensDisposable = vscode.languages.registerCodeLensProvider(
"*",
new SuggestionsCodeLensProvider()
);
+ diffsCodeLensDisposable = vscode.languages.registerCodeLensProvider(
+ "*",
+ new DiffViewerCodeLensProvider()
+ );
context.subscriptions.push(suggestionsCodeLensDisposable);
+ context.subscriptions.push(diffsCodeLensDisposable);
}