(file_path: str, primary_symbols, parent_path, keyword)
| 383 | return F"No symbol {keyword} found in this file." |
| 384 | |
| 385 | def get_symbol_per_file(file_path: str, primary_symbols, parent_path, keyword): |
| 386 | out_file_symbols = [] |
| 387 | file_symbols = run_ctags(file_path) |
| 388 | primary_symbols = [int(symbol_kind) for symbol_kind in primary_symbols] |
| 389 | file_symbols = [symbol for symbol in file_symbols if symbol["kind"] in primary_symbols] |
| 390 | |
| 391 | for symbol in file_symbols: |
| 392 | symbol_definition = open(file_path, "r").readlines()[symbol["range"]["start_line"]-1:symbol["range"]["end_line"]] |
| 393 | symbol_definition = "".join(symbol_definition) |
| 394 | output_item = { |
| 395 | "name": symbol["name"], |
| 396 | "definition": add_num_line(symbol_definition, symbol["range"]["start_line"]), |
| 397 | "range": symbol["range"], |
| 398 | "path": file_path.replace(parent_path, ""), |
| 399 | } |
| 400 | if keyword is not None: |
| 401 | # if keyword exists, we prefer exact match over partial match to reduce false positives and redudant observation, otherwise we keep all partial matches. |
| 402 | condition = (keyword == symbol["name"]) if keyword in [s["name"] for s in file_symbols] else (keyword in symbol["name"]) |
| 403 | if condition: |
| 404 | out_file_symbols.append(output_item) |
| 405 | else: |
| 406 | out_file_symbols.append(output_item) |
| 407 | |
| 408 | return out_file_symbols |
| 409 | |
| 410 | def get_symbol_verbose(file_path: str, parent_path: str, keyword: str = None): |
| 411 | primary_symbols = [SymbolKind.Class, SymbolKind.Method, SymbolKind.Function, SymbolKind.Interface] |
no test coverage detected