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

Function get_symbol_verbose

src/hyperagent/utils.py:410–435  ·  view source on GitHub ↗
(file_path: str, parent_path: str, keyword: str = None)

Source from the content-addressed store, hash-verified

408 return out_file_symbols
409
410def get_symbol_verbose(file_path: str, parent_path: str, keyword: str = None):
411 primary_symbols = [SymbolKind.Class, SymbolKind.Method, SymbolKind.Function, SymbolKind.Interface]
412 with open(file_path, 'r+') as f:
413 try:
414 if not f.read().endswith('\n'):
415 f.write('\n')
416 out_file_symbols = get_symbol_per_file(file_path, primary_symbols, parent_path, keyword)
417 out_str = ""
418 out_str += f"Symbols in {file_path.replace(parent_path, '')}\n"
419 num_line_per_symbol = [symbol["range"]["end_line"] - symbol["range"]["start_line"] for symbol in out_file_symbols]
420 if len(out_file_symbols) == 0:
421 return "No symbol found in this file."
422
423 if len(out_file_symbols) >= 3 or max(num_line_per_symbol) > 35:
424 out_str += "Name StartLine EndLine\n"
425 for symbol in out_file_symbols:
426 out_str += f"{symbol['name']} {symbol['range']['start_line']} {symbol['range']['end_line']}\n"
427 else:
428 out_str += "Name StartLine EndLine Definition\n"
429 for symbol in out_file_symbols:
430 out_str += f"{symbol['name']} {symbol['range']['start_line']} {symbol['range']['end_line']} \n{symbol['definition']}\n"
431
432 return out_str
433 except UnicodeDecodeError:
434 print(f"Error in reading file {file_path}")
435 return f"Error in reading file {file_path}"
436
437def setup_logger():
438 class CustomFormatter(logging.Formatter):

Callers 1

_runMethod · 0.90

Calls 2

get_symbol_per_fileFunction · 0.85
replaceMethod · 0.80

Tested by

no test coverage detected