Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add multifile edits to Edit page #3015

Merged
merged 13 commits into from
Nov 22, 2024
3 changes: 1 addition & 2 deletions core/autocomplete/context/ImportDefinitionsService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IDE } from "../..";
import { RangeInFileWithContents } from "../../commands/util";
import { IDE, RangeInFileWithContents } from "../..";
import { PrecalculatedLruCache } from "../../util/LruCache";
import {
getFullLanguageName,
Expand All @@ -22,7 +21,7 @@

constructor(private readonly ide: IDE) {
ide.onDidChangeActiveTextEditor((filepath) => {
this.cache.initKey(filepath);

Check warning on line 24 in core/autocomplete/context/ImportDefinitionsService.ts

View workflow job for this annotation

GitHub Actions / tsc-check

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 24 in core/autocomplete/context/ImportDefinitionsService.ts

View workflow job for this annotation

GitHub Actions / tsc-check

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
});
}

Expand Down
7 changes: 3 additions & 4 deletions core/autocomplete/context/ranking/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions core/autocomplete/context/ranking/slidingWindow.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions core/autocomplete/util/ast.ts
Original file line number Diff line number Diff line change
@@ -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[];

Expand Down
9 changes: 7 additions & 2 deletions core/autocomplete/util/types.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
53 changes: 35 additions & 18 deletions core/commands/slash/edit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ContextItemWithId, ILLM, SlashCommand } from "../../";
import {
ContextItemWithId,
ILLM,
RangeInFileWithContents,
SlashCommand,
} from "../../";
import {
filterCodeBlockLines,
filterEnglishLinesAtEnd,
Expand All @@ -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.

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 0 additions & 2 deletions core/commands/slash/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import GenerateTerminalCommand from "./cmd";
import CommitMessageCommand from "./commit";
import DraftIssueCommand from "./draftIssue";
import HttpSlashCommand from "./http";
import MultiFileEditSlashCommand from "./multifileEdit";
import OnboardSlashCommand from "./onboard";
import ReviewMessageCommand from "./review";
import ShareSlashCommand from "./share";
Expand All @@ -15,5 +14,4 @@ export default [
CommitMessageCommand,
ReviewMessageCommand,
OnboardSlashCommand,
MultiFileEditSlashCommand,
];
107 changes: 0 additions & 107 deletions core/commands/slash/multifileEdit.ts

This file was deleted.

11 changes: 1 addition & 10 deletions core/commands/util.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
33 changes: 32 additions & 1 deletion core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export interface ILLM extends LLMOptions {
complete(
prompt: string,
signal: AbortSignal,
options?: LLMFullCompletionOptions
options?: LLMFullCompletionOptions,
): Promise<string>;

streamComplete(
Expand Down Expand Up @@ -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.
Expand Down
42 changes: 13 additions & 29 deletions core/protocol/ideWebview.ts
Original file line number Diff line number Diff line change
@@ -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: [
Expand Down Expand Up @@ -54,30 +60,6 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & {
"edit/escape": [undefined, void];
};

export interface EditModeArgs {
highlightedCode: RangeInFileWithContents;
}

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
Expand All @@ -98,6 +80,7 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
},
void,
];
addCodeToEdit: [CodeToEdit, void];
navigateTo: [{ path: string; toggle?: boolean }, void];
addModel: [undefined, void];

Expand All @@ -118,7 +101,8 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
openOnboardingCard: [undefined, void];
applyCodeFromChat: [undefined, void];
updateApplyState: [ApplyState, void];
startEditMode: [EditModeArgs, void];
setEditStatus: [{ status: EditStatus; fileAfterEdit?: string }, void];
exitEditMode: [undefined, void];
focusEdit: [undefined, void];
focusEditWithoutClear: [undefined, void];
};
Loading
Loading