diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-09-17 12:15:08 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-09-17 12:15:08 -0700 |
commit | 9cd249ee007911037639281c6d7590889ad7b467 (patch) | |
tree | 08e5cf59c2ee019ea069c7fd907b05564550cbe7 | |
parent | c9c2fe681050745290f3ae4389a9ee7cff35fc91 (diff) | |
download | sncontinue-9cd249ee007911037639281c6d7590889ad7b467.tar.gz sncontinue-9cd249ee007911037639281c6d7590889ad7b467.tar.bz2 sncontinue-9cd249ee007911037639281c6d7590889ad7b467.zip |
feat: :sparkles: refactor via search Step
-rw-r--r-- | continuedev/src/continuedev/libs/util/ripgrep.py | 25 | ||||
-rw-r--r-- | continuedev/src/continuedev/plugins/context_providers/search.py | 29 | ||||
-rw-r--r-- | continuedev/src/continuedev/plugins/steps/refactor.py | 32 | ||||
-rw-r--r-- | docs/sidebars.js | 1 |
4 files changed, 60 insertions, 27 deletions
diff --git a/continuedev/src/continuedev/libs/util/ripgrep.py b/continuedev/src/continuedev/libs/util/ripgrep.py new file mode 100644 index 00000000..f7e0af9a --- /dev/null +++ b/continuedev/src/continuedev/libs/util/ripgrep.py @@ -0,0 +1,25 @@ +import os + + +def get_rg_path(): + if os.name == "nt": + paths_to_try = [ + f"C:\\Users\\{os.getlogin()}\\AppData\\Local\\Programs\\Microsoft VS Code\\resources\\app\\node_modules.asar.unpacked\\@vscode\\ripgrep\\bin\\rg.exe", + f"C:\\Users\\{os.getlogin()}\\AppData\\Local\\Programs\\Microsoft VS Code\\resources\\app\\node_modules.asar.unpacked\\vscode-ripgrep\\bin\\rg.exe", + ] + for path in paths_to_try: + if os.path.exists(path): + rg_path = path + break + elif os.name == "posix": + if "darwin" in os.sys.platform: + rg_path = "/Applications/Visual Studio Code.app/Contents/Resources/app/node_modules.asar.unpacked/@vscode/ripgrep/bin/rg" + else: + rg_path = "/usr/share/code/resources/app/node_modules.asar.unpacked/vscode-ripgrep/bin/rg" + else: + rg_path = "rg" + + if not os.path.exists(rg_path): + rg_path = "rg" + + return rg_path diff --git a/continuedev/src/continuedev/plugins/context_providers/search.py b/continuedev/src/continuedev/plugins/context_providers/search.py index 4e2e33da..a36b2a0a 100644 --- a/continuedev/src/continuedev/plugins/context_providers/search.py +++ b/continuedev/src/continuedev/plugins/context_providers/search.py @@ -1,4 +1,3 @@ -import os from typing import List from pydantic import Field @@ -7,6 +6,7 @@ from ripgrepy import Ripgrepy from ...core.context import ContextProvider from ...core.main import ContextItem, ContextItemDescription, ContextItemId from ...libs.util.logging import logger +from ...libs.util.ripgrep import get_rg_path from .util import remove_meilisearch_disallowed_chars @@ -36,31 +36,8 @@ class SearchContextProvider(ContextProvider): ), ) - def _get_rg_path(self): - if os.name == "nt": - paths_to_try = [ - f"C:\\Users\\{os.getlogin()}\\AppData\\Local\\Programs\\Microsoft VS Code\\resources\\app\\node_modules.asar.unpacked\\@vscode\\ripgrep\\bin\\rg.exe", - f"C:\\Users\\{os.getlogin()}\\AppData\\Local\\Programs\\Microsoft VS Code\\resources\\app\\node_modules.asar.unpacked\\vscode-ripgrep\\bin\\rg.exe", - ] - for path in paths_to_try: - if os.path.exists(path): - rg_path = path - break - elif os.name == "posix": - if "darwin" in os.sys.platform: - rg_path = "/Applications/Visual Studio Code.app/Contents/Resources/app/node_modules.asar.unpacked/@vscode/ripgrep/bin/rg" - else: - rg_path = "/usr/share/code/resources/app/node_modules.asar.unpacked/vscode-ripgrep/bin/rg" - else: - rg_path = "rg" - - if not os.path.exists(rg_path): - rg_path = "rg" - - return rg_path - async def _search(self, query: str) -> str: - rg = Ripgrepy(query, self.workspace_dir, rg_path=self._get_rg_path()) + rg = Ripgrepy(query, self.workspace_dir, rg_path=get_rg_path()) results = rg.I().context(2).run() return f"Search results in workspace for '{query}':\n\n{results}" @@ -92,7 +69,7 @@ class SearchContextProvider(ContextProvider): self.workspace_dir = workspace_dir try: - Ripgrepy("", workspace_dir, rg_path=self._get_rg_path()) + Ripgrepy("", workspace_dir, rg_path=get_rg_path()) except Exception as e: logger.warning(f"Failed to initialize ripgrepy: {e}") return [] diff --git a/continuedev/src/continuedev/plugins/steps/refactor.py b/continuedev/src/continuedev/plugins/steps/refactor.py index cfbce662..56e9e09e 100644 --- a/continuedev/src/continuedev/plugins/steps/refactor.py +++ b/continuedev/src/continuedev/plugins/steps/refactor.py @@ -1,10 +1,13 @@ import asyncio -from typing import List +from typing import List, Optional + +from ripgrepy import Ripgrepy from ...core.main import Step from ...core.models import Models from ...core.sdk import ContinueSDK from ...libs.llm.prompts.edit import simplified_edit_prompt +from ...libs.util.ripgrep import get_rg_path from ...libs.util.strings import remove_quotes_and_escapes, strip_code_block from ...libs.util.templating import render_prompt_template from ...models.filesystem import RangeInFile @@ -32,6 +35,33 @@ class RefactorReferencesStep(Step): ) +class RefactorBySearchStep(Step): + name: str = "Refactor by search" + + pattern: str + user_input: str + + rg_path: Optional[str] = None + "Optional path to ripgrep executable" + + def get_range_for_result(self, result) -> RangeInFile: + pass + + async def run(self, sdk: ContinueSDK): + rg = Ripgrepy( + self.pattern, + sdk.ide.workspace_directory, + rg_path=self.rg_path or get_rg_path(), + ) + + results = rg.I().context(2).run() + range_in_files = [self.get_range_for_result(result) for result in results] + + await sdk.run_step( + ParallelEditStep(user_input=self.user_input, range_in_files=range_in_files) + ) + + class ParallelEditStep(Step): name: str = "Edit multiple ranges in parallel" user_input: str diff --git a/docs/sidebars.js b/docs/sidebars.js index b6c7b899..d7e0ceda 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -40,6 +40,7 @@ const sidebars = { "walkthroughs/codellama", "walkthroughs/manually-run-continue", "walkthroughs/running-continue-without-internet", + "walkthroughs/headless-mode", ], }, "development-data", |