| 12 | |
| 13 | |
| 14 | class ContextHelper: |
| 15 | def __init__(self, args: Namespace): |
| 16 | self._args = args |
| 17 | self._lsp: Optional[LanguageServer] = None |
| 18 | |
| 19 | @asynccontextmanager |
| 20 | async def start_server(self) -> AsyncIterator[LanguageServer]: |
| 21 | print("\nInitializing language server...") |
| 22 | self._lsp = await initialize_language_server(self._args) |
| 23 | async with self._lsp.start_server() as server: |
| 24 | yield server |
| 25 | |
| 26 | async def find_test_file_context(self, test_file: Path): |
| 27 | if not self._lsp: |
| 28 | raise ValueError( |
| 29 | "Language server not initialized. Please call start_server() first." |
| 30 | ) |
| 31 | context_files = await find_test_file_context(self._args, self._lsp, test_file) |
| 32 | return context_files |
| 33 | |
| 34 | async def analyze_context( |
| 35 | self, |
| 36 | test_file: Path, |
| 37 | context_files: List[Path], |
| 38 | ai_caller: AICaller, |
| 39 | ) -> Tuple[Path, List[Path]]: |
| 40 | if not self._lsp: |
| 41 | raise ValueError( |
| 42 | "Language server not initialized. Please call start_server() first." |
| 43 | ) |
| 44 | source_file, context_files_include = await analyze_context( |
| 45 | test_file, context_files, self._args, ai_caller |
| 46 | ) |
| 47 | return source_file, context_files_include |