feat: ✨ refactor via search Step
This commit is contained in:
parent
c9c2fe6810
commit
9cd249ee00
4 changed files with 60 additions and 27 deletions
25
continuedev/src/continuedev/libs/util/ripgrep.py
Normal file
25
continuedev/src/continuedev/libs/util/ripgrep.py
Normal file
|
|
@ -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
|
||||
|
|
@ -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 []
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ const sidebars = {
|
|||
"walkthroughs/codellama",
|
||||
"walkthroughs/manually-run-continue",
|
||||
"walkthroughs/running-continue-without-internet",
|
||||
"walkthroughs/headless-mode",
|
||||
],
|
||||
},
|
||||
"development-data",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue