+
+{file_suffix}
+
+
+{self.user_input}
+
+
+Please output the code to be inserted at the cursor in order to fulfill the user_request. Do NOT preface your answer or write anything other than code. You should not write any tags, just the code. Make sure to correctly indent the code:""")
+ return prompt
+
prompt = self._prompt
if file_prefix.strip() != "":
prompt += dedent(f"""
@@ -306,15 +323,32 @@ class DefaultModelEditCodeStep(Step):
prompt = self.compile_prompt(file_prefix, contents, file_suffix, sdk)
full_file_contents_lines = full_file_contents.split("\n")
- async def sendDiffUpdate(lines: List[str], sdk: ContinueSDK):
- nonlocal full_file_contents_lines, rif
+ lines_to_display = []
+
+ async def sendDiffUpdate(lines: List[str], sdk: ContinueSDK, final: bool = False):
+ nonlocal full_file_contents_lines, rif, lines_to_display
completion = "\n".join(lines)
full_prefix_lines = full_file_contents_lines[:rif.range.start.line]
full_suffix_lines = full_file_contents_lines[rif.range.end.line:]
+
+ # Don't do this at the very end, just show the inserted code
+ if final:
+ lines_to_display = []
+ # Only recalculate at every new-line, because this is sort of expensive
+ elif completion.endswith("\n"):
+ contents_lines = rif.contents.split("\n")
+ rewritten_lines = 0
+ for line in lines:
+ for i in range(rewritten_lines, len(contents_lines)):
+ if difflib.SequenceMatcher(None, line, contents_lines[i]).ratio() > 0.7 and contents_lines[i].strip() != "":
+ rewritten_lines = i + 1
+ break
+ lines_to_display = contents_lines[rewritten_lines:]
+
new_file_contents = "\n".join(
- full_prefix_lines) + "\n" + completion + "\n" + "\n".join(full_suffix_lines)
+ full_prefix_lines) + "\n" + completion + "\n" + "\n".join(lines_to_display) + "\n" + "\n".join(full_suffix_lines)
step_index = sdk.history.current_index
@@ -495,7 +529,7 @@ class DefaultModelEditCodeStep(Step):
completion_lines_covered += 1
current_line_in_file += 1
- await sendDiffUpdate(lines + [common_whitespace + unfinished_line], sdk)
+ await sendDiffUpdate(lines + [common_whitespace if unfinished_line.startswith("<") else (common_whitespace + unfinished_line)], sdk)
# Add the unfinished line
if unfinished_line != "" and not self.line_to_be_ignored(unfinished_line, completion_lines_covered == 0) and not self.is_end_line(unfinished_line):
@@ -505,7 +539,7 @@ class DefaultModelEditCodeStep(Step):
completion_lines_covered += 1
current_line_in_file += 1
- await sendDiffUpdate(lines, sdk)
+ await sendDiffUpdate(lines, sdk, final=True)
if False:
# If the current block isn't empty, add that suggestion
diff --git a/extension/react-app/src/components/ComboBox.tsx b/extension/react-app/src/components/ComboBox.tsx
index 801c3a036..585a0584f 100644
--- a/extension/react-app/src/components/ComboBox.tsx
+++ b/extension/react-app/src/components/ComboBox.tsx
@@ -180,6 +180,26 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
useImperativeHandle(ref, () => downshiftProps, [downshiftProps]);
+ const [metaKeyPressed, setMetaKeyPressed] = useState(false);
+ useEffect(() => {
+ const handleKeyDown = (e: KeyboardEvent) => {
+ if (e.key === "Meta") {
+ setMetaKeyPressed(true);
+ }
+ };
+ const handleKeyUp = (e: KeyboardEvent) => {
+ if (e.key === "Meta") {
+ setMetaKeyPressed(false);
+ }
+ };
+ window.addEventListener("keydown", handleKeyDown);
+ window.addEventListener("keyup", handleKeyUp);
+ return () => {
+ window.removeEventListener("keydown", handleKeyDown);
+ window.removeEventListener("keyup", handleKeyUp);
+ };
+ });
+
useEffect(() => {
if (!inputRef.current) {
return;
@@ -272,7 +292,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
{
const target = e.target as HTMLTextAreaElement;
@@ -357,10 +377,12 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
))}
- {/*
- Highlight code to include as context. Currently open file included by
- default. {highlightedCodeSections.length === 0 && ""}
- */}
+ {highlightedCodeSections.length === 0 &&
+ (downshiftProps.inputValue?.startsWith("/edit") || metaKeyPressed) && (
+
+ Inserting at cursor
+
+ )}
{
setHoveringContextDropdown(true);
diff --git a/extension/src/diffs.ts b/extension/src/diffs.ts
index 1dc292e15..3ea6b4f80 100644
--- a/extension/src/diffs.ts
+++ b/extension/src/diffs.ts
@@ -164,7 +164,12 @@ class DiffManager {
// Stop the step at step_index in case it is still streaming
ideProtocolClient.deleteAtIndex(diffInfo.step_index);
- this.cleanUpDiff(diffInfo);
+ vscode.workspace.textDocuments
+ .find((doc) => doc.uri.fsPath === newFilepath)
+ ?.save()
+ .then(() => {
+ this.cleanUpDiff(diffInfo);
+ });
}
}