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
8 changes: 3 additions & 5 deletions src/cocoindex_code/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from cocoindex.resources.id import IdGenerator

from .settings import PROJECT_SETTINGS
from .shared import CODEBASE_DIR, EMBEDDER, SQLITE_DB, CodeChunk
from .shared import CODEBASE_DIR, EMBEDDER, EXT_LANG_OVERRIDE_MAP, SQLITE_DB, CodeChunk

# Chunking configuration
CHUNK_SIZE = 2000
Expand All @@ -28,7 +28,6 @@ async def process_file(
table: sqlite.TableTarget[CodeChunk],
) -> None:
"""Process a single file: chunk, embed, and store."""
ps = coco.use_context(PROJECT_SETTINGS)
embedder = coco.use_context(EMBEDDER)

try:
Expand All @@ -40,10 +39,9 @@ async def process_file(
return

suffix = file.file_path.path.suffix
# Check language overrides from project settings
override_map = {f".{lo.ext}": lo.lang for lo in ps.language_overrides}
ext_lang_override_map = coco.use_context(EXT_LANG_OVERRIDE_MAP)
language = (
override_map.get(suffix)
ext_lang_override_map.get(suffix)
or detect_code_language(filename=file.file_path.path.name)
or "text"
)
Expand Down
6 changes: 5 additions & 1 deletion src/cocoindex_code/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .indexer import indexer_main
from .protocol import IndexingProgress
from .settings import PROJECT_SETTINGS, ProjectSettings
from .shared import CODEBASE_DIR, EMBEDDER, SQLITE_DB, Embedder
from .shared import CODEBASE_DIR, EMBEDDER, EXT_LANG_OVERRIDE_MAP, SQLITE_DB, Embedder


class Project:
Expand Down Expand Up @@ -86,6 +86,10 @@ async def create(
context.provide(SQLITE_DB, sqlite.connect(str(target_sqlite_db_path), load_vec=True))
context.provide(EMBEDDER, embedder)
context.provide(PROJECT_SETTINGS, project_settings)
context.provide(
EXT_LANG_OVERRIDE_MAP,
{f".{lo.ext}": lo.lang for lo in project_settings.language_overrides},
)

env = coco.Environment(settings, context_provider=context)
app = coco.App(
Expand Down
1 change: 1 addition & 0 deletions src/cocoindex_code/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
EMBEDDER = coco.ContextKey[Embedder]("embedder")
SQLITE_DB = coco.ContextKey[sqlite.ManagedConnection]("index_db", tracked=False)
CODEBASE_DIR = coco.ContextKey[pathlib.Path]("codebase", tracked=False)
EXT_LANG_OVERRIDE_MAP = coco.ContextKey[dict[str, str]]("ext_lang_override_map")

# Module-level variable — set by daemon at startup (needed for CodeChunk annotation).
embedder: Embedder | None = None
Expand Down
Loading