diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-09-01 14:08:30 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-09-01 14:08:30 -0700 |
commit | 631f7498190af1403c44f0bfdc93032a965df3ea (patch) | |
tree | fafa6ddf7d9d08d314093e798b3cc370332a086c /continuedev/src | |
parent | e6d4e5f60bcf855401d09a2649a516b5932cc53a (diff) | |
parent | 07f1a9a4dbbca57c14957eb21ef356adbf803bff (diff) | |
download | sncontinue-631f7498190af1403c44f0bfdc93032a965df3ea.tar.gz sncontinue-631f7498190af1403c44f0bfdc93032a965df3ea.tar.bz2 sncontinue-631f7498190af1403c44f0bfdc93032a965df3ea.zip |
Merge branch 'main' of https://github.com/continuedev/continue
Diffstat (limited to 'continuedev/src')
5 files changed, 67 insertions, 24 deletions
diff --git a/continuedev/src/continuedev/libs/util/paths.py b/continuedev/src/continuedev/libs/util/paths.py index b3e9ecc1..9f3117d0 100644 --- a/continuedev/src/continuedev/libs/util/paths.py +++ b/continuedev/src/continuedev/libs/util/paths.py @@ -31,6 +31,12 @@ def getServerFolderPath(): return path +def getMeilisearchExePath(): + binary_name = "meilisearch.exe" if os.name == "nt" else "meilisearch" + path = os.path.join(getServerFolderPath(), binary_name) + return path + + def getSessionFilePath(session_id: str): path = os.path.join(getSessionsFolderPath(), f"{session_id}.json") os.makedirs(os.path.dirname(path), exist_ok=True) diff --git a/continuedev/src/continuedev/plugins/context_providers/file.py b/continuedev/src/continuedev/plugins/context_providers/file.py index 9846dd3e..859088b8 100644 --- a/continuedev/src/continuedev/plugins/context_providers/file.py +++ b/continuedev/src/continuedev/plugins/context_providers/file.py @@ -123,7 +123,7 @@ class FileContextProvider(ContextProvider): ) async def provide_context_items(self, workspace_dir: str) -> List[ContextItem]: - contents = await self.sdk.ide.listDirectoryContents(workspace_dir) + contents = await self.sdk.ide.listDirectoryContents(workspace_dir, True) if contents is None: return [] diff --git a/continuedev/src/continuedev/server/ide.py b/continuedev/src/continuedev/server/ide.py index 8a62c39e..89fcd0d1 100644 --- a/continuedev/src/continuedev/server/ide.py +++ b/continuedev/src/continuedev/server/ide.py @@ -494,10 +494,12 @@ class IdeProtocolServer(AbstractIdeProtocolServer): ) return resp.fileEdit - async def listDirectoryContents(self, directory: str) -> List[str]: + async def listDirectoryContents( + self, directory: str, recursive: bool = False + ) -> List[str]: """List the contents of a directory""" resp = await self._send_and_receive_json( - {"directory": directory}, + {"directory": directory, "recursive": recursive}, ListDirectoryContentsResponse, "listDirectoryContents", ) @@ -574,7 +576,11 @@ async def websocket_endpoint(websocket: WebSocket, session_id: str = None): # Start meilisearch try: - await start_meilisearch() + + async def on_err(e): + logger.debug(f"Failed to start MeiliSearch: {e}") + + create_async_task(start_meilisearch(), on_err) except Exception as e: logger.debug("Failed to start MeiliSearch") logger.debug(e) diff --git a/continuedev/src/continuedev/server/ide_protocol.py b/continuedev/src/continuedev/server/ide_protocol.py index 4ef4bde7..2a07ae2a 100644 --- a/continuedev/src/continuedev/server/ide_protocol.py +++ b/continuedev/src/continuedev/server/ide_protocol.py @@ -148,7 +148,9 @@ class AbstractIdeProtocolServer(ABC): """Called when a file is saved""" @abstractmethod - async def listDirectoryContents(self, directory: str) -> List[str]: + async def listDirectoryContents( + self, directory: str, recursive: bool = False + ) -> List[str]: """List directory contents""" @abstractmethod diff --git a/continuedev/src/continuedev/server/meilisearch_server.py b/continuedev/src/continuedev/server/meilisearch_server.py index 037ce8fa..390eeb50 100644 --- a/continuedev/src/continuedev/server/meilisearch_server.py +++ b/continuedev/src/continuedev/server/meilisearch_server.py @@ -3,20 +3,59 @@ import os import shutil import subprocess +import aiofiles +import aiohttp from meilisearch_python_async import Client from ..libs.util.logging import logger -from ..libs.util.paths import getServerFolderPath +from ..libs.util.paths import getMeilisearchExePath, getServerFolderPath -def ensure_meilisearch_installed() -> bool: +async def download_file(url: str, filename: str): + async with aiohttp.ClientSession() as session: + async with session.get(url) as resp: + if resp.status == 200: + f = await aiofiles.open(filename, mode="wb") + await f.write(await resp.read()) + await f.close() + + +async def download_meilisearch(): + """ + Downloads MeiliSearch. + """ + + serverPath = getServerFolderPath() + logger.debug("Downloading MeiliSearch...") + + if os.name == "nt": + download_url = "https://github.com/meilisearch/meilisearch/releases/download/v1.3.2/meilisearch-windows-amd64.exe" + download_path = getMeilisearchExePath() + if not os.path.exists(download_path): + await download_file(download_url, download_path) + # subprocess.run( + # f"curl -L {download_url} -o {download_path}", + # shell=True, + # check=True, + # cwd=serverPath, + # ) + else: + subprocess.run( + "curl -L https://install.meilisearch.com | sh", + shell=True, + check=True, + cwd=serverPath, + ) + + +async def ensure_meilisearch_installed() -> bool: """ Checks if MeiliSearch is installed. Returns a bool indicating whether it was installed to begin with. """ serverPath = getServerFolderPath() - meilisearchPath = os.path.join(serverPath, "meilisearch") + meilisearchPath = getMeilisearchExePath() dumpsPath = os.path.join(serverPath, "dumps") dataMsPath = os.path.join(serverPath, "data.ms") @@ -40,14 +79,7 @@ def ensure_meilisearch_installed() -> bool: for p in existing_paths: shutil.rmtree(p, ignore_errors=True) - # Download MeiliSearch - logger.debug("Downloading MeiliSearch...") - subprocess.run( - "curl -L https://install.meilisearch.com | sh", - shell=True, - check=True, - cwd=serverPath, - ) + await download_meilisearch() return False @@ -66,7 +98,7 @@ async def check_meilisearch_running() -> bool: if resp.status != "available": return False return True - except Exception as e: + except Exception: return False except Exception: return False @@ -86,24 +118,21 @@ async def start_meilisearch(): """ Starts the MeiliSearch server, wait for it. """ - - # Doesn't work on windows for now - if not os.name == "posix": - return - serverPath = getServerFolderPath() # Check if MeiliSearch is installed, if not download - was_already_installed = ensure_meilisearch_installed() + was_already_installed = await ensure_meilisearch_installed() # Check if MeiliSearch is running if not await check_meilisearch_running() or not was_already_installed: logger.debug("Starting MeiliSearch...") + binary_name = "meilisearch" if os.name == "nt" else "./meilisearch" subprocess.Popen( - ["./meilisearch", "--no-analytics"], + [binary_name, "--no-analytics"], cwd=serverPath, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, close_fds=True, start_new_session=True, + shell=True ) |