A tool for searching for matched identifiers (variable, function, class name) from a Python repository. Primarily used for class and function search. The results are mixed and not sorted by any criteria. Args: path (str): The path to the Python repository. language (str
| 28 | names: list[str] = Field(..., description="The names of the identifiers to search. Identifier should be a single word like `some_function` not `something.something`") |
| 29 | |
| 30 | class CodeSearchTool(BaseTool): |
| 31 | """ |
| 32 | A tool for searching for matched identifiers (variable, function, class name) from a Python repository. |
| 33 | Primarily used for class and function search. The results are mixed and not sorted by any criteria. |
| 34 | |
| 35 | Args: |
| 36 | path (str): The path to the Python repository. |
| 37 | language (str): The programming language of the repository. |
| 38 | |
| 39 | Attributes: |
| 40 | name (str): The name of the tool. |
| 41 | description (str): A description of the tool. |
| 42 | args_schema (Type[BaseModel]): The schema for the tool's arguments. |
| 43 | path (str): The path to the Python repository. |
| 44 | verbose (bool): Whether to display verbose output. |
| 45 | language (str): The programming language of the repository. |
| 46 | backend (jedi.Project | ZoektServer): The search engine backend. |
| 47 | |
| 48 | Methods: |
| 49 | _run(names: list[str], verbose: bool = True) -> List[SearchResult]: |
| 50 | Run the code search tool synchronously. |
| 51 | _arun(names: list[str], verbose: bool = True) -> List[SearchResult]: |
| 52 | Run the code search tool asynchronously (not implemented). |
| 53 | |
| 54 | """ |
| 55 | |
| 56 | name = "code_search" |
| 57 | description = """Useful when you want to find all matched primary symbols (function, class name) in a repository. You want to quickly find a class or function like `some_function` function not `something.something`""" |
| 58 | args_schema: Type[BaseModel] = CodeSearchArgs |
| 59 | path = "" |
| 60 | verbose = False |
| 61 | language = "python" |
| 62 | backend: ZoektServer = None |
| 63 | |
| 64 | def __init__(self, path: str, language: str, index_path: Optional[str] = None, build: bool = False): |
| 65 | super().__init__() |
| 66 | self.path = path |
| 67 | self.language = language |
| 68 | if build: |
| 69 | if not os.path.exists(index_path): |
| 70 | os.makedirs(index_path) |
| 71 | self.backend = ZoektServer(language) |
| 72 | self.backend.setup_index(path, index_path=index_path) |
| 73 | else: |
| 74 | self.backend = ZoektServer(language, repo_path=path, index_path=index_path) |
| 75 | |
| 76 | |
| 77 | def _run(self, names: list[str], verbose: bool = True): |
| 78 | if any ("." in name for name in names): |
| 79 | return "Please check the word again, the word should be identifier only, not `something.something`" |
| 80 | result = search_elements_inside_project(names, self.backend, verbose=verbose, language=self.language) |
| 81 | return result |
| 82 | |
| 83 | |
| 84 | class GoToDefinitionArgs(BaseModel): |
nothing calls this directly
no outgoing calls
no test coverage detected