diff options
author | Ty Dunn <ty@tydunn.com> | 2023-06-28 23:10:54 -0700 |
---|---|---|
committer | Ty Dunn <ty@tydunn.com> | 2023-06-28 23:10:54 -0700 |
commit | b9e1ff3a1a2ea76a2a2ca754ee25df551381bbc6 (patch) | |
tree | 298d23233ee082e8d24da221612c0965161a4f5e /continuedev/src | |
parent | 5cb80a064fe49ae64f5c15e1e4d130d7925a61f8 (diff) | |
parent | 14f779412c086d569d6f86b9c3e871cbeb45c95a (diff) | |
download | sncontinue-b9e1ff3a1a2ea76a2a2ca754ee25df551381bbc6.tar.gz sncontinue-b9e1ff3a1a2ea76a2a2ca754ee25df551381bbc6.tar.bz2 sncontinue-b9e1ff3a1a2ea76a2a2ca754ee25df551381bbc6.zip |
Merge branch 'main' of github.com:continuedev/continue
Diffstat (limited to 'continuedev/src')
-rw-r--r-- | continuedev/src/continuedev/core/autopilot.py | 15 | ||||
-rw-r--r-- | continuedev/src/continuedev/libs/util/dedent.py | 16 | ||||
-rw-r--r-- | continuedev/src/continuedev/server/ide.py | 12 | ||||
-rw-r--r-- | continuedev/src/continuedev/steps/core/core.py | 14 |
4 files changed, 43 insertions, 14 deletions
diff --git a/continuedev/src/continuedev/core/autopilot.py b/continuedev/src/continuedev/core/autopilot.py index 3b2b65db..7d149e7e 100644 --- a/continuedev/src/continuedev/core/autopilot.py +++ b/continuedev/src/continuedev/core/autopilot.py @@ -139,13 +139,14 @@ class Autopilot(ContinueBaseModel): return None # If a parent step is deleted/cancelled, don't run this step - last_depth = self._step_depth - i = self.history.current_index - while i >= 0 and self.history.timeline[i].depth == last_depth - 1: - if self.history.timeline[i].deleted: - return None - last_depth = self.history.timeline[i].depth - i -= 1 + # TODO: This was problematic because when running a step after deleting one, it seemed to think that was the parent + # last_depth = self._step_depth + # i = self.history.current_index + # while i >= 0 and self.history.timeline[i].depth == last_depth - 1: + # if self.history.timeline[i].deleted: + # return None + # last_depth = self.history.timeline[i].depth + # i -= 1 capture_event(self.continue_sdk.ide.unique_id, 'step run', { 'step_name': step.name, 'params': step.dict()}) diff --git a/continuedev/src/continuedev/libs/util/dedent.py b/continuedev/src/continuedev/libs/util/dedent.py new file mode 100644 index 00000000..74edd173 --- /dev/null +++ b/continuedev/src/continuedev/libs/util/dedent.py @@ -0,0 +1,16 @@ +from typing import Tuple + + +def dedent_and_get_common_whitespace(s: str) -> Tuple[str, str]: + lines = s.splitlines() + + # Longest common whitespace prefix + lcp = lines[0].split(lines[0].strip())[0] + for i in range(1, len(lines)): + for j in range(0, len(lcp)): + if j >= len(lines[i]) or lcp[j] != lines[i][j]: + lcp = lcp[:j] + if lcp == "": + return s, "" + break + return "\n".join(map(lambda x: x.removeprefix(lcp), lines)), lcp diff --git a/continuedev/src/continuedev/server/ide.py b/continuedev/src/continuedev/server/ide.py index 6a94326a..ff0b2a24 100644 --- a/continuedev/src/continuedev/server/ide.py +++ b/continuedev/src/continuedev/server/ide.py @@ -253,10 +253,14 @@ class IdeProtocolServer(AbstractIdeProtocolServer): async def getUserSecret(self, key: str) -> str: """Get a user secret""" - resp = await self._send_and_receive_json({ - "key": key - }, GetUserSecretResponse, "getUserSecret") - return resp.value + try: + resp = await self._send_and_receive_json({ + "key": key + }, GetUserSecretResponse, "getUserSecret") + return resp.value + except Exception as e: + print("Error getting user secret", e) + return "" async def saveFile(self, filepath: str): """Save a file""" diff --git a/continuedev/src/continuedev/steps/core/core.py b/continuedev/src/continuedev/steps/core/core.py index a712c12f..c8acd7c5 100644 --- a/continuedev/src/continuedev/steps/core/core.py +++ b/continuedev/src/continuedev/steps/core/core.py @@ -11,6 +11,7 @@ from ...models.filesystem import FileSystem, RangeInFile, RangeInFileWithContent from ...core.observation import Observation, TextObservation, TracebackObservation, UserInputObservation from ...core.main import ChatMessage, Step, SequentialStep from ...libs.util.count_tokens import MAX_TOKENS_FOR_MODEL, DEFAULT_MAX_TOKENS +from ...libs.util.dedent import dedent_and_get_common_whitespace import difflib @@ -266,6 +267,8 @@ class DefaultModelEditCodeStep(Step): file_prefix, contents, file_suffix, model_to_use = await self.get_prompt_parts( rif, sdk, full_file_contents) + contents, common_whitespace = dedent_and_get_common_whitespace( + contents) prompt = self.compile_prompt(file_prefix, contents, file_suffix, sdk) full_file_contents_lines = full_file_contents.split("\n") @@ -292,10 +295,11 @@ class DefaultModelEditCodeStep(Step): index_of_last_matched_line = -1 async def handle_generated_line(line: str): - nonlocal lines, current_block_start, current_line_in_file, original_lines, original_lines_below_previous_blocks, current_block_lines, offset_from_blocks, matched_lines_at_end_of_block, index_of_last_matched_line, LINES_TO_MATCH_BEFORE_ENDING_BLOCK + nonlocal lines, current_block_start, current_line_in_file, original_lines, original_lines_below_previous_blocks, current_block_lines, offset_from_blocks, matched_lines_at_end_of_block, index_of_last_matched_line, LINES_TO_MATCH_BEFORE_ENDING_BLOCK, common_whitespace # Highlight the line to show progress - line_to_highlight = current_line_in_file - len(current_block_lines) + # - len(current_block_lines) + line_to_highlight = current_line_in_file await sdk.ide.highlightCode(RangeInFile(filepath=rif.filepath, range=Range.from_shorthand( line_to_highlight, 0, line_to_highlight, 0)), "#FFFFFF22" if len(current_block_lines) == 0 else "#00FF0022") @@ -393,6 +397,9 @@ class DefaultModelEditCodeStep(Step): # 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 @@ -406,7 +413,7 @@ class DefaultModelEditCodeStep(Step): continue # Because really short lines might be expected to be repeated, this is only a !heuristic! # Stop when it starts copying the file_suffix - elif line.strip() == line_below_highlighted_range.strip() and len(line.strip()) > 4 and not line.strip() == original_lines_below_previous_blocks[0].strip(): + elif line.strip() == line_below_highlighted_range.strip() and len(line.strip()) > 4 and not (len(original_lines_below_previous_blocks) > 0 and line.strip() == original_lines_below_previous_blocks[0].strip()): repeating_file_suffix = True break @@ -417,6 +424,7 @@ class DefaultModelEditCodeStep(Step): # 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): + unfinished_line = common_whitespace + unfinished_line lines.append(unfinished_line) await handle_generated_line(unfinished_line) completion_lines_covered += 1 |