Spaces:
Sleeping
Sleeping
| from typing import Dict, List | |
| from .ast_parser import PythonASTParser | |
| from .graph import DependencyGraph | |
| class WorkspaceIndexer: | |
| """Orchestrates AST parsing, symbol indexing, and workspace search.""" | |
| def __init__(self): | |
| self.parser = PythonASTParser() | |
| self.graph = DependencyGraph() | |
| self.symbol_index: Dict[str, List[str]] = {} | |
| def index_file(self, filepath: str, source_code: str): | |
| # Parse abstract syntax tree | |
| symbols = self.parser.parse(source_code) | |
| # Populate symbol index | |
| self.symbol_index[filepath] = symbols.get("classes", []) + symbols.get("functions", []) | |
| # Populate dependency graph via imports | |
| self.graph.add_node(filepath) | |
| for imp in symbols.get("imports", []): | |
| self.graph.add_edge(filepath, imp) | |
| def search_symbols(self, query: str) -> List[str]: | |
| """Basic workspace search for symbols.""" | |
| results = [] | |
| for filepath, syms in self.symbol_index.items(): | |
| if any(query.lower() in sym.lower() for sym in syms): | |
| results.append(filepath) | |
| return results | |