fix: 🐛 fix ssh /edit by checking for file through vscode fs
This commit is contained in:
parent
b0426d82a4
commit
417d45ccdd
7 changed files with 38 additions and 14 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
from textwrap import dedent
|
||||
from typing import Any, Coroutine, Dict, Generator, List, Union
|
||||
|
||||
import aiohttp
|
||||
|
|
@ -46,12 +47,14 @@ class Ollama(LLM):
|
|||
prompt = ""
|
||||
has_system = msgs[0]["role"] == "system"
|
||||
if has_system:
|
||||
system_message = f"""\
|
||||
system_message = dedent(
|
||||
f"""\
|
||||
<<SYS>>
|
||||
{self.system_message}
|
||||
<</SYS>>
|
||||
|
||||
"""
|
||||
)
|
||||
if len(msgs) > 1:
|
||||
prompt += f"[INST] {system_message}{msgs[1]['content']} [/INST]"
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -1,16 +1,7 @@
|
|||
import json
|
||||
import ssl
|
||||
import traceback
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
Coroutine,
|
||||
Dict,
|
||||
Generator,
|
||||
List,
|
||||
Optional,
|
||||
Union,
|
||||
)
|
||||
from typing import Any, Callable, Coroutine, Dict, Generator, List, Optional, Union
|
||||
|
||||
import aiohttp
|
||||
import certifi
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
# These steps are depended upon by ContinueSDK
|
||||
import difflib
|
||||
import os
|
||||
import traceback
|
||||
from textwrap import dedent
|
||||
from typing import Any, Coroutine, List, Union
|
||||
|
|
@ -822,7 +821,8 @@ Please output the code to be inserted at the cursor in order to fulfill the user
|
|||
|
||||
for rif in rif_with_contents:
|
||||
# If the file doesn't exist, ask them to save it first
|
||||
if not os.path.exists(rif.filepath):
|
||||
exists = await sdk.ide.fileExists(rif.filepath)
|
||||
if not exists:
|
||||
message = (
|
||||
f"The file {rif.filepath} does not exist. Please save it first."
|
||||
)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class DefaultOnTracebackStep(Step):
|
|||
for seg in segs:
|
||||
if (
|
||||
seg.startswith(os.path.sep)
|
||||
and os.path.exists(seg)
|
||||
and os.path.exists(seg) # TODO: Use sdk.ide.fileExists
|
||||
and os.path.commonprefix([seg, sdk.ide.workspace_directory])
|
||||
== sdk.ide.workspace_directory
|
||||
):
|
||||
|
|
|
|||
|
|
@ -124,6 +124,10 @@ class ListDirectoryContentsResponse(BaseModel):
|
|||
contents: List[str]
|
||||
|
||||
|
||||
class FileExistsResponse(BaseModel):
|
||||
exists: bool
|
||||
|
||||
|
||||
T = TypeVar("T", bound=BaseModel)
|
||||
|
||||
|
||||
|
|
@ -246,6 +250,7 @@ class IdeProtocolServer(AbstractIdeProtocolServer):
|
|||
"runCommand",
|
||||
"getTerminalContents",
|
||||
"listDirectoryContents",
|
||||
"fileExists",
|
||||
]:
|
||||
self.sub_queue.post(message_type, data)
|
||||
elif message_type == "workspaceDirectory":
|
||||
|
|
@ -455,6 +460,13 @@ class IdeProtocolServer(AbstractIdeProtocolServer):
|
|||
)
|
||||
return resp.contents
|
||||
|
||||
async def fileExists(self, filepath: str) -> str:
|
||||
"""Check whether file exists"""
|
||||
resp = await self._send_and_receive_json(
|
||||
{"filepath": filepath}, FileExistsResponse, "fileExists"
|
||||
)
|
||||
return resp.exists
|
||||
|
||||
async def getUserSecret(self, key: str) -> str:
|
||||
"""Get a user secret"""
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -151,5 +151,9 @@ class AbstractIdeProtocolServer(ABC):
|
|||
async def listDirectoryContents(self, directory: str) -> List[str]:
|
||||
"""List directory contents"""
|
||||
|
||||
@abstractmethod
|
||||
async def fileExists(self, filepath: str) -> str:
|
||||
"""Check if a file exists"""
|
||||
|
||||
workspace_directory: str
|
||||
unique_id: str
|
||||
|
|
|
|||
|
|
@ -236,6 +236,11 @@ class IdeProtocolClient {
|
|||
uniqueId: this.getUniqueId(),
|
||||
});
|
||||
break;
|
||||
case "fileExists":
|
||||
messenger.send("fileExists", {
|
||||
exists: await this.fileExists(data.filepath),
|
||||
});
|
||||
break;
|
||||
case "getUserSecret":
|
||||
messenger.send("getUserSecret", {
|
||||
value: await this.getUserSecret(data.key),
|
||||
|
|
@ -432,6 +437,15 @@ class IdeProtocolClient {
|
|||
openEditorAndRevealRange(filepath, undefined, vscode.ViewColumn.One);
|
||||
}
|
||||
|
||||
async fileExists(filepath: string): Promise<boolean> {
|
||||
try {
|
||||
await vscode.workspace.fs.stat(vscode.Uri.file(filepath));
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
showVirtualFile(name: string, contents: string) {
|
||||
vscode.workspace
|
||||
.openTextDocument(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue