updates based on feedback
This commit is contained in:
parent
59e6cee114
commit
e0704b273b
24 changed files with 290 additions and 204 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import { IDE } from "../..";
|
||||
import { RangeInFileWithContents } from "../../commands/util";
|
||||
import { IDE, RangeInFileWithContents } from "../..";
|
||||
import { PrecalculatedLruCache } from "../../util/LruCache";
|
||||
import {
|
||||
getFullLanguageName,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { RangeInFileWithContents } from "../../../commands/util.js";
|
||||
import { Range } from "../../../index.js";
|
||||
import { countTokens } from "../../../llm/countTokens.js";
|
||||
import { HelperVars } from "../../util/HelperVars.js";
|
||||
import { Range, RangeInFileWithContents } from "../../../";
|
||||
import { countTokens } from "../../../llm/countTokens";
|
||||
import { HelperVars } from "../../util/HelperVars";
|
||||
|
||||
export type AutocompleteSnippet = RangeInFileWithContents & {
|
||||
score?: number;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { RangeInFileWithContents } from "../../../commands/util.js";
|
||||
import { RangeInFileWithContents } from "../../../";
|
||||
|
||||
import { AutocompleteSnippet, jaccardSimilarity } from "./index.js";
|
||||
import { AutocompleteSnippet, jaccardSimilarity } from "./";
|
||||
|
||||
function* slidingWindow(
|
||||
content: string,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import Parser from "web-tree-sitter";
|
||||
|
||||
import { RangeInFileWithContents } from "../../commands/util.js";
|
||||
import { getParserForFile } from "../../util/treeSitter.js";
|
||||
import { RangeInFileWithContents } from "../../";
|
||||
import { getParserForFile } from "../../util/treeSitter";
|
||||
|
||||
export type AstPath = Parser.SyntaxNode[];
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
import { Position, Range, RangeInFile, TabAutocompleteOptions } from "../..";
|
||||
import { RangeInFileWithContents } from "../../commands/util";
|
||||
import {
|
||||
Position,
|
||||
Range,
|
||||
RangeInFile,
|
||||
RangeInFileWithContents,
|
||||
TabAutocompleteOptions,
|
||||
} from "../..";
|
||||
|
||||
export type RecentlyEditedRange = RangeInFile & {
|
||||
timestamp: number;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
import { ContextItemWithId, ILLM, SlashCommand } from "../../";
|
||||
import {
|
||||
ContextItemWithId,
|
||||
ILLM,
|
||||
RangeInFileWithContents,
|
||||
SlashCommand,
|
||||
} from "../../";
|
||||
import {
|
||||
filterCodeBlockLines,
|
||||
filterEnglishLinesAtEnd,
|
||||
|
|
@ -13,10 +18,7 @@ import {
|
|||
dedentAndGetCommonWhitespace,
|
||||
getMarkdownLanguageTagForFile,
|
||||
} from "../../util/";
|
||||
import {
|
||||
ctxItemToRifWithContents,
|
||||
type RangeInFileWithContents,
|
||||
} from "../util";
|
||||
import { ctxItemToRifWithContents } from "../util";
|
||||
|
||||
const PROMPT = `Take the file prefix and suffix into account, but only rewrite the code_to_edit as specified in the user_request. The code you write in modified_code_to_edit will replace the code between the code_to_edit tags. Do NOT preface your answer or write anything other than code. The </modified_code_to_edit> tag should be written to indicate the end of the modified code section. Do not ever use nested tags.
|
||||
|
||||
|
|
@ -478,10 +480,18 @@ const EditSlashCommand: SlashCommand = {
|
|||
messages = rendered;
|
||||
}
|
||||
|
||||
const completion = llm.streamComplete(rendered as string, new AbortController().signal, {
|
||||
maxTokens: Math.min(maxTokens, Math.floor(llm.contextLength / 2), 4096),
|
||||
raw: true,
|
||||
});
|
||||
const completion = llm.streamComplete(
|
||||
rendered as string,
|
||||
new AbortController().signal,
|
||||
{
|
||||
maxTokens: Math.min(
|
||||
maxTokens,
|
||||
Math.floor(llm.contextLength / 2),
|
||||
4096,
|
||||
),
|
||||
raw: true,
|
||||
},
|
||||
);
|
||||
let lineStream = streamLines(completion);
|
||||
|
||||
lineStream = filterEnglishLinesAtStart(lineStream);
|
||||
|
|
@ -494,14 +504,18 @@ const EditSlashCommand: SlashCommand = {
|
|||
);
|
||||
} else {
|
||||
async function* gen() {
|
||||
for await (const chunk of llm.streamChat(messages, new AbortController().signal,{
|
||||
temperature: 0.5, // TODO
|
||||
maxTokens: Math.min(
|
||||
maxTokens,
|
||||
Math.floor(llm.contextLength / 2),
|
||||
4096,
|
||||
),
|
||||
})) {
|
||||
for await (const chunk of llm.streamChat(
|
||||
messages,
|
||||
new AbortController().signal,
|
||||
{
|
||||
temperature: 0.5, // TODO
|
||||
maxTokens: Math.min(
|
||||
maxTokens,
|
||||
Math.floor(llm.contextLength / 2),
|
||||
4096,
|
||||
),
|
||||
},
|
||||
)) {
|
||||
yield stripImages(chunk.content);
|
||||
}
|
||||
}
|
||||
|
|
@ -609,7 +623,10 @@ ${lines.join("\n")}
|
|||
|
||||
Please briefly explain the changes made to the code above. Give no more than 2-3 sentences, and use markdown bullet points:`;
|
||||
|
||||
for await (const update of llm.streamComplete(prompt, new AbortController().signal)) {
|
||||
for await (const update of llm.streamComplete(
|
||||
prompt,
|
||||
new AbortController().signal,
|
||||
)) {
|
||||
yield update;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,4 @@
|
|||
import { ContextItemWithId } from "../";
|
||||
|
||||
export interface RangeInFileWithContents {
|
||||
filepath: string;
|
||||
range: {
|
||||
start: { line: number; character: number };
|
||||
end: { line: number; character: number };
|
||||
};
|
||||
contents: string;
|
||||
}
|
||||
import { ContextItemWithId, RangeInFileWithContents } from "../";
|
||||
|
||||
export function ctxItemToRifWithContents(
|
||||
item: ContextItemWithId,
|
||||
|
|
|
|||
33
core/index.d.ts
vendored
33
core/index.d.ts
vendored
|
|
@ -106,7 +106,7 @@ export interface ILLM extends LLMOptions {
|
|||
complete(
|
||||
prompt: string,
|
||||
signal: AbortSignal,
|
||||
options?: LLMFullCompletionOptions
|
||||
options?: LLMFullCompletionOptions,
|
||||
): Promise<string>;
|
||||
|
||||
streamComplete(
|
||||
|
|
@ -1012,6 +1012,37 @@ interface ModelRoles {
|
|||
repoMapFileSelection?: string;
|
||||
}
|
||||
|
||||
export type EditStatus =
|
||||
| "not-started"
|
||||
| "streaming"
|
||||
| "accepting"
|
||||
| "accepting:full-diff"
|
||||
| "done";
|
||||
|
||||
export type ApplyStateStatus =
|
||||
| "streaming" // Changes are being applied to the file
|
||||
| "done" // All changes have been applied, awaiting user to accept/reject
|
||||
| "closed"; // All changes have been applied. Note that for new files, we immediately set the status to "closed"
|
||||
|
||||
export interface ApplyState {
|
||||
streamId: string;
|
||||
status?: ApplyStateStatus;
|
||||
numDiffs?: number;
|
||||
filepath?: string;
|
||||
fileContent?: string;
|
||||
}
|
||||
|
||||
export interface RangeInFileWithContents {
|
||||
filepath: string;
|
||||
range: {
|
||||
start: { line: number; character: number };
|
||||
end: { line: number; character: number };
|
||||
};
|
||||
contents: string;
|
||||
}
|
||||
|
||||
export type CodeToEdit = RangeInFileWithContents | FileWithContents;
|
||||
|
||||
/**
|
||||
* Represents the configuration for a quick action in the Code Lens.
|
||||
* Quick actions are custom commands that can be added to function and class declarations.
|
||||
|
|
|
|||
|
|
@ -1,8 +1,14 @@
|
|||
import { ToIdeFromWebviewOrCoreProtocol } from "./ide.js";
|
||||
import { ToWebviewFromIdeOrCoreProtocol } from "./webview.js";
|
||||
import { ToIdeFromWebviewOrCoreProtocol } from "./ide";
|
||||
import { ToWebviewFromIdeOrCoreProtocol } from "./webview";
|
||||
|
||||
import type { RangeInFileWithContents } from "../commands/util.js";
|
||||
import type { ContextSubmenuItem, MessageContent } from "../index.js";
|
||||
import type {
|
||||
ApplyState,
|
||||
CodeToEdit,
|
||||
ContextSubmenuItem,
|
||||
EditStatus,
|
||||
MessageContent,
|
||||
RangeInFileWithContents,
|
||||
} from "../";
|
||||
|
||||
export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & {
|
||||
onLoad: [
|
||||
|
|
@ -54,26 +60,6 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & {
|
|||
"edit/escape": [undefined, void];
|
||||
};
|
||||
|
||||
export type EditStatus =
|
||||
| "not-started"
|
||||
| "streaming"
|
||||
| "accepting"
|
||||
| "accepting:full-diff"
|
||||
| "done";
|
||||
|
||||
export type ApplyStateStatus =
|
||||
| "streaming" // Changes are being applied to the file
|
||||
| "done" // All changes have been applied, awaiting user to accept/reject
|
||||
| "closed"; // All changes have been applied. Note that for new files, we immediately set the status to "closed"
|
||||
|
||||
export interface ApplyState {
|
||||
streamId: string;
|
||||
status?: ApplyStateStatus;
|
||||
numDiffs?: number;
|
||||
filepath?: string;
|
||||
fileContent?: string;
|
||||
}
|
||||
|
||||
export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
|
||||
setInactive: [undefined, void];
|
||||
submitMessage: [{ message: any }, void]; // any -> JSONContent from TipTap
|
||||
|
|
@ -94,7 +80,7 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
|
|||
},
|
||||
void,
|
||||
];
|
||||
addCodeToEdit: [RangeInFileWithContents, void];
|
||||
addCodeToEdit: [CodeToEdit, void];
|
||||
navigateTo: [{ path: string; toggle?: boolean }, void];
|
||||
addModel: [undefined, void];
|
||||
|
||||
|
|
@ -118,4 +104,5 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
|
|||
setEditStatus: [{ status: EditStatus; fileAfterEdit?: string }, void];
|
||||
exitEditMode: [undefined, void];
|
||||
focusEdit: [undefined, void];
|
||||
focusEditWithoutClear: [undefined, void];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import { GetLspDefinitionsFunction } from "core/autocomplete/CompletionProvider"
|
|||
import { AutocompleteLanguageInfo } from "core/autocomplete/constants/AutocompleteLanguageInfo";
|
||||
import { AutocompleteSnippet } from "core/autocomplete/context/ranking";
|
||||
import { getAst, getTreePathAtCursor } from "core/autocomplete/util/ast";
|
||||
import { RangeInFileWithContents } from "core/commands/util";
|
||||
import {
|
||||
FUNCTION_BLOCK_NODE_TYPES,
|
||||
FUNCTION_DECLARATION_NODE_TYPEs,
|
||||
|
|
@ -10,7 +9,7 @@ import {
|
|||
import { intersection } from "core/util/ranges";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
import type { IDE, Range, RangeInFile } from "core";
|
||||
import type { IDE, Range, RangeInFile, RangeInFileWithContents } from "core";
|
||||
import type Parser from "web-tree-sitter";
|
||||
|
||||
type GotoProviderName =
|
||||
|
|
@ -134,7 +133,9 @@ async function crawlTypes(
|
|||
|
||||
// Parse AST
|
||||
const ast = await getAst(rif.filepath, contents);
|
||||
if (!ast) {return results;}
|
||||
if (!ast) {
|
||||
return results;
|
||||
}
|
||||
const astLineCount = ast.rootNode.text.split("\n").length;
|
||||
|
||||
// Find type identifiers
|
||||
|
|
@ -343,10 +344,14 @@ export const getDefinitionsFromLsp: GetLspDefinitionsFunction = async (
|
|||
): Promise<AutocompleteSnippet[]> => {
|
||||
try {
|
||||
const ast = await getAst(filepath, contents);
|
||||
if (!ast) {return [];}
|
||||
if (!ast) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const treePath = await getTreePathAtCursor(ast, cursorIndex);
|
||||
if (!treePath) {return [];}
|
||||
if (!treePath) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const results: RangeInFileWithContents[] = [];
|
||||
for (const node of treePath.reverse()) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { RangeInFileWithContents } from "core";
|
||||
import { getSymbolsForSnippet } from "core/autocomplete/context/ranking";
|
||||
import { RecentlyEditedRange } from "core/autocomplete/util/types";
|
||||
import { RangeInFileWithContents } from "core/commands/util";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
type VsCodeRecentlyEditedRange = {
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ import * as fs from "node:fs";
|
|||
import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
|
||||
import { ContextMenuConfig } from "core";
|
||||
import { ContextMenuConfig, RangeInFileWithContents } from "core";
|
||||
import { CompletionProvider } from "core/autocomplete/CompletionProvider";
|
||||
import { RangeInFileWithContents } from "core/commands/util";
|
||||
import { ConfigHandler } from "core/config/ConfigHandler";
|
||||
import { getModelByRole } from "core/config/util";
|
||||
import { ContinueServerClient } from "core/continueServer/stubs/client";
|
||||
|
|
@ -201,6 +200,58 @@ function hideGUI() {
|
|||
}
|
||||
}
|
||||
|
||||
async function processDiff(
|
||||
action: "accept" | "reject",
|
||||
sidebar: ContinueGUIWebviewViewProvider,
|
||||
diffManager: DiffManager,
|
||||
ide: VsCodeIde,
|
||||
verticalDiffManager: VerticalDiffManager,
|
||||
newFilepath?: string | vscode.Uri,
|
||||
streamId?: string,
|
||||
) {
|
||||
captureCommandTelemetry(`${action}Diff`);
|
||||
|
||||
let fullPath = newFilepath;
|
||||
|
||||
if (fullPath instanceof vscode.Uri) {
|
||||
fullPath = fullPath.fsPath;
|
||||
} else if (fullPath) {
|
||||
fullPath = getFullyQualifiedPath(ide, fullPath);
|
||||
} else {
|
||||
console.warn(`Unable to resolve filepath: ${newFilepath}`);
|
||||
}
|
||||
|
||||
if (!fullPath) return;
|
||||
|
||||
await ide.openFile(fullPath);
|
||||
|
||||
// Clear vertical diffs depending on action
|
||||
verticalDiffManager.clearForFilepath(fullPath, action === "accept");
|
||||
|
||||
// Accept or reject the diff
|
||||
if (action === "accept") {
|
||||
await diffManager.acceptDiff(fullPath);
|
||||
} else {
|
||||
await diffManager.rejectDiff(fullPath);
|
||||
}
|
||||
|
||||
void sidebar.webviewProtocol.request("setEditStatus", {
|
||||
status: "done",
|
||||
});
|
||||
|
||||
if (streamId) {
|
||||
const fileContent = await ide.readFile(fullPath);
|
||||
|
||||
await sidebar.webviewProtocol.request("updateApplyState", {
|
||||
fileContent,
|
||||
filepath: fullPath,
|
||||
streamId,
|
||||
status: "closed",
|
||||
numDiffs: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Copy everything over from extension.ts
|
||||
const commandsMap: (
|
||||
ide: VsCodeIde,
|
||||
|
|
@ -267,77 +318,34 @@ const commandsMap: (
|
|||
range,
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
"continue.acceptDiff": async (
|
||||
newFilepath?: string | vscode.Uri,
|
||||
streamId?: string,
|
||||
) => {
|
||||
captureCommandTelemetry("acceptDiff");
|
||||
) =>
|
||||
processDiff(
|
||||
"accept",
|
||||
sidebar,
|
||||
diffManager,
|
||||
ide,
|
||||
verticalDiffManager,
|
||||
newFilepath,
|
||||
streamId,
|
||||
),
|
||||
|
||||
let fullPath = newFilepath;
|
||||
|
||||
if (fullPath instanceof vscode.Uri) {
|
||||
fullPath = fullPath.fsPath;
|
||||
} else if (fullPath) {
|
||||
fullPath = getFullyQualifiedPath(ide, fullPath);
|
||||
} else {
|
||||
console.warn(`Unable to resolve filepath: ${newFilepath}`);
|
||||
}
|
||||
|
||||
verticalDiffManager.clearForFilepath(fullPath, true);
|
||||
await diffManager.acceptDiff(fullPath);
|
||||
|
||||
void sidebar.webviewProtocol.request("setEditStatus", {
|
||||
status: "done",
|
||||
});
|
||||
|
||||
if (streamId && fullPath) {
|
||||
const fileContent = await ide.readFile(fullPath);
|
||||
|
||||
await sidebar.webviewProtocol.request("updateApplyState", {
|
||||
fileContent,
|
||||
filepath: fullPath,
|
||||
streamId: streamId,
|
||||
status: "closed",
|
||||
numDiffs: 0,
|
||||
});
|
||||
}
|
||||
},
|
||||
"continue.rejectDiff": async (
|
||||
newFilepath?: string | vscode.Uri,
|
||||
streamId?: string,
|
||||
) => {
|
||||
captureCommandTelemetry("rejectDiff");
|
||||
|
||||
let fullPath = newFilepath;
|
||||
|
||||
if (fullPath instanceof vscode.Uri) {
|
||||
fullPath = fullPath.fsPath;
|
||||
} else if (fullPath) {
|
||||
fullPath = getFullyQualifiedPath(ide, fullPath);
|
||||
} else {
|
||||
console.warn(`Unable to resolve filepath: ${newFilepath}`);
|
||||
}
|
||||
|
||||
verticalDiffManager.clearForFilepath(fullPath, false);
|
||||
await diffManager.rejectDiff(fullPath);
|
||||
void sidebar.webviewProtocol.request("setEditStatus", {
|
||||
status: "done",
|
||||
});
|
||||
|
||||
if (streamId && fullPath) {
|
||||
const fileContent = await ide.readFile(fullPath);
|
||||
|
||||
await sidebar.webviewProtocol.request("updateApplyState", {
|
||||
fileContent,
|
||||
filepath: fullPath,
|
||||
streamId: streamId,
|
||||
status: "closed",
|
||||
numDiffs: 0,
|
||||
});
|
||||
}
|
||||
},
|
||||
) =>
|
||||
processDiff(
|
||||
"reject",
|
||||
sidebar,
|
||||
diffManager,
|
||||
ide,
|
||||
verticalDiffManager,
|
||||
newFilepath,
|
||||
streamId,
|
||||
),
|
||||
"continue.acceptVerticalDiffBlock": (filepath?: string, index?: number) => {
|
||||
captureCommandTelemetry("acceptVerticalDiffBlock");
|
||||
verticalDiffManager.acceptRejectVerticalDiffBlock(true, filepath, index);
|
||||
|
|
@ -453,8 +461,6 @@ const commandsMap: (
|
|||
void addHighlightedCodeToContext(sidebar.webviewProtocol);
|
||||
}
|
||||
},
|
||||
// TODO
|
||||
"continue.focusEditWithoutClear": async () => {},
|
||||
"continue.focusEdit": async () => {
|
||||
captureCommandTelemetry("focusEdit");
|
||||
focusGUI();
|
||||
|
|
@ -501,6 +507,51 @@ const commandsMap: (
|
|||
sidebar.webviewProtocol?.request("focusContinueInput", undefined);
|
||||
}, 30);
|
||||
},
|
||||
"continue.focusEditWithoutClear": async () => {
|
||||
captureCommandTelemetry("focusEditWithoutClear");
|
||||
focusGUI();
|
||||
|
||||
sidebar.webviewProtocol?.request("focusEditWithoutClear", undefined);
|
||||
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
|
||||
const document = editor.document;
|
||||
|
||||
const existingDiff = verticalDiffManager.getHandlerForFile(
|
||||
document.fileName,
|
||||
);
|
||||
|
||||
// If there's a diff currently being applied, then we just toggle focus back to the input
|
||||
if (existingDiff) {
|
||||
sidebar.webviewProtocol?.request("focusContinueInput", undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
const rangeInFileWithContents = getCurrentlyHighlightedCode(false);
|
||||
|
||||
if (rangeInFileWithContents) {
|
||||
sidebar.webviewProtocol?.request(
|
||||
"addCodeToEdit",
|
||||
rangeInFileWithContents,
|
||||
);
|
||||
} else {
|
||||
const filepath = document.uri.fsPath;
|
||||
const contents = document.getText();
|
||||
|
||||
sidebar.webviewProtocol?.request("addCodeToEdit", {
|
||||
filepath,
|
||||
contents,
|
||||
});
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
sidebar.webviewProtocol?.request("focusContinueInput", undefined);
|
||||
}, 30);
|
||||
},
|
||||
"continue.exitEditMode": async () => {
|
||||
captureCommandTelemetry("exitEditMode");
|
||||
await sidebar.webviewProtocol?.request("exitEditMode", undefined);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import { ApplyState } from "core/protocol/ideWebview";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
import {
|
||||
|
|
@ -10,7 +9,7 @@ import {
|
|||
} from "./decorations";
|
||||
|
||||
import type { VerticalDiffCodeLens } from "./manager";
|
||||
import type { DiffLine } from "core";
|
||||
import type { ApplyState, DiffLine } from "core";
|
||||
|
||||
export interface VerticalDiffHandlerOptions {
|
||||
input?: string;
|
||||
|
|
|
|||
|
|
@ -255,7 +255,9 @@ export class VsCodeMessenger {
|
|||
llm,
|
||||
fastLlm,
|
||||
);
|
||||
|
||||
const verticalDiffManager = await this.verticalDiffManagerPromise;
|
||||
|
||||
if (instant) {
|
||||
await verticalDiffManager.streamDiffLines(
|
||||
diffLines,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import {
|
|||
setEditStatus,
|
||||
addCodeToEdit,
|
||||
focusEdit,
|
||||
clearCodeToEdit,
|
||||
} from "../redux/slices/editModeState";
|
||||
import { setShowDialog } from "../redux/slices/uiStateSlice";
|
||||
import {
|
||||
|
|
@ -192,6 +193,16 @@ const Layout = () => {
|
|||
|
||||
useWebviewListener(
|
||||
"focusEdit",
|
||||
async () => {
|
||||
dispatch(focusEdit());
|
||||
dispatch(clearCodeToEdit());
|
||||
navigate("/edit");
|
||||
},
|
||||
[navigate],
|
||||
);
|
||||
|
||||
useWebviewListener(
|
||||
"focusEditWithoutClear",
|
||||
async () => {
|
||||
dispatch(focusEdit());
|
||||
navigate("/edit");
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ export default function AcceptRejectAllButtons({
|
|||
onAcceptOrReject,
|
||||
}: AcceptRejectAllButtonsProps) {
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
// To handle the case of a single-range edit
|
||||
const hasSinglePendingApplyStates = pendingApplyStates.length === 1;
|
||||
|
||||
async function handleAcceptOrReject(status: "acceptDiff" | "rejectDiff") {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import Image from "@tiptap/extension-image";
|
|||
import Paragraph from "@tiptap/extension-paragraph";
|
||||
import Placeholder from "@tiptap/extension-placeholder";
|
||||
import Text from "@tiptap/extension-text";
|
||||
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
||||
import { Plugin } from "@tiptap/pm/state";
|
||||
import { Editor, EditorContent, JSONContent, useEditor } from "@tiptap/react";
|
||||
import {
|
||||
ContextItemWithId,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { ToWebviewProtocol } from "core/protocol";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { useWebviewListener } from "./useWebviewListener";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import { InformationCircleIcon, PlusIcon } from "@heroicons/react/24/outline";
|
||||
import { PlusIcon } from "@heroicons/react/24/outline";
|
||||
import { useContext } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { CodeToEdit, removeCodeToEdit } from "../../redux/slices/editModeState";
|
||||
import { removeCodeToEdit } from "../../redux/slices/editModeState";
|
||||
import { RootState } from "../../redux/store";
|
||||
import CodeToEditListItem from "./CodeToEditListItem";
|
||||
import { RangeInFileWithContents } from "core/commands/util";
|
||||
import { vscEditorBackground } from "../../components";
|
||||
import { setShouldAddFileForEditing } from "../../redux/slices/uiStateSlice";
|
||||
import { CodeToEdit, RangeInFileWithContents } from "core";
|
||||
|
||||
export default function WorkingSet() {
|
||||
const dispatch = useDispatch();
|
||||
|
|
@ -16,6 +16,15 @@ export default function WorkingSet() {
|
|||
|
||||
const hasCodeToEdit = editModeState.codeToEdit.length > 0;
|
||||
|
||||
const addFileText = hasCodeToEdit ? "Add file" : "Add a file to get started";
|
||||
|
||||
const title =
|
||||
editModeState.codeToEdit.length === 0
|
||||
? "Code to edit"
|
||||
: editModeState.codeToEdit.length === 1
|
||||
? "Code to edit (1 item)"
|
||||
: `Code to edit (${editModeState.codeToEdit.length} items)`;
|
||||
|
||||
function onDelete(rif: RangeInFileWithContents) {
|
||||
dispatch(removeCodeToEdit(rif));
|
||||
}
|
||||
|
|
@ -48,37 +57,24 @@ export default function WorkingSet() {
|
|||
));
|
||||
|
||||
return (
|
||||
<div
|
||||
className="mx-1 flex flex-col rounded-t-lg px-1 pb-1"
|
||||
style={{ backgroundColor: vscEditorBackground }}
|
||||
>
|
||||
<div className="flex items-center justify-between gap-1.5 px-1 py-1.5 text-xs text-neutral-500">
|
||||
<span>Code to edit</span>
|
||||
<div className="bg-vsc-editor-background border-vsc-input-border mx-1 flex flex-col rounded-t-lg border border-b-0 border-solid p-1">
|
||||
<div className="text-lightgray flex items-center justify-between gap-1.5 px-1 py-1.5 text-xs">
|
||||
<span>{title}</span>
|
||||
|
||||
<span
|
||||
className="flex cursor-pointer items-center justify-between gap-1 rounded px-1 py-0.5 transition-colors hover:bg-white/10"
|
||||
className="hover:bg-lightgray hover:text-vsc-foreground flex cursor-pointer items-center justify-between gap-1 rounded px-1 py-0.5 transition-colors hover:bg-opacity-20"
|
||||
onClick={onClickAddFileToCodeToEdit}
|
||||
>
|
||||
<PlusIcon className="inline h-3 w-3" />
|
||||
<span>Add file</span>
|
||||
<span>{addFileText}</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="scrollbar-hide max-h-[50vh] overflow-y-auto">
|
||||
{hasCodeToEdit ? (
|
||||
<ul className="mb-1.5 mt-0 list-outside list-none space-y-1.5 pl-0">
|
||||
{codeToEditItems}
|
||||
</ul>
|
||||
) : (
|
||||
<span
|
||||
className="my-1.5 flex cursor-pointer items-center gap-1 rounded p-1 transition-colors hover:bg-white/10"
|
||||
onClick={onClickAddFileToCodeToEdit}
|
||||
>
|
||||
<PlusIcon className="inline h-3 w-3" />
|
||||
<span>Add a file to get started</span>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{hasCodeToEdit && (
|
||||
<ul className="scrollbar-hide mb-1.5 mt-1 max-h-[50vh] list-outside list-none space-y-1.5 overflow-y-auto pl-0">
|
||||
{codeToEditItems}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ import { useState } from "react";
|
|||
import StyledMarkdownPreview from "../../components/markdown/StyledMarkdownPreview";
|
||||
import { getMarkdownLanguageTagForFile } from "core/util";
|
||||
import styled from "styled-components";
|
||||
import { CodeToEdit } from "../../redux/slices/editModeState";
|
||||
import { CodeToEdit } from "core";
|
||||
|
||||
export interface CodeToEditListItemProps {
|
||||
code: CodeToEdit;
|
||||
onDelete: (code: CodeToEdit) => void;
|
||||
onClickFilename: (code: CodeToEdit) => void;
|
||||
onDelete: (codeToEdit: CodeToEdit) => void;
|
||||
onClickFilename: (codeToEdit: CodeToEdit) => void;
|
||||
}
|
||||
|
||||
// Easiest method to overwrite the top level styling of the markdown preview
|
||||
|
|
@ -26,7 +26,7 @@ const NoPaddingWrapper = styled.div`
|
|||
|
||||
pre {
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
padding: 0px 0px 0px 10px !important;
|
||||
}
|
||||
`;
|
||||
|
||||
|
|
@ -35,13 +35,13 @@ export default function CodeToEditListItem({
|
|||
onDelete,
|
||||
onClickFilename,
|
||||
}: CodeToEditListItemProps) {
|
||||
const [showCodeSnippet, setShowCodeSnippet] = useState(true);
|
||||
const [showCodeSnippet, setShowCodeSnippet] = useState(false);
|
||||
|
||||
const filepath = code.filepath.split("/").pop() || code.filepath;
|
||||
let title = filepath;
|
||||
|
||||
if ("range" in code) {
|
||||
title += `(${code.range.start.line + 1} - ${code.range.end.line + 1})`;
|
||||
title += ` (${code.range.start.line + 1} - ${code.range.end.line + 1})`;
|
||||
}
|
||||
|
||||
const source =
|
||||
|
|
@ -54,11 +54,11 @@ export default function CodeToEditListItem({
|
|||
|
||||
return (
|
||||
<li
|
||||
className="flex cursor-pointer flex-col rounded border border-solid border-neutral-500 shadow-sm transition-transform"
|
||||
className="flex cursor-pointer flex-col"
|
||||
onClick={() => setShowCodeSnippet((showCodeSnippet) => !showCodeSnippet)}
|
||||
>
|
||||
<div
|
||||
className={`flex justify-between px-2 py-1 ${showCodeSnippet ? "border-x-0 border-b border-t-0 border-solid border-neutral-500" : ""}`}
|
||||
className={`hover:bg-lightgray hover:text-vsc-foreground flex justify-between rounded px-2 py-1 transition-colors hover:bg-opacity-20 ${showCodeSnippet && "text-vsc-foreground bg-lightgray bg-opacity-20"}`}
|
||||
>
|
||||
<div className="flex items-center gap-0.5">
|
||||
{showCodeSnippet ? (
|
||||
|
|
@ -67,7 +67,7 @@ export default function CodeToEditListItem({
|
|||
e.stopPropagation();
|
||||
setShowCodeSnippet(false);
|
||||
}}
|
||||
className="h-3.5 w-3.5 cursor-pointer rounded-md rounded-sm p-0.5 text-gray-400 transition-colors hover:bg-white/10"
|
||||
className="text-lightgray hover:bg-lightgray hover:text-vsc-foreground h-3.5 w-3.5 cursor-pointer rounded-md rounded-sm p-0.5 hover:bg-opacity-20"
|
||||
/>
|
||||
) : (
|
||||
<ChevronRightIcon
|
||||
|
|
@ -75,7 +75,7 @@ export default function CodeToEditListItem({
|
|||
e.stopPropagation();
|
||||
setShowCodeSnippet(true);
|
||||
}}
|
||||
className="h-3.5 w-3.5 cursor-pointer rounded-md rounded-sm p-0.5 text-gray-400 transition-colors hover:bg-white/10"
|
||||
className="text-lightgray hover:bg-lightgray hover:text-vsc-foreground h-3.5 w-3.5 cursor-pointer rounded-md rounded-sm p-0.5 hover:bg-opacity-20"
|
||||
/>
|
||||
)}
|
||||
<FileIcon filename={code.filepath} height={"18px"} width={"18px"} />
|
||||
|
|
@ -95,7 +95,7 @@ export default function CodeToEditListItem({
|
|||
e.stopPropagation();
|
||||
onDelete(code);
|
||||
}}
|
||||
className="h-3.5 w-3.5 cursor-pointer rounded-md rounded-sm p-0.5 text-gray-400 transition-colors hover:bg-white/10"
|
||||
className="text-lightgray hover:bg-lightgray hover:text-vsc-foreground h-3.5 w-3.5 cursor-pointer rounded-md rounded-sm p-0.5 hover:bg-opacity-20"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import useChatHandler from "../../hooks/useChatHandler";
|
|||
import AcceptRejectAllButtons from "../../components/StepContainer/AcceptRejectAllButtons";
|
||||
import ContinueInputBox from "../../components/mainInput/ContinueInputBox";
|
||||
import StepContainer from "../../components/StepContainer";
|
||||
import styled from "styled-components";
|
||||
import getMultifileEditPrompt from "./getMultifileEditPrompt";
|
||||
import { RangeInFileWithContents } from "core/commands/util";
|
||||
|
||||
|
|
@ -121,14 +120,6 @@ export default function Edit() {
|
|||
stripImages(userInstructions),
|
||||
].join("\n\n");
|
||||
|
||||
const codeToEdit = editModeState.codeToEdit[0];
|
||||
|
||||
let rif: RangeInFileWithContents = {
|
||||
filepath: codeToEdit.filepath,
|
||||
contents: codeToEdit.contents,
|
||||
range: "range" in codeToEdit ? codeToEdit.range : undefined,
|
||||
};
|
||||
|
||||
ideMessenger.post("edit/sendPrompt", {
|
||||
prompt,
|
||||
range: editModeState.codeToEdit[0] as RangeInFileWithContents,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { FileWithContents, MessageContent } from "core";
|
||||
import { RangeInFileWithContents } from "core/commands/util";
|
||||
import { EditStatus } from "core/protocol/ideWebview";
|
||||
|
||||
export type CodeToEdit = RangeInFileWithContents | FileWithContents;
|
||||
import { CodeToEdit, EditStatus, MessageContent } from "core";
|
||||
|
||||
interface EditModeState {
|
||||
editStatus: EditStatus;
|
||||
|
|
@ -20,15 +16,22 @@ const initialState: EditModeState = {
|
|||
isInEditMode: false,
|
||||
};
|
||||
|
||||
function isCodeToEditEqual(a: CodeToEdit, b: CodeToEdit) {
|
||||
return a.filepath === b.filepath && a.contents === b.contents;
|
||||
}
|
||||
|
||||
export const editModeStateSlice = createSlice({
|
||||
name: "editModeState",
|
||||
initialState,
|
||||
reducers: {
|
||||
addCodeToEdit: (state, { payload }: PayloadAction<CodeToEdit>) => {
|
||||
state.codeToEdit.push(payload);
|
||||
state.editStatus = "not-started";
|
||||
state.previousInputs = [];
|
||||
state.fileAfterEdit = undefined;
|
||||
const entryExists = state.codeToEdit.some((entry) =>
|
||||
isCodeToEditEqual(entry, payload),
|
||||
);
|
||||
|
||||
if (!entryExists) {
|
||||
state.codeToEdit.push(payload);
|
||||
}
|
||||
},
|
||||
focusEdit: (state) => {
|
||||
state.isInEditMode = true;
|
||||
|
|
@ -42,11 +45,7 @@ export const editModeStateSlice = createSlice({
|
|||
},
|
||||
removeCodeToEdit: (state, { payload }: PayloadAction<CodeToEdit>) => {
|
||||
state.codeToEdit = state.codeToEdit.filter(
|
||||
(entry) =>
|
||||
!(
|
||||
entry.filepath === payload.filepath &&
|
||||
entry.contents === payload.contents
|
||||
),
|
||||
(entry) => !isCodeToEditEqual(entry, payload),
|
||||
);
|
||||
},
|
||||
clearCodeToEdit: (state) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
|
||||
import { JSONContent } from "@tiptap/react";
|
||||
import {
|
||||
ApplyState,
|
||||
ChatHistoryItem,
|
||||
ChatMessage,
|
||||
Checkpoint,
|
||||
|
|
@ -13,7 +14,6 @@ import {
|
|||
import { BrowserSerializedContinueConfig } from "core/config/load";
|
||||
import { ConfigValidationError } from "core/config/validation";
|
||||
import { stripImages } from "core/llm/images";
|
||||
import { ApplyState } from "core/protocol/ideWebview";
|
||||
import { v4 as uuidv4, v4 } from "uuid";
|
||||
|
||||
// We need this to handle reorderings (e.g. a mid-array deletion) of the messages array.
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ module.exports = {
|
|||
"spin-slow": "spin 6s linear infinite",
|
||||
},
|
||||
colors: {
|
||||
lightgray: "#999998",
|
||||
"vsc-background": "rgb(var(--vsc-background) / <alpha-value>)",
|
||||
"secondary-dark": "rgb(var(--secondary-dark) / <alpha-value>)",
|
||||
"vsc-input-background": "var(--vscode-input-background, rgb(45 45 45))",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue