summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--continuedev/poetry.lock34
-rw-r--r--continuedev/pyproject.toml1
-rw-r--r--continuedev/src/continuedev/core/sdk.py3
-rw-r--r--continuedev/src/continuedev/libs/util/calculate_diff.py152
-rw-r--r--continuedev/src/continuedev/libs/util/copy_codebase.py38
-rw-r--r--continuedev/src/continuedev/models/filesystem_edit.py4
-rw-r--r--continuedev/src/continuedev/steps/chat.py12
-rw-r--r--continuedev/src/continuedev/steps/react.py33
-rw-r--r--extension/package.json80
-rw-r--r--extension/react-app/src/components/CodeBlock.tsx1
-rw-r--r--extension/react-app/src/components/StepContainer.tsx23
-rw-r--r--extension/react-app/src/tabs/chat/MessageDiv.tsx4
-rw-r--r--extension/react-app/src/tabs/gui.tsx20
-rw-r--r--extension/src/continueIdeClient.ts31
-rw-r--r--extension/src/decorations.ts19
15 files changed, 298 insertions, 157 deletions
diff --git a/continuedev/poetry.lock b/continuedev/poetry.lock
index 857a7c99..4aedce87 100644
--- a/continuedev/poetry.lock
+++ b/continuedev/poetry.lock
@@ -345,6 +345,21 @@ typing-inspect = ">=0.4.0"
dev = ["flake8", "hypothesis", "ipython", "mypy (>=0.710)", "portray", "pytest (>=6.2.3)", "simplejson", "types-dataclasses"]
[[package]]
+name = "diff-match-patch"
+version = "20230430"
+description = "Diff Match and Patch"
+category = "main"
+optional = false
+python-versions = ">=3.7"
+files = [
+ {file = "diff-match-patch-20230430.tar.gz", hash = "sha256:953019cdb9c9d2c9e47b5b12bcff3cf4746fc4598eb406076fa1fc27e6a1f15c"},
+ {file = "diff_match_patch-20230430-py3-none-any.whl", hash = "sha256:dce43505fb7b1b317de7195579388df0746d90db07015ed47a85e5e44930ef93"},
+]
+
+[package.extras]
+dev = ["attribution (==1.6.2)", "black (==23.3.0)", "flit (==3.8.0)", "mypy (==1.2.0)", "ufmt (==2.1.0)", "usort (==1.0.6)"]
+
+[[package]]
name = "fastapi"
version = "0.95.1"
description = "FastAPI framework, high performance, easy to learn, fast to code, ready for production"
@@ -1252,23 +1267,6 @@ socks = ["PySocks (>=1.5.6,!=1.5.7)"]
use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"]
[[package]]
-name = "setuptools"
-version = "67.7.2"
-description = "Easily download, build, install, upgrade, and uninstall Python packages"
-category = "main"
-optional = false
-python-versions = ">=3.7"
-files = [
- {file = "setuptools-67.7.2-py3-none-any.whl", hash = "sha256:23aaf86b85ca52ceb801d32703f12d77517b2556af839621c641fca11287952b"},
- {file = "setuptools-67.7.2.tar.gz", hash = "sha256:f104fa03692a2602fa0fec6c6a9e63b6c8a968de13e17c026957dd1f53d80990"},
-]
-
-[package.extras]
-docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-hoverxref (<2)", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (==0.8.3)", "sphinx-reredirects", "sphinxcontrib-towncrier"]
-testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8 (<5)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pip-run (>=8.8)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"]
-testing-integration = ["build[virtualenv]", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"]
-
-[[package]]
name = "six"
version = "1.16.0"
description = "Python 2 and 3 compatibility utilities"
@@ -1739,4 +1737,4 @@ multidict = ">=4.0"
[metadata]
lock-version = "2.0"
python-versions = "^3.9"
-content-hash = "9f9254c954b7948c49debba86bc81a4a9c3f50694424f5940d0058725b1bf0fb"
+content-hash = "0f5f759bac0e44a1fbcc9babeccdea8688ea2226a4bae7a13858542ae03a3228"
diff --git a/continuedev/pyproject.toml b/continuedev/pyproject.toml
index 631742ec..7315e79d 100644
--- a/continuedev/pyproject.toml
+++ b/continuedev/pyproject.toml
@@ -7,6 +7,7 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.9"
+diff-match-patch = "^20230430"
fastapi = "^0.95.1"
typer = "^0.7.0"
openai = "^0.27.5"
diff --git a/continuedev/src/continuedev/core/sdk.py b/continuedev/src/continuedev/core/sdk.py
index a94b5026..2849b0c8 100644
--- a/continuedev/src/continuedev/core/sdk.py
+++ b/continuedev/src/continuedev/core/sdk.py
@@ -149,3 +149,6 @@ class ContinueSDK(AbstractContinueSDK):
history_context.append(ChatMessage(
content=f"The following code is highlighted:\n```\n{code}\n```", role="user"))
return history_context
+
+ async def update_ui(self):
+ await self.__autopilot.update_subscribers()
diff --git a/continuedev/src/continuedev/libs/util/calculate_diff.py b/continuedev/src/continuedev/libs/util/calculate_diff.py
new file mode 100644
index 00000000..d778891b
--- /dev/null
+++ b/continuedev/src/continuedev/libs/util/calculate_diff.py
@@ -0,0 +1,152 @@
+import difflib
+from typing import List
+from ...models.main import Position, Range
+from ...models.filesystem import FileEdit
+from diff_match_patch import diff_match_patch
+
+
+def calculate_diff_match_patch(filepath: str, original: str, updated: str) -> List[FileEdit]:
+ dmp = diff_match_patch()
+ diffs = dmp.diff_main(original, updated)
+ dmp.diff_cleanupSemantic(diffs)
+
+ replacements = []
+
+ current_index = 0
+ deleted_length = 0
+
+ for diff in diffs:
+ if diff[0] == diff_match_patch.DIFF_EQUAL:
+ current_index += len(diff[1])
+ deleted_length = 0
+ elif diff[0] == diff_match_patch.DIFF_INSERT:
+ current_index += deleted_length
+ replacements.append((current_index, current_index, diff[1]))
+ current_index += len(diff[1])
+ deleted_length = 0
+ elif diff[0] == diff_match_patch.DIFF_DELETE:
+ replacements.append(
+ (current_index, current_index + len(diff[1]), ''))
+ deleted_length += len(diff[1])
+ elif diff[0] == diff_match_patch.DIFF_REPLACE:
+ replacements.append(
+ (current_index, current_index + len(diff[1]), ''))
+ current_index += deleted_length
+ replacements.append((current_index, current_index, diff[2]))
+ current_index += len(diff[2])
+ deleted_length = 0
+
+ return [FileEdit(filepath=filepath, range=Range.from_indices(original, r[0], r[1]), replacement=r[2]) for r in replacements]
+
+
+def calculate_diff(filepath: str, original: str, updated: str) -> List[FileEdit]:
+ s = difflib.SequenceMatcher(None, original, updated)
+ offset = 0 # The indices are offset by previous deletions/insertions
+ edits = []
+ for tag, i1, i2, j1, j2 in s.get_opcodes():
+ i1, i2, j1, j2 = i1 + offset, i2 + offset, j1 + offset, j2 + offset
+ replacement = updated[j1:j2]
+ if tag == "equal":
+ pass
+ elif tag == "delete":
+ edits.append(FileEdit.from_deletion(
+ filepath, Range.from_indices(original, i1, i2)))
+ offset -= i2 - i1
+ elif tag == "insert":
+ edits.append(FileEdit.from_insertion(
+ filepath, Position.from_index(original, i1), replacement))
+ offset += j2 - j1
+ elif tag == "replace":
+ edits.append(FileEdit(filepath=filepath, range=Range.from_indices(
+ original, i1, i2), replacement=replacement))
+ offset += (j2 - j1) - (i2 - i1)
+ else:
+ raise Exception("Unexpected difflib.SequenceMatcher tag: " + tag)
+
+ return edits
+
+
+def calculate_diff2(filepath: str, original: str, updated: str) -> List[FileEdit]:
+ edits = []
+ max_iterations = 1000
+ i = 0
+ while not original == updated:
+ # TODO - For some reason it can't handle a single newline at the end of the file?
+ s = difflib.SequenceMatcher(None, original, updated)
+ opcodes = s.get_opcodes()
+ for edit_index in range(len(opcodes)):
+ tag, i1, i2, j1, j2 = s.get_opcodes()[edit_index]
+ replacement = updated[j1:j2]
+ if tag == "equal":
+ continue
+ elif tag == "delete":
+ edits.append(FileEdit.from_deletion(
+ filepath, Range.from_indices(original, i1, i2)))
+ elif tag == "insert":
+ edits.append(FileEdit.from_insertion(
+ filepath, Position.from_index(original, i1), replacement))
+ elif tag == "replace":
+ edits.append(FileEdit(filepath=filepath, range=Range.from_indices(
+ original, i1, i2), replacement=replacement))
+ else:
+ raise Exception(
+ "Unexpected difflib.SequenceMatcher tag: " + tag)
+ break
+
+ original = apply_edit_to_str(original, edits[-1])
+
+ i += 1
+ if i > max_iterations:
+ raise Exception("Max iterations reached")
+
+ return edits
+
+
+def read_range_in_str(s: str, r: Range) -> str:
+ lines = s.splitlines()[r.start.line:r.end.line + 1]
+ if len(lines) == 0:
+ return ""
+
+ lines[0] = lines[0][r.start.character:]
+ lines[-1] = lines[-1][:r.end.character + 1]
+ return "\n".join(lines)
+
+
+def apply_edit_to_str(s: str, edit: FileEdit) -> str:
+ original = read_range_in_str(s, edit.range)
+
+ # Split lines and deal with some edge cases (could obviously be nicer)
+ lines = s.splitlines()
+ if s.startswith("\n"):
+ lines.insert(0, "")
+ if s.endswith("\n"):
+ lines.append("")
+
+ if len(lines) == 0:
+ lines = [""]
+
+ end = Position(line=edit.range.end.line,
+ character=edit.range.end.character)
+ if edit.range.end.line == len(lines) and edit.range.end.character == 0:
+ end = Position(line=edit.range.end.line - 1,
+ character=len(lines[min(len(lines) - 1, edit.range.end.line - 1)]))
+
+ before_lines = lines[:edit.range.start.line]
+ after_lines = lines[end.line + 1:]
+ between_str = lines[min(len(lines) - 1, edit.range.start.line)][:edit.range.start.character] + \
+ edit.replacement + \
+ lines[min(len(lines) - 1, end.line)][end.character + 1:]
+
+ new_range = Range(
+ start=edit.range.start,
+ end=Position(
+ line=edit.range.start.line +
+ len(edit.replacement.splitlines()) - 1,
+ character=edit.range.start.character +
+ len(edit.replacement.splitlines()
+ [-1]) if edit.replacement != "" else 0
+ )
+ )
+
+ lines = before_lines + between_str.splitlines() + after_lines
+ return "\n".join(lines)
diff --git a/continuedev/src/continuedev/libs/util/copy_codebase.py b/continuedev/src/continuedev/libs/util/copy_codebase.py
index af957a34..97143faf 100644
--- a/continuedev/src/continuedev/libs/util/copy_codebase.py
+++ b/continuedev/src/continuedev/libs/util/copy_codebase.py
@@ -3,13 +3,12 @@ from pathlib import Path
from typing import Iterable, List, Union
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
-from ..models.main import FileEdit, DeleteDirectory, DeleteFile, AddDirectory, AddFile, FileSystemEdit, Position, Range, RenameFile, RenameDirectory, SequentialFileSystemEdit
-from ..models.filesystem import FileSystem
-from ..libs.main import Autopilot
-from ..libs.map_path import map_path
-from ..libs.steps.main import ManualEditAction
+from ...models.main import FileEdit, DeleteDirectory, DeleteFile, AddDirectory, AddFile, FileSystemEdit, RenameFile, RenameDirectory, SequentialFileSystemEdit
+from ...models.filesystem import FileSystem
+from ...core.autopilot import Autopilot
+from .map_path import map_path
+from ...core.sdk import ManualEditStep
import shutil
-import difflib
def create_copy(orig_root: str, copy_root: str = None, ignore: Iterable[str] = []):
@@ -36,33 +35,6 @@ def create_copy(orig_root: str, copy_root: str = None, ignore: Iterable[str] = [
os.symlink(child, map_path(child))
-def calculate_diff(filepath: str, original: str, updated: str) -> List[FileEdit]:
- s = difflib.SequenceMatcher(None, original, updated)
- offset = 0 # The indices are offset by previous deletions/insertions
- edits = []
- for tag, i1, i2, j1, j2 in s.get_opcodes():
- i1, i2, j1, j2 = i1 + offset, i2 + offset, j1 + offset, j2 + offset
- replacement = updated[j1:j2]
- if tag == "equal":
- pass
- elif tag == "delete":
- edits.append(FileEdit.from_deletion(
- filepath, Range.from_indices(original, i1, i2)))
- offset -= i2 - i1
- elif tag == "insert":
- edits.append(FileEdit.from_insertion(
- filepath, Position.from_index(original, i1), replacement))
- offset += j2 - j1
- elif tag == "replace":
- edits.append(FileEdit(filepath, Range.from_indices(
- original, i1, i2), replacement))
- offset += (j2 - j1) - (i2 + i1)
- else:
- raise Exception("Unexpected difflib.SequenceMatcher tag: " + tag)
-
- return edits
-
-
# The whole usage of watchdog here should only be specific to RealFileSystem, you want to have a different "Observer" class for VirtualFileSystem, which would depend on being sent notifications
class CopyCodebaseEventHandler(PatternMatchingEventHandler):
def __init__(self, ignore_directories: List[str], ignore_patterns: List[str], autopilot: Autopilot, orig_root: str, copy_root: str, filesystem: FileSystem):
diff --git a/continuedev/src/continuedev/models/filesystem_edit.py b/continuedev/src/continuedev/models/filesystem_edit.py
index 8e74b819..b06ca2b3 100644
--- a/continuedev/src/continuedev/models/filesystem_edit.py
+++ b/continuedev/src/continuedev/models/filesystem_edit.py
@@ -30,8 +30,8 @@ class FileEdit(AtomicFileSystemEdit):
return FileEdit(map_path(self.filepath, orig_root, copy_root), self.range, self.replacement)
@staticmethod
- def from_deletion(filepath: str, start: Position, end: Position) -> "FileEdit":
- return FileEdit(filepath, Range(start, end), "")
+ def from_deletion(filepath: str, range: Range) -> "FileEdit":
+ return FileEdit(filepath=filepath, range=range, replacement="")
@staticmethod
def from_insertion(filepath: str, position: Position, content: str) -> "FileEdit":
diff --git a/continuedev/src/continuedev/steps/chat.py b/continuedev/src/continuedev/steps/chat.py
index 80065c24..56e49223 100644
--- a/continuedev/src/continuedev/steps/chat.py
+++ b/continuedev/src/continuedev/steps/chat.py
@@ -7,6 +7,18 @@ from .core.core import MessageStep
class SimpleChatStep(Step):
user_input: str
+ name: str = "Chat"
async def run(self, sdk: ContinueSDK):
+<<<<<<< Updated upstream
self.description = sdk.models.gpt35.complete(self.user_input, with_history=await sdk.get_chat_context())
+=======
+ # TODO: With history
+ self.description = ""
+ for chunk in sdk.models.gpt35.stream_chat([{"role": "user", "content": self.user_input}]):
+ self.description += chunk
+ await sdk.update_ui()
+
+ self.name = sdk.models.gpt35.complete(
+ f"Write a short title for the following chat message: {self.description}").strip()
+>>>>>>> Stashed changes
diff --git a/continuedev/src/continuedev/steps/react.py b/continuedev/src/continuedev/steps/react.py
index 6b6024ce..d98b41c6 100644
--- a/continuedev/src/continuedev/steps/react.py
+++ b/continuedev/src/continuedev/steps/react.py
@@ -1,5 +1,9 @@
from textwrap import dedent
+<<<<<<< Updated upstream
from typing import List, Union
+=======
+from typing import List, Tuple
+>>>>>>> Stashed changes
from ..core.main import Step
from ..core.sdk import ContinueSDK
from .core.core import MessageStep
@@ -7,31 +11,42 @@ from .core.core import MessageStep
class NLDecisionStep(Step):
user_input: str
+<<<<<<< Updated upstream
steps: List[Step]
hide: bool = True
default_step: Union[Step, None] = None
+=======
+ steps: List[Tuple[Step, str]]
+
+ hide: bool = True
+>>>>>>> Stashed changes
async def run(self, sdk: ContinueSDK):
step_descriptions = "\n".join([
- f"- {step.name}: {step.description}"
+ f"- {step[0].name}: {step[1]}"
for step in self.steps
])
prompt = dedent(f"""\
- The following steps are available, in the format "- [step name]: [step description]":
- {step_descriptions}
-
- The user gave the following input:
-
- {self.user_input}
-
- Select the step which should be taken next. Say only the name of the selected step:""")
+ The following steps are available, in the format "- [step name]: [step description]":
+ {step_descriptions}
+
+ The user gave the following input:
+
+ {self.user_input}
+
+ Select the step which should be taken next to satisfy the user input. Say only the name of the selected step. You must choose one:""")
resp = sdk.models.gpt35.complete(prompt).lower()
step_to_run = None
for step in self.steps:
+<<<<<<< Updated upstream
if step.name.lower() in resp:
step_to_run = step
+=======
+ if step[0].name.lower() in resp:
+ step_to_run = step[0]
+>>>>>>> Stashed changes
step_to_run = step_to_run or self.default_step or self.steps[0]
diff --git a/extension/package.json b/extension/package.json
index 1d2fd995..8ee8cb4c 100644
--- a/extension/package.json
+++ b/extension/package.json
@@ -55,93 +55,13 @@
},
"commands": [
{
- "command": "continue.writeDocstring",
- "category": "Continue",
- "title": "Write a docstring for the current function"
- },
- {
"command": "continue.openContinueGUI",
"category": "Continue",
"title": "Open Continue GUI"
- },
- {
- "command": "continue.askQuestionFromInput",
- "Category": "Continue",
- "title": "Ask a question from input box"
- },
- {
- "command": "continue.openCapturedTerminal",
- "Category": "Continue",
- "title": "Open Captured Terminal"
- },
- {
- "command": "continue.askQuestion",
- "Category": "Continue",
- "title": "Ask a question from webview"
- },
- {
- "command": "continue.createTerminal",
- "category": "Continue",
- "title": "Create Terminal"
- },
- {
- "command": "continue.debugTest",
- "category": "Continue",
- "title": "Debug Test"
- },
- {
- "command": "continue.suggestionDown",
- "category": "Continue",
- "title": "Suggestion Down"
- },
- {
- "command": "continue.suggestionUp",
- "category": "Continue",
- "title": "Suggestion Up"
- },
- {
- "command": "continue.acceptSuggestion",
- "category": "Continue",
- "title": "Accept Suggestion"
- },
- {
- "command": "continue.rejectSuggestion",
- "category": "Continue",
- "title": "Reject Suggestion"
- },
- {
- "command": "continue.writeUnitTest",
- "title": "Write Unit Test",
- "category": "Continue"
- },
- {
- "command": "continue.findSuspiciousCode",
- "title": "Find Suspicious Code",
- "category": "Continue"
- },
- {
- "command": "continue.focusContinueInput",
- "title": "Focus Continue Input",
- "category": "Continue"
}
],
"keybindings": [
{
- "command": "continue.suggestionDown",
- "mac": "shift+ctrl+down",
- "key": "shift+ctrl+down"
- },
- {
- "command": "continue.suggestionUp",
- "mac": "shift+ctrl+up",
- "key": "shift+ctrl+up"
- },
- {
- "command": "continue.acceptSuggestion",
- "mac": "shift+ctrl+enter",
- "key": "shift+ctrl+enter"
- },
- {
"command": "continue.focusContinueInput",
"mac": "cmd+k",
"key": "ctrl+k"
diff --git a/extension/react-app/src/components/CodeBlock.tsx b/extension/react-app/src/components/CodeBlock.tsx
index e0336554..eedae3fb 100644
--- a/extension/react-app/src/components/CodeBlock.tsx
+++ b/extension/react-app/src/components/CodeBlock.tsx
@@ -11,6 +11,7 @@ const StyledPre = styled.pre`
border: 1px solid gray;
border-radius: ${defaultBorderRadius};
background-color: ${vscBackground};
+ padding: 8px;
`;
const StyledCode = styled.code`
diff --git a/extension/react-app/src/components/StepContainer.tsx b/extension/react-app/src/components/StepContainer.tsx
index 8ea54325..fb0143b5 100644
--- a/extension/react-app/src/components/StepContainer.tsx
+++ b/extension/react-app/src/components/StepContainer.tsx
@@ -84,6 +84,15 @@ const OnHoverDiv = styled.div`
animation: ${appear} 0.3s ease-in-out;
`;
+const MarkdownPre = styled.pre`
+ background-color: ${secondaryDark};
+ padding: 10px;
+ border-radius: ${defaultBorderRadius};
+ border: 0.5px solid white;
+`;
+
+const MarkdownCode = styled.code``;
+
function StepContainer(props: StepContainerProps) {
const [open, setOpen] = useState(
typeof props.open === "undefined" ? true : props.open
@@ -182,7 +191,19 @@ function StepContainer(props: StepContainerProps) {
{props.historyNode.observation.error as string}
</pre>
) : (
- <ReactMarkdown key={1} className="overflow-scroll">
+ <ReactMarkdown
+ key={1}
+ className="overflow-scroll"
+ components={{
+ pre: ({ node, ...props }) => {
+ return (
+ <CodeBlock
+ children={props.children[0] as string}
+ ></CodeBlock>
+ );
+ },
+ }}
+ >
{props.historyNode.step.description as any}
</ReactMarkdown>
)}
diff --git a/extension/react-app/src/tabs/chat/MessageDiv.tsx b/extension/react-app/src/tabs/chat/MessageDiv.tsx
index 1d7bb5f5..3543dd93 100644
--- a/extension/react-app/src/tabs/chat/MessageDiv.tsx
+++ b/extension/react-app/src/tabs/chat/MessageDiv.tsx
@@ -58,7 +58,9 @@ function MessageDiv(props: ChatMessage) {
}, [richContent, isStreaming]);
useEffect(() => {
- setRichContent([<ReactMarkdown key={1}>{props.content}</ReactMarkdown>]);
+ setRichContent([
+ <ReactMarkdown key={1} children={props.content}></ReactMarkdown>,
+ ]);
}, [props.content]);
return (
diff --git a/extension/react-app/src/tabs/gui.tsx b/extension/react-app/src/tabs/gui.tsx
index 5c75579b..9f7e651f 100644
--- a/extension/react-app/src/tabs/gui.tsx
+++ b/extension/react-app/src/tabs/gui.tsx
@@ -41,7 +41,7 @@ function GUI(props: GUIProps) {
// name: "Waiting for user input",
// cmd: "python3 /Users/natesesti/Desktop/continue/extension/examples/python/main.py",
// description:
- // "Run `python3 /Users/natesesti/Desktop/continue/extension/examples/python/main.py`",
+ // "Run `python3 /Users/natesesti/Desktop/continue/extension/examples/python/main.py` and ```\nprint(sum(first, second))\n```\n- Testing\n- Testing 2\n- Testing 3",
// },
// observation: {
// title: "ERROR FOUND",
@@ -92,7 +92,7 @@ function GUI(props: GUIProps) {
// prompt:
// "I ran into this problem with my Python code:\n\n Traceback (most recent call last):\n File \"/Users/natesesti/Desktop/continue/extension/examples/python/main.py\", line 7, in <module>\n print(sum(first, second))\n ^^^^^^^^^^^^^^^^^^\n File \"/Users/natesesti/Desktop/continue/extension/examples/python/sum.py\", line 2, in sum\n return a + b\n ~~^~~\nTypeError: unsupported operand type(s) for +: 'int' and 'str'\n\n Below are the files that might need to be fixed:\n\n {code}\n\n This is what the code should be in order to avoid the problem:\n",
// description:
- // "Editing files: /Users/natesesti/Desktop/continue/extension/examples/python/main.py",
+ // "Run `python3 /Users/natesesti/Desktop/continue/extension/examples/python/main.py` and\n```python\nprint(sum(first, second))\n```\n- Testing\n- Testing 2\n- Testing 3",
// },
// output: [
// null,
@@ -154,22 +154,30 @@ function GUI(props: GUIProps) {
// output: [null, null],
// },
// ],
- // current_index: 0,
+ // current_index: 3,
// } as any);
const topGuiDivRef = useRef<HTMLDivElement>(null);
const client = useContinueGUIProtocol();
+ const [scrollTimeout, setScrollTimeout] = useState<NodeJS.Timeout | null>(
+ null
+ );
const scrollToBottom = useCallback(() => {
+ if (scrollTimeout) {
+ clearTimeout(scrollTimeout);
+ }
+ // Debounced smooth scroll to bottom of screen
if (topGuiDivRef.current) {
- setTimeout(() => {
+ const timeout = setTimeout(() => {
window.scrollTo({
top: window.outerHeight,
behavior: "smooth",
});
- }, 100);
+ }, 200);
+ setScrollTimeout(timeout);
}
- }, [topGuiDivRef.current]);
+ }, [topGuiDivRef.current, scrollTimeout]);
useEffect(() => {
console.log("CLIENT ON STATE UPDATE: ", client, client?.onStateUpdate);
diff --git a/extension/src/continueIdeClient.ts b/extension/src/continueIdeClient.ts
index bbaf5f08..c395ae0e 100644
--- a/extension/src/continueIdeClient.ts
+++ b/extension/src/continueIdeClient.ts
@@ -13,6 +13,7 @@ import { FileEditWithFullContents } from "../schema/FileEditWithFullContents";
import fs = require("fs");
import { WebsocketMessenger } from "./util/messenger";
import { CapturedTerminal } from "./terminal/terminalEmulator";
+import { decorationManager } from "./decorations";
class IdeProtocolClient {
private messenger: WebsocketMessenger | null = null;
@@ -281,8 +282,36 @@ class IdeProtocolClient {
edit.range.start.line,
edit.range.start.character,
edit.range.end.line,
- edit.range.end.character + 1
+ edit.range.end.character
);
+ const decorationKey =
+ edit.replacement === ""
+ ? {
+ editorUri: editor.document.uri.fsPath,
+ options: {
+ range: new vscode.Range(
+ new vscode.Position(range.start.line, 0),
+ new vscode.Position(range.end.line + 1, 0)
+ ),
+ // after: {
+ // contentText: "Removed",
+ // },
+ },
+ decorationType: vscode.window.createTextEditorDecorationType({
+ backgroundColor: "rgba(255, 0, 0, 0.2)",
+ }),
+ }
+ : {
+ editorUri: editor.document.uri.fsPath,
+ options: {
+ range,
+ },
+ decorationType: vscode.window.createTextEditorDecorationType({
+ backgroundColor: "rgba(66, 105, 55, 1.0)",
+ isWholeLine: true,
+ }),
+ };
+ decorationManager.addDecoration(decorationKey);
editor.edit((editBuilder) => {
this._makingEdit += 2; // editBuilder.replace takes 2 edits: delete and insert
editBuilder.replace(range, edit.replacement);
diff --git a/extension/src/decorations.ts b/extension/src/decorations.ts
index 456f0c10..d2c94135 100644
--- a/extension/src/decorations.ts
+++ b/extension/src/decorations.ts
@@ -94,15 +94,22 @@ class DecorationManager {
decorationTypes = new Map();
decorationTypes.set(key.decorationType, [key.options]);
this.editorToDecorations.set(key.editorUri, decorationTypes);
- }
-
- const decorations = decorationTypes.get(key.decorationType);
- if (!decorations) {
- decorationTypes.set(key.decorationType, [key.options]);
} else {
- decorations.push(key.options);
+ const decorations = decorationTypes.get(key.decorationType);
+ if (!decorations) {
+ decorationTypes.set(key.decorationType, [key.options]);
+ } else {
+ decorations.push(key.options);
+ }
}
+
this.rerenderDecorations(key.editorUri, key.decorationType);
+
+ vscode.window.onDidChangeTextEditorSelection((event) => {
+ if (event.textEditor.document.fileName === key.editorUri) {
+ this.deleteAllDecorations(key.editorUri);
+ }
+ });
}
deleteDecoration(key: DecorationKey) {