MCPcopy Index your code
hub / github.com/FSoft-AI4Code/HyperAgent / GoToDefinitionTool

Class GoToDefinitionTool

src/hyperagent/tools/nav_tools.py:89–143  ·  view source on GitHub ↗

A tool for finding the definition of a symbol inside a code snippet. Args: path (str): The path to the code snippet. language (str): The programming language of the code snippet. Attributes: name (str): The name of the tool. description (str): A descrip

Source from the content-addressed store, hash-verified

87 relative_path: str = Field(..., description="The relative path of the file containing the symbol to search")
88
89class GoToDefinitionTool(BaseTool):
90 """
91 A tool for finding the definition of a symbol inside a code snippet.
92
93 Args:
94 path (str): The path to the code snippet.
95 language (str): The programming language of the code snippet.
96
97 Attributes:
98 name (str): The name of the tool.
99 description (str): A description of the tool.
100 args_schema (class): The schema for the tool's arguments.
101 path (str): The path to the code snippet.
102 lsptoolkit (LSPToolKit): An instance of the LSPToolKit class.
103 language (str): The programming language of the code snippet.
104 verbose (bool): Flag indicating whether to display verbose output.
105
106 Methods:
107 _run(word: str, line: int, relative_path: str) -> str: Runs the tool to find the definition of a symbol.
108
109 """
110
111 name = "go_to_definition"
112 description = """Useful when you want to find the definition of an identifier inside a code snippet that you saw. This can be applied into variable."""
113 args_schema = GoToDefinitionArgs
114 path = ""
115 lsptoolkit: LSPToolKit = None
116 language = "python"
117 verbose = False
118
119 def __init__(self, path: str, language: str):
120 super().__init__()
121 self.path = path
122 self.lsptoolkit = LSPToolKit(path, language)
123
124 def _run(self, word: str, relative_path: str, line: int = None, verbose: bool = True):
125 """
126 Runs the tool to find the definition of a symbol.
127
128 Args:
129 word (str): The symbol to find the definition of.
130 line (int): The line number of the symbol in the code snippet.
131 relative_path (str): The relative path of the code snippet.
132 verbose (bool, optional): Whether to display verbose output. Defaults to True.
133
134 Returns:
135 str: The definition of the symbol.
136
137 """
138 if line is not None:
139 line = int(line)
140 try:
141 return self.lsptoolkit.get_definition(word, relative_path, line, verbose=verbose)
142 except:
143 return "File read failed, please check the path again"
144
145class FindAllReferencesArgs(BaseModel):
146 word: str = Field(..., description="The name of the symbol to find all references")

Callers 1

get_all_symbolsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected