Buckets:

download
raw
3.28 kB
from abc import ABC, abstractmethod
from pathlib import Path
from typing import TYPE_CHECKING, Iterable
from typing_extensions import NotRequired, TypedDict
if TYPE_CHECKING:
from mcp_server.core.repo_context import RepoContext
class IndexShard(TypedDict):
file: str
symbols: list[dict]
language: str
chunks: NotRequired[list[dict]]
metadata: NotRequired[dict]
class Reference:
"""A reference to a symbol occurrence in a file."""
__slots__ = ("file", "start_line", "end_line")
def __init__(
self,
file: str,
start_line: int = 0,
end_line: int = 0,
*,
line: int | None = None,
) -> None:
object.__setattr__(self, "file", file)
if line is not None:
object.__setattr__(self, "start_line", line)
object.__setattr__(self, "end_line", line)
else:
object.__setattr__(self, "start_line", start_line)
object.__setattr__(self, "end_line", end_line)
def __setattr__(self, name, value):
raise AttributeError("Reference is immutable")
def __eq__(self, other):
if not isinstance(other, Reference):
return NotImplemented
return (
self.file == other.file
and self.start_line == other.start_line
and self.end_line == other.end_line
)
def __hash__(self):
return hash((self.file, self.start_line, self.end_line))
def __repr__(self):
return (
f"Reference(file={self.file!r}, start_line={self.start_line}, end_line={self.end_line})"
)
class SymbolDef(TypedDict):
symbol: str
kind: str
language: str
signature: str
doc: str | None
defined_in: str
start_line: int
end_line: int
span: tuple[int, int]
class SearchResult(TypedDict):
file: str
start_line: int
end_line: int
snippet: str
class SearchOpts(TypedDict, total=False):
semantic: bool
limit: int
source_type: str
friction_categories: list[str]
history_labels: list[str]
history_repos: list[str]
include_source_metadata: bool
class IPlugin(ABC):
lang: str
@property
def language(self) -> str:
"""Return the language identifier."""
return self.lang
def bind(self, ctx: "RepoContext") -> None: # type: ignore[name-defined]
"""P3 IF-0-P3-3: attach a RepoContext to this plugin instance.
Default no-op. Plugins that need per-repo state (store, cache, etc.)
override this; ``PluginFactory.create_plugin`` calls it post-construction
iff the caller passed a context. Kept as a method rather than a
constructor change so legacy fixtures that build plugins with no args
keep working.
"""
return None
@abstractmethod
def supports(self, path: str | Path) -> bool: ...
@abstractmethod
def indexFile(self, path: str | Path, content: str) -> IndexShard: ...
@abstractmethod
def getDefinition(self, symbol: str) -> SymbolDef | None: ...
@abstractmethod
def findReferences(self, symbol: str) -> Iterable[Reference]: ...
@abstractmethod
def search(self, query: str, opts: SearchOpts | None = None) -> Iterable[SearchResult]: ...

Xet Storage Details

Size:
3.28 kB
·
Xet hash:
920b5b32565e4a9dd039871082c83a788a0a51830be81cc1e4d2fa73d693f3a2

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.