MCPcopy Create free account
hub / github.com/FSoft-AI4Code/HyperAgent / get_code_jedi

Function get_code_jedi

src/hyperagent/code_search.py:48–72  ·  view source on GitHub ↗

Fetch and possibly format code from a jedi.Script definition. This function gets the code for a definition and optionally adds line numbers to it. Args: definition (jedi.Script): The jedi.Script instance where the code lives. verbose (bool, optional): If true, line num

(definition: jedi.Script, verbose: bool=False)

Source from the content-addressed store, hash-verified

46 raise NotImplementedError(f"Language {language} is not supported yet")
47
48def get_code_jedi(definition: jedi.Script, verbose: bool=False) -> str:
49 """
50 Fetch and possibly format code from a jedi.Script definition.
51
52 This function gets the code for a definition and optionally adds line numbers to it.
53
54 Args:
55 definition (jedi.Script): The jedi.Script instance where the code lives.
56 verbose (bool, optional): If true, line numbers are appended before each code line. Defaults to False.
57
58 Returns:
59 str: The raw or line-numbered code as a string.
60 """
61 raw = definition.get_line_code(after=definition.get_definition_end_position()[0]-definition.get_definition_start_position()[0])
62 start_num_line = definition.get_definition_start_position()[0] - 2 # jedi start from 1
63 if not verbose:
64 return raw
65 else:
66 results = []
67 splited_raw = raw.split("\n")
68 for _, line in enumerate(splited_raw):
69 new_line = str(start_num_line + 1) + " " + line
70 results.append(new_line)
71 start_num_line += 1
72 return "\n".join(results)
73
74def search_py_elements_inside_project(names, backend, num_result=3, verbose=False):
75 """Get all matched identifiers from a repo

Callers 1

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected