diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-07-04 22:39:52 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-07-04 22:39:52 -0700 |
commit | c2743058a79e8e998b9e9a9e2fa4c79f53e52af3 (patch) | |
tree | ca25214dc3ed823a0b535fd6cd7f6c89b782aa9a /continuedev/src | |
parent | 35f5beabe55c59149ad0a6e4eb242fbc5352bf2e (diff) | |
download | sncontinue-c2743058a79e8e998b9e9a9e2fa4c79f53e52af3.tar.gz sncontinue-c2743058a79e8e998b9e9a9e2fa4c79f53e52af3.tar.bz2 sncontinue-c2743058a79e8e998b9e9a9e2fa4c79f53e52af3.zip |
side-by-side diff editor
Diffstat (limited to 'continuedev/src')
-rw-r--r-- | continuedev/src/continuedev/steps/core/core.py | 82 |
1 files changed, 49 insertions, 33 deletions
diff --git a/continuedev/src/continuedev/steps/core/core.py b/continuedev/src/continuedev/steps/core/core.py index b9f0da35..b215b317 100644 --- a/continuedev/src/continuedev/steps/core/core.py +++ b/continuedev/src/continuedev/steps/core/core.py @@ -295,6 +295,17 @@ 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 + + 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 + 1:] + new_file_contents = "\n".join( + full_prefix_lines) + "\n" + completion + "\n" + "\n".join(full_suffix_lines) + await sdk.ide.showDiff(rif.filepath, new_file_contents) + # Important state variables # ------------------------- original_lines = [] if rif.contents == "" else rif.contents.split("\n") @@ -435,16 +446,16 @@ class DefaultModelEditCodeStep(Step): chunk_lines.pop() # because this will be an empty string else: unfinished_line = chunk_lines.pop() - lines.extend(chunk_lines) + lines.extend(map(lambda l: common_whitespace + l, chunk_lines)) + + if True: + await sendDiffUpdate(lines, sdk) # Deal with newly accumulated lines for line in chunk_lines: # Trailing whitespace doesn't matter line = line.rstrip() - # Add the common whitespace that was removed before prompting - line = common_whitespace + line - # Lines that should signify the end of generation if self.is_end_line(line): break @@ -463,7 +474,9 @@ class DefaultModelEditCodeStep(Step): break # If none of the above, insert the line! - await handle_generated_line(line) + if False: + await handle_generated_line(line) + completion_lines_covered += 1 current_line_in_file += 1 @@ -475,34 +488,37 @@ class DefaultModelEditCodeStep(Step): completion_lines_covered += 1 current_line_in_file += 1 - # If the current block isn't empty, add that suggestion - if len(current_block_lines) > 0: - # We have a chance to back-track here for blank lines that are repeats of the end of the original - # Don't want to have the same ending in both the original and the generated, can just leave it there - num_to_remove = 0 - for i in range(-1, -len(current_block_lines) - 1, -1): - if len(original_lines_below_previous_blocks) == 0: - break - if current_block_lines[i] == original_lines_below_previous_blocks[-1]: - num_to_remove += 1 - original_lines_below_previous_blocks.pop() - else: - break - current_block_lines = current_block_lines[:- - num_to_remove] if num_to_remove > 0 else current_block_lines - - # It's also possible that some lines match at the beginning of the block - # while len(current_block_lines) > 0 and len(original_lines_below_previous_blocks) > 0 and current_block_lines[0] == original_lines_below_previous_blocks[0]: - # current_block_lines.pop(0) - # original_lines_below_previous_blocks.pop(0) - # current_block_start += 1 - - await sdk.ide.showSuggestion(FileEdit( - filepath=rif.filepath, - range=Range.from_shorthand( - current_block_start, 0, current_block_start + len(original_lines_below_previous_blocks), 0), - replacement="\n".join(current_block_lines) - )) + await sendDiffUpdate(lines, sdk) + + if False: + # If the current block isn't empty, add that suggestion + if len(current_block_lines) > 0: + # We have a chance to back-track here for blank lines that are repeats of the end of the original + # Don't want to have the same ending in both the original and the generated, can just leave it there + num_to_remove = 0 + for i in range(-1, -len(current_block_lines) - 1, -1): + if len(original_lines_below_previous_blocks) == 0: + break + if current_block_lines[i] == original_lines_below_previous_blocks[-1]: + num_to_remove += 1 + original_lines_below_previous_blocks.pop() + else: + break + current_block_lines = current_block_lines[:- + num_to_remove] if num_to_remove > 0 else current_block_lines + + # It's also possible that some lines match at the beginning of the block + # while len(current_block_lines) > 0 and len(original_lines_below_previous_blocks) > 0 and current_block_lines[0] == original_lines_below_previous_blocks[0]: + # current_block_lines.pop(0) + # original_lines_below_previous_blocks.pop(0) + # current_block_start += 1 + + await sdk.ide.showSuggestion(FileEdit( + filepath=rif.filepath, + range=Range.from_shorthand( + current_block_start, 0, current_block_start + len(original_lines_below_previous_blocks), 0), + replacement="\n".join(current_block_lines) + )) # Record the completion completion = "\n".join(lines) |