getVisibleFiles
This commit is contained in:
parent
fb45ef57ec
commit
d78cb7b1e0
11 changed files with 40 additions and 27 deletions
|
|
@ -208,6 +208,8 @@ class Autopilot(ContinueBaseModel):
|
|||
async def delete_at_index(self, index: int):
|
||||
self.history.timeline[index].step.hide = True
|
||||
self.history.timeline[index].deleted = True
|
||||
self.history.timeline[index].active = False
|
||||
|
||||
await self.update_subscribers()
|
||||
|
||||
async def delete_context_at_indices(self, indices: List[int]):
|
||||
|
|
|
|||
|
|
@ -204,14 +204,14 @@ class ContinueSDK(AbstractContinueSDK):
|
|||
|
||||
preface = "The following code is highlighted"
|
||||
|
||||
# If no higlighted ranges, use first file as context
|
||||
if len(highlighted_code) == 0:
|
||||
preface = "The following file is open"
|
||||
# Get the full contents of all open files
|
||||
files = await self.ide.getOpenFiles()
|
||||
if len(files) > 0:
|
||||
content = await self.ide.readFile(files[0])
|
||||
visible_files = await self.ide.getVisibleFiles()
|
||||
if len(visible_files) > 0:
|
||||
content = await self.ide.readFile(visible_files[0])
|
||||
highlighted_code = [
|
||||
RangeInFileWithContents.from_entire_file(files[0], content)]
|
||||
RangeInFileWithContents.from_entire_file(visible_files[0], content)]
|
||||
|
||||
for rif in highlighted_code:
|
||||
msg = ChatMessage(content=f"{preface} ({rif.filepath}):\n```\n{rif.contents}\n```",
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ class TemplateRecipe(Step):
|
|||
|
||||
# The code executed when the recipe is run
|
||||
async def run(self, sdk: ContinueSDK) -> Coroutine[Observation, None, None]:
|
||||
open_files = await sdk.ide.getOpenFiles()
|
||||
visible_files = await sdk.ide.getVisibleFiles()
|
||||
await sdk.edit_file(
|
||||
filename=open_files[0],
|
||||
filename=visible_files[0],
|
||||
prompt=f"Append a statement to print `Hello, {self.name}!` at the end of the file."
|
||||
)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class WritePytestsRecipe(Step):
|
|||
|
||||
async def run(self, sdk: ContinueSDK):
|
||||
if self.for_filepath is None:
|
||||
self.for_filepath = (await sdk.ide.getOpenFiles())[0]
|
||||
self.for_filepath = (await sdk.ide.getVisibleFiles())[0]
|
||||
|
||||
filename = os.path.basename(self.for_filepath)
|
||||
dirname = os.path.dirname(self.for_filepath)
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ class FileEditsUpdate(BaseModel):
|
|||
class OpenFilesResponse(BaseModel):
|
||||
openFiles: List[str]
|
||||
|
||||
class VisibleFilesResponse(BaseModel):
|
||||
visibleFiles: List[str]
|
||||
|
||||
class HighlightedCodeResponse(BaseModel):
|
||||
highlightedCode: List[RangeInFile]
|
||||
|
|
@ -180,7 +182,7 @@ class IdeProtocolServer(AbstractIdeProtocolServer):
|
|||
self.onMainUserInput(data["input"])
|
||||
elif message_type == "deleteAtIndex":
|
||||
self.onDeleteAtIndex(data["index"])
|
||||
elif message_type in ["highlightedCode", "openFiles", "readFile", "editFile", "getUserSecret", "runCommand", "uniqueId"]:
|
||||
elif message_type in ["highlightedCode", "openFiles", "visibleFiles", "readFile", "editFile", "getUserSecret", "runCommand", "uniqueId"]:
|
||||
self.sub_queue.post(message_type, data)
|
||||
elif message_type == "workspaceDirectory":
|
||||
self.workspace_directory = data["workspaceDirectory"]
|
||||
|
|
@ -302,6 +304,10 @@ class IdeProtocolServer(AbstractIdeProtocolServer):
|
|||
async def getOpenFiles(self) -> List[str]:
|
||||
resp = await self._send_and_receive_json({}, OpenFilesResponse, "openFiles")
|
||||
return resp.openFiles
|
||||
|
||||
async def getVisibleFiles(self) -> List[str]:
|
||||
resp = await self._send_and_receive_json({}, VisibleFilesResponse, "visibleFiles")
|
||||
return resp.visibleFiles
|
||||
|
||||
async def get_unique_id(self) -> str:
|
||||
resp = await self._send_and_receive_json({}, UniqueIdResponse, "uniqueId")
|
||||
|
|
|
|||
|
|
@ -51,6 +51,10 @@ class AbstractIdeProtocolServer(ABC):
|
|||
async def getOpenFiles(self) -> List[str]:
|
||||
"""Get a list of open files"""
|
||||
|
||||
@abstractmethod
|
||||
async def getVisibleFiles(self) -> List[str]:
|
||||
"""Get a list of visible files"""
|
||||
|
||||
@abstractmethod
|
||||
async def getHighlightedCode(self) -> List[RangeInFile]:
|
||||
"""Get a list of highlighted code"""
|
||||
|
|
|
|||
|
|
@ -99,8 +99,8 @@ class FasterEditHighlightedCodeStep(Step):
|
|||
async def run(self, sdk: ContinueSDK) -> Coroutine[Observation, None, None]:
|
||||
range_in_files = await sdk.get_code_context(only_editing=True)
|
||||
if len(range_in_files) == 0:
|
||||
# Get the full contents of all open files
|
||||
files = await sdk.ide.getOpenFiles()
|
||||
# Get the full contents of all visible files
|
||||
files = await sdk.ide.getVisibleFiles()
|
||||
contents = {}
|
||||
for file in files:
|
||||
contents[file] = await sdk.ide.readFile(file)
|
||||
|
|
@ -191,8 +191,8 @@ class StarCoderEditHighlightedCodeStep(Step):
|
|||
range_in_files = await sdk.get_code_context(only_editing=True)
|
||||
found_highlighted_code = len(range_in_files) > 0
|
||||
if not found_highlighted_code:
|
||||
# Get the full contents of all open files
|
||||
files = await sdk.ide.getOpenFiles()
|
||||
# Get the full contents of all visible files
|
||||
files = await sdk.ide.getVisibleFiles()
|
||||
contents = {}
|
||||
for file in files:
|
||||
contents[file] = await sdk.ide.readFile(file)
|
||||
|
|
@ -275,16 +275,6 @@ class EditHighlightedCodeStep(Step):
|
|||
await sdk.run_step(DefaultModelEditCodeStep(user_input=self.user_input, range_in_files=range_in_files))
|
||||
|
||||
|
||||
class FindCodeStep(Step):
|
||||
prompt: str
|
||||
|
||||
async def describe(self, models: Models) -> Coroutine[str, None, None]:
|
||||
return "Finding code"
|
||||
|
||||
async def run(self, sdk: ContinueSDK) -> Coroutine[Observation, None, None]:
|
||||
return await sdk.ide.getOpenFiles()
|
||||
|
||||
|
||||
class UserInputStep(Step):
|
||||
user_input: str
|
||||
|
||||
|
|
|
|||
|
|
@ -29,4 +29,4 @@ class WelcomeStep(Step):
|
|||
- Ask about how the class works, how to write it in another language, etc.
|
||||
\"\"\"""")))
|
||||
|
||||
await sdk.ide.setFileOpen(filepath=filepath)
|
||||
# await sdk.ide.setFileOpen(filepath=filepath)
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ function StepContainer(props: StepContainerProps) {
|
|||
>
|
||||
<StepContainerDiv open={props.open}>
|
||||
<GradientBorder
|
||||
loading={props.historyNode.active as boolean | false}
|
||||
loading={props.historyNode.active as boolean || false}
|
||||
isFirst={props.isFirst}
|
||||
isLast={props.isLast}
|
||||
borderColor={
|
||||
|
|
@ -178,7 +178,7 @@ function StepContainer(props: StepContainerProps) {
|
|||
}}
|
||||
>
|
||||
<HeaderDiv
|
||||
loading={props.historyNode.active as boolean | false}
|
||||
loading={props.historyNode.active as boolean || false}
|
||||
error={props.historyNode.observation?.error ? true : false}
|
||||
>
|
||||
<div className="m-2">
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ export function getContinueServerUrl() {
|
|||
extensionContext &&
|
||||
extensionContext.extensionMode === vscode.ExtensionMode.Development
|
||||
) {
|
||||
// return "http://localhost:8001";
|
||||
return "http://localhost:8001";
|
||||
}
|
||||
return (
|
||||
vscode.workspace.getConfiguration("continue").get<string>("serverUrl") ||
|
||||
|
|
|
|||
|
|
@ -131,6 +131,11 @@ class IdeProtocolClient {
|
|||
openFiles: this.getOpenFiles(),
|
||||
});
|
||||
break;
|
||||
case "visibleFiles":
|
||||
messenger.send("visibleFiles", {
|
||||
visibleFiles: this.getVisibleFiles(),
|
||||
});
|
||||
break;
|
||||
case "readFile":
|
||||
messenger.send("readFile", {
|
||||
contents: this.readFile(data.filepath),
|
||||
|
|
@ -330,6 +335,12 @@ class IdeProtocolClient {
|
|||
});
|
||||
}
|
||||
|
||||
getVisibleFiles(): string[] {
|
||||
return vscode.window.visibleTextEditors.map((editor) => {
|
||||
return editor.document.uri.fsPath;
|
||||
});
|
||||
}
|
||||
|
||||
saveFile(filepath: string) {
|
||||
vscode.window.visibleTextEditors.forEach((editor) => {
|
||||
if (editor.document.uri.fsPath === filepath) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue