fix: 🐛 fix bugs when selecting code to edit

This commit is contained in:
Nate Sesti 2023-08-01 14:42:48 -07:00
parent 74a52c8399
commit fa34214012
7 changed files with 18 additions and 56 deletions

View file

@ -1,7 +1,7 @@
from functools import cached_property
import traceback
import time
from typing import Any, Callable, Coroutine, Dict, List, Union
from typing import Callable, Coroutine, Dict, List, Union
from aiohttp import ClientPayloadError
from pydantic import root_validator
@ -66,6 +66,8 @@ class Autopilot(ContinueBaseModel):
_user_input_queue = AsyncSubscriptionQueue()
_retry_queue = AsyncSubscriptionQueue()
started: bool = False
async def start(self):
self.continue_sdk = await ContinueSDK.create(self)
if override_policy := self.continue_sdk.config.policy_override:
@ -79,6 +81,7 @@ class Autopilot(ContinueBaseModel):
])
await self.context_manager.load_index(self.ide.workspace_directory)
self.started = True
class Config:
arbitrary_types_allowed = True
@ -201,7 +204,7 @@ class Autopilot(ContinueBaseModel):
await self.update_subscribers()
async def set_editing_at_ids(self, ids: List[str]):
self.context_manager.context_providers["code"].set_editing_at_ids(ids)
await self.context_manager.context_providers["code"].set_editing_at_ids(ids)
await self.update_subscribers()
async def _run_singular_step(self, step: "Step", is_future_step: bool = False) -> Coroutine[Observation, None, None]:

View file

@ -93,8 +93,8 @@ class GUIProtocolServer(AbstractGUIProtocolServer):
self.on_delete_context_with_ids(data["ids"])
elif message_type == "toggle_adding_highlighted_code":
self.on_toggle_adding_highlighted_code()
elif message_type == "set_editing_at_indices":
self.on_set_editing_at_indices(data["indices"])
elif message_type == "set_editing_at_ids":
self.on_set_editing_at_ids(data["ids"])
elif message_type == "show_logs_at_index":
self.on_show_logs_at_index(data["index"])
elif message_type == "select_context_item":
@ -138,9 +138,9 @@ class GUIProtocolServer(AbstractGUIProtocolServer):
create_async_task(
self.session.autopilot.toggle_adding_highlighted_code(), self.on_error)
def on_set_editing_at_indices(self, indices: List[int]):
def on_set_editing_at_ids(self, ids: List[str]):
create_async_task(
self.session.autopilot.set_editing_at_indices(indices), self.on_error)
self.session.autopilot.set_editing_at_ids(ids), self.on_error)
def on_show_logs_at_index(self, index: int):
name = f"continue_logs.txt"

View file

@ -309,7 +309,9 @@ class IdeProtocolServer(AbstractIdeProtocolServer):
def __get_autopilot(self):
if self.session_id not in self.session_manager.sessions:
return None
return self.session_manager.sessions[self.session_id].autopilot
autopilot = self.session_manager.sessions[self.session_id].autopilot
return autopilot if autopilot.started else None
def onFileEdits(self, edits: List[FileEditWithFullContents]):
if autopilot := self.__get_autopilot():

View file

@ -1,5 +1,4 @@
import asyncio
import sys
import time
import psutil
import os
@ -8,13 +7,11 @@ from fastapi.middleware.cors import CORSMiddleware
import atexit
import uvicorn
import argparse
import logging.config
from .ide import router as ide_router
from .gui import router as gui_router
from .session_manager import session_manager
from ..libs.util.paths import getLogFilePath
from ..libs.util.logging import logger
app = FastAPI()
@ -38,25 +35,6 @@ def health():
return {"status": "ok"}
class Logger(object):
def __init__(self, log_file: str):
self.terminal = sys.stdout
self.log = open(log_file, "a")
def write(self, message):
self.terminal.write(message)
self.log.write(message)
def flush(self):
# this flush method is needed for python 3 compatibility.
# this handles the flush command by doing nothing.
# you might want to specify some extra behavior here.
pass
def isatty(self):
return False
try:
# add cli arg for server port
parser = argparse.ArgumentParser()
@ -71,7 +49,6 @@ except Exception as e:
def run_server():
config = uvicorn.Config(app, host="127.0.0.1", port=args.port)
server = uvicorn.Server(config)
server.run()
@ -87,32 +64,10 @@ def cleanup():
loop.close()
def cpu_usage_report():
process = psutil.Process(os.getpid())
# Call cpu_percent once to start measurement, but ignore the result
process.cpu_percent(interval=None)
# Wait for a short period of time
time.sleep(1)
# Call cpu_percent again to get the CPU usage over the interval
cpu_usage = process.cpu_percent(interval=None)
logger.debug(f"CPU usage: {cpu_usage}%")
atexit.register(cleanup)
if __name__ == "__main__":
try:
# Uncomment to get CPU usage reports
# import threading
# def cpu_usage_loop():
# while True:
# cpu_usage_report()
# time.sleep(2)
# cpu_thread = threading.Thread(target=cpu_usage_loop)
# cpu_thread.start()
run_server()
except Exception as e:
logger.debug(f"Error starting Continue server: {e}")

View file

@ -168,7 +168,9 @@ const PillButton = (props: PillButtonProps) => {
data-tooltip-id={`edit-${props.index}`}
backgroundColor={"#8800aa55"}
onClick={() => {
client?.setEditingAtIndices([props.index]);
client?.setEditingAtIds([
props.item.description.id.item_id,
]);
}}
>
<PaintBrush

View file

@ -23,7 +23,7 @@ abstract class AbstractContinueGUIClientProtocol {
abstract deleteContextWithIds(ids: ContextItemId[]): void;
abstract setEditingAtIndices(indices: number[]): void;
abstract setEditingAtIds(ids: string[]): void;
abstract toggleAddingHighlightedCode(): void;

View file

@ -78,8 +78,8 @@ class ContinueGUIClientProtocol extends AbstractContinueGUIClientProtocol {
});
}
setEditingAtIndices(indices: number[]) {
this.messenger.send("set_editing_at_indices", { indices });
setEditingAtIds(ids: string[]) {
this.messenger.send("set_editing_at_ids", { ids });
}
toggleAddingHighlightedCode(): void {