✨ follow-up quick edits with cmd/ctrl+shift+L

This commit is contained in:
Nate Sesti 2024-02-09 21:35:44 -08:00
parent 09b2e069e9
commit 4d93311a2b
3 changed files with 63 additions and 33 deletions

View file

@ -19,13 +19,27 @@ export class VerticalPerLineDiffHandler {
private currentLineIndex: number;
private cancelled: boolean = false;
public get range(): vscode.Range {
const startLine = Math.min(this.startLine, this.endLine);
const endLine = Math.max(this.startLine, this.endLine);
return new vscode.Range(startLine, 0, endLine, Number.MAX_SAFE_INTEGER);
}
private newLinesAdded: number = 0;
constructor(startLine: number, endLine: number, editor: vscode.TextEditor) {
public input?: string;
constructor(
startLine: number,
endLine: number,
editor: vscode.TextEditor,
input?: string
) {
this.currentLineIndex = startLine;
this.startLine = startLine;
this.endLine = endLine;
this.editor = editor;
this.input = input;
this.redDecorationManager = new DecorationTypeRangeManager(
redDecorationType,

View file

@ -11,7 +11,8 @@ class VerticalPerLineDiffManager {
createVerticalPerLineDiffHandler(
filepath: string,
startLine: number,
endLine: number
endLine: number,
input: string
) {
if (this.filepathToEditorMap.has(filepath)) {
this.filepathToEditorMap.get(filepath)?.clear(false);
@ -22,7 +23,8 @@ class VerticalPerLineDiffManager {
const handler = new VerticalPerLineDiffHandler(
startLine,
endLine,
editor
editor,
input
);
this.filepathToEditorMap.set(filepath, handler);
return handler;
@ -87,49 +89,63 @@ export async function streamEdit(input: string) {
const startLine = editor.selection.start.line;
const endLine = editor.selection.end.line;
const existingHandler =
verticalPerLineDiffManager.getHandlerForFile(filepath);
existingHandler?.clear(false);
await new Promise((resolve) => {
setTimeout(resolve, 200);
});
const diffHandler =
verticalPerLineDiffManager.createVerticalPerLineDiffHandler(
filepath,
startLine,
endLine
existingHandler?.range.start.line ?? startLine,
existingHandler?.range.end.line ?? endLine,
input
);
if (!diffHandler) {
return;
}
if (diffHandler) {
const selectedRange = new vscode.Range(
const selectedRange =
existingHandler?.range ??
new vscode.Range(
editor.selection.start.with(undefined, 0),
editor.selection.end.with(undefined, Number.MAX_SAFE_INTEGER)
);
const rangeContent = editor.document.getText(selectedRange);
const llm = await llmFromTitle();
const rangeContent = editor.document.getText(selectedRange);
const llm = await llmFromTitle();
// Unselect the range
editor.selection = new vscode.Selection(
editor.selection.active,
editor.selection.active
// Unselect the range
editor.selection = new vscode.Selection(
editor.selection.active,
editor.selection.active
);
vscode.commands.executeCommand("setContext", "continue.streamingDiff", true);
if (existingHandler?.input) {
if (existingHandler.input.startsWith("Original request: ")) {
existingHandler.input = existingHandler.input.substring(
"Original request: ".length
);
}
input = `Original request: ${existingHandler.input}\nUpdated request: ${input}`;
}
try {
await diffHandler.run(
streamDiffLines(
rangeContent,
llm,
input,
getMarkdownLanguageTagForFile(filepath)
)
);
} finally {
vscode.commands.executeCommand(
"setContext",
"continue.streamingDiff",
true
false
);
try {
await diffHandler.run(
streamDiffLines(
rangeContent,
llm,
input,
getMarkdownLanguageTagForFile(filepath)
)
);
} finally {
vscode.commands.executeCommand(
"setContext",
"continue.streamingDiff",
false
);
}
}
}

View file

@ -41,7 +41,7 @@ class VerticalPerLineCodeLensProvider implements vscode.CodeLensProvider {
if (codeLenses.length === 2) {
codeLenses.push(
new vscode.CodeLens(range, {
title: `(${getMetaKeyLabel()}⇧↩/${getMetaKeyLabel()}⇧⌫ to accept/reject all)`,
title: `(${getMetaKeyLabel()}⇧↩/${getMetaKeyLabel()}⇧⌫ to accept/reject all, ${getMetaKeyLabel()}⇧L to retry)`,
command: "",
})
);