diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-07-02 20:14:27 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-07-02 20:14:27 -0700 |
commit | 894a197892fc4e3a6a5af7d47b7702ea895e20b7 (patch) | |
tree | 40bd82d5ae5f7a3a0467c32d18ed51b923368e58 /continuedev/src | |
parent | 359c277f25c323d3fd47830d569fb05f93920d3a (diff) | |
download | sncontinue-894a197892fc4e3a6a5af7d47b7702ea895e20b7.tar.gz sncontinue-894a197892fc4e3a6a5af7d47b7702ea895e20b7.tar.bz2 sncontinue-894a197892fc4e3a6a5af7d47b7702ea895e20b7.zip |
finishing up explicit context
Diffstat (limited to 'continuedev/src')
-rw-r--r-- | continuedev/src/continuedev/core/autopilot.py | 17 | ||||
-rw-r--r-- | continuedev/src/continuedev/models/filesystem.py | 16 | ||||
-rw-r--r-- | continuedev/src/continuedev/models/main.py | 5 | ||||
-rw-r--r-- | continuedev/src/continuedev/steps/chat.py | 2 |
4 files changed, 20 insertions, 20 deletions
diff --git a/continuedev/src/continuedev/core/autopilot.py b/continuedev/src/continuedev/core/autopilot.py index b9e61c63..1a77ca64 100644 --- a/continuedev/src/continuedev/core/autopilot.py +++ b/continuedev/src/continuedev/core/autopilot.py @@ -139,21 +139,22 @@ class Autopilot(ContinueBaseModel): for rif in range_in_files: rif.filepath = os.path.relpath(rif.filepath, workspace_path) + old_ranges = self._highlighted_ranges + range_in_files new_ranges = [] - for rif in range_in_files: + + while len(old_ranges) > 0: + old_range = old_ranges.pop(0) found_overlap = False - for i in range(len(self._highlighted_ranges)): - hr = self._highlighted_ranges[i] - if hr.filepath == rif.filepath and hr.range.overlaps_with(rif.range): - new_ranges.append(rif.union(hr)) + for i in range(len(new_ranges)): + if old_range.filepath == new_ranges[i].filepath and old_range.range.overlaps_with(new_ranges[i].range): + new_ranges[i] = old_range.union(new_ranges[i]) found_overlap = True - self._highlighted_ranges.pop(i) break if not found_overlap: - new_ranges.append(rif) + new_ranges.append(old_range) - self._highlighted_ranges += new_ranges + self._highlighted_ranges = new_ranges await self.update_subscribers() _step_depth: int = 0 diff --git a/continuedev/src/continuedev/models/filesystem.py b/continuedev/src/continuedev/models/filesystem.py index fc1c3f13..df0b15d7 100644 --- a/continuedev/src/continuedev/models/filesystem.py +++ b/continuedev/src/continuedev/models/filesystem.py @@ -40,21 +40,15 @@ class RangeInFileWithContents(RangeInFile): assert first.filepath == second.filepath - # Calculate the start and end positions of the overlap - overlap_start = max(first.range.start, - second.range.start) - first.range.start - overlap_end = min(first.range.end, second.range.end) - \ - first.range.start - - # Calculate the new contents by removing the overlap - union_contents = first.contents[:overlap_start] + \ - second.contents[overlap_start:overlap_end] + \ - first.contents[overlap_end:] + # Calculate union of contents + num_overlapping_lines = first.range.end.line - second.range.start.line + 1 + union_lines = first.contents.splitlines()[:-num_overlapping_lines] + \ + second.contents.splitlines() return RangeInFileWithContents( filepath=first.filepath, range=first.range.union(second.range), - contents=union_contents + contents="\n".join(union_lines) ) @staticmethod diff --git a/continuedev/src/continuedev/models/main.py b/continuedev/src/continuedev/models/main.py index 101be4ae..fa736772 100644 --- a/continuedev/src/continuedev/models/main.py +++ b/continuedev/src/continuedev/models/main.py @@ -43,6 +43,11 @@ class Position(BaseModel): def from_end_of_file(contents: str) -> "Position": return Position.from_index(contents, len(contents)) + def to_index(self, string: str) -> int: + """Convert line and character to index in string""" + lines = string.splitlines() + return sum(map(len, lines[:self.line])) + self.character + class Range(BaseModel): """A range in a file. 0-indexed.""" diff --git a/continuedev/src/continuedev/steps/chat.py b/continuedev/src/continuedev/steps/chat.py index 8494563b..b10ec3d7 100644 --- a/continuedev/src/continuedev/steps/chat.py +++ b/continuedev/src/continuedev/steps/chat.py @@ -106,7 +106,7 @@ class RunTerminalCommandStep(Step): class ViewDirectoryTreeStep(Step): name: str = "View Directory Tree" - description: str = "View the directory tree to learn which folder and files exist." + description: str = "View the directory tree to learn which folder and files exist. You should always do this before adding new files." async def describe(self, models: Models) -> Coroutine[Any, Any, Coroutine[str, None, None]]: return f"Viewed the directory tree." |