more streaming edge cases

This commit is contained in:
Nate Sesti 2023-06-27 14:48:11 -07:00
parent 7b2f76b012
commit fd0b1b3e8e
3 changed files with 24 additions and 18 deletions

View file

@ -288,14 +288,11 @@ class DefaultModelEditCodeStep(Step):
current_line_in_file, 0, current_line_in_file, 0)), "#FFFFFF22" if len(current_block_lines) == 0 else "#FFFF0022")
if len(current_block_lines) == 0:
if len(original_lines_below_previous_blocks) == 0 or line != original_lines_below_previous_blocks[0]:
current_block_lines.append(line)
current_block_start = current_line_in_file
else:
current_block_start = current_line_in_file
if len(original_lines_below_previous_blocks) > 0 and line == original_lines_below_previous_blocks[0]:
original_lines_below_previous_blocks = original_lines_below_previous_blocks[
1:]
return
return
# We are in a block currently, and checking for whether it should be ended
for i in range(len(original_lines_below_previous_blocks)):
@ -303,12 +300,15 @@ class DefaultModelEditCodeStep(Step):
if og_line == line:
# Insert the suggestion
replacement = "\n".join(current_block_lines)
await sdk.ide.showSuggestion(FileEdit(
filepath=rif.filepath,
range=Range.from_shorthand(
current_block_start, 0, current_block_start + i, 0),
replacement="\n".join(current_block_lines)
replacement=replacement
))
if replacement == "":
current_line_in_file += 1
# Reset current block / update variables
original_lines_below_previous_blocks = original_lines_below_previous_blocks[
@ -348,6 +348,9 @@ class DefaultModelEditCodeStep(Step):
# Deal with newly accumulated lines
for line in chunk_lines:
# Trailing whitespace doesn't matter
line = line.rstrip()
# Lines that should signify the end of generation
if self.is_end_line(line):
break

View file

@ -6,12 +6,12 @@ class SuggestionsCodeLensProvider implements vscode.CodeLensProvider {
document: vscode.TextDocument,
token: vscode.CancellationToken
): vscode.CodeLens[] | Thenable<vscode.CodeLens[]> {
let suggestions = editorToSuggestions.get(document.uri.toString());
const suggestions = editorToSuggestions.get(document.uri.toString());
if (!suggestions) {
return [];
}
let codeLenses: vscode.CodeLens[] = [];
const codeLenses: vscode.CodeLens[] = [];
for (const suggestion of suggestions) {
const range = new vscode.Range(
suggestion.oldRange.start,
@ -27,12 +27,16 @@ class SuggestionsCodeLensProvider implements vscode.CodeLensProvider {
title: "Reject ❌",
command: "continue.rejectSuggestion",
arguments: [suggestion],
}),
new vscode.CodeLens(range, {
title: "(⌘⇧↩/⌘⇧⌫ to accept/reject all)",
command: "",
})
);
if (codeLenses.length === 2) {
codeLenses.push(
new vscode.CodeLens(range, {
title: "(⌘⇧↩/⌘⇧⌫ to accept/reject all)",
command: "",
})
);
}
}
return codeLenses;

View file

@ -316,7 +316,7 @@ export async function showSuggestion(
(edit) => {
edit.insert(
new vscode.Position(range.end.line, 0),
suggestion + "\n"
suggestion + (suggestion === "" ? "" : "\n")
);
},
{ undoStopBefore: false, undoStopAfter: false }
@ -324,12 +324,11 @@ export async function showSuggestion(
.then(
(success) => {
if (success) {
const suggestionLinesLength =
suggestion === "" ? 0 : suggestion.split("\n").length;
let suggestionRange = new vscode.Range(
new vscode.Position(range.end.line, 0),
new vscode.Position(
range.end.line + suggestion.split("\n").length,
0
)
new vscode.Position(range.end.line + suggestionLinesLength, 0)
);
const filename = editor!.document.uri.toString();