Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion codetide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from codetide.core.common import readFile, writeFile
from codetide.core.logs import logger

from codetide.parsers.generic_parser import GenericParser
from codetide.parsers import BaseParser
from codetide import parsers

Expand Down Expand Up @@ -224,7 +225,7 @@ def _initialize_parsers(
"""Initialize parsers for all required languages."""
for language in languages:
if language not in self._instantiated_parsers:
parser_obj = getattr(parsers, self.parserId(language), None)
parser_obj = getattr(parsers, self.parserId(language), GenericParser)
if parser_obj is not None:
self._instantiated_parsers[language] = parser_obj()
logger.debug(f"Initialized parser for {language}")
Expand Down
10 changes: 6 additions & 4 deletions codetide/parsers/generic_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ..core.models import CodeBase, CodeFileModel, ImportStatement
from ..parsers.base_parser import BaseParser
from ..core.common import readFile

from concurrent.futures import ThreadPoolExecutor
from typing import List, Optional, Union
Expand Down Expand Up @@ -45,17 +46,18 @@ async def parse_file(self, file_path: Union[str, Path], root_path: Optional[Unio
# Use aiofiles or run synchronous file IO in executor
loop = asyncio.get_running_loop()
with ThreadPoolExecutor() as pool:

code = await loop.run_in_executor(pool, readFile, file_path, "rb")
if root_path is not None:
file_path = file_path.relative_to(Path(root_path))

codeFile = await loop.run_in_executor(pool, self.parse_code, file_path)
codeFile = await loop.run_in_executor(pool, self.parse_code, file_path, code)

return codeFile

def parse_code(self, file_path :Path):
def parse_code(self, file_path :Path, code :str):
codeFile = CodeFileModel(
file_path=str(file_path)
file_path=str(file_path),
raw=code
)
return codeFile

Expand Down
Loading