Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /ViperJuice_Code-Index-MCP /mcp_server /interfaces /plugin_interfaces.py
| """ | |
| Plugin System Interfaces | |
| All interfaces related to the plugin system including plugin base interface, | |
| plugin management, discovery, loading, and lifecycle management. | |
| """ | |
| from abc import ABC, abstractmethod | |
| from dataclasses import dataclass, field | |
| from pathlib import Path | |
| from typing import Any, Dict, List, Optional | |
| from .shared_interfaces import IObservable, PluginStatus, Result | |
| # ======================================== | |
| # Plugin Data Types | |
| # ======================================== | |
| class SymbolDefinition: | |
| """Symbol definition information""" | |
| symbol: str | |
| file_path: str | |
| start_line: int | |
| end_line: int | |
| column: int | |
| symbol_type: str # function, class, variable, etc. | |
| signature: Optional[str] = None | |
| docstring: Optional[str] = None | |
| scope: Optional[str] = None | |
| class SymbolReference: | |
| """Symbol reference information""" | |
| symbol: str | |
| file_path: str | |
| start_line: int | |
| end_line: int | |
| column: int | |
| context: Optional[str] = None | |
| class SearchResult: | |
| """Search result information""" | |
| file_path: str | |
| start_line: int | |
| end_line: int | |
| column: int | |
| snippet: str | |
| match_type: str # exact, fuzzy, semantic | |
| score: float | |
| context: Optional[str] = None | |
| class IndexedFile: | |
| """Information about an indexed file""" | |
| file_path: str | |
| last_modified: float | |
| size: int | |
| symbols: List[SymbolDefinition] | |
| language: str | |
| encoding: str = "utf-8" | |
| class PluginMetadata: | |
| """Plugin metadata information""" | |
| name: str | |
| version: str | |
| description: str | |
| author: str | |
| supported_extensions: List[str] | |
| supported_languages: List[str] | |
| dependencies: List[str] = field(default_factory=list) | |
| entry_point: str = "plugin.py" | |
| config_schema: Optional[Dict[str, Any]] = None | |
| class PluginRuntimeInfo: | |
| """Stable runtime status shared across plugin managers and status endpoints.""" | |
| name: str | |
| status: PluginStatus | |
| enabled: bool | |
| version: Optional[str] = None | |
| language: Optional[str] = None | |
| error: Optional[str] = None | |
| # ======================================== | |
| # Core Plugin Interface | |
| # ======================================== | |
| class IPlugin(ABC): | |
| """Base interface that all language plugins must implement""" | |
| def name(self) -> str: | |
| """Get the plugin name""" | |
| def supported_extensions(self) -> List[str]: | |
| """Get list of file extensions this plugin supports""" | |
| def supported_languages(self) -> List[str]: | |
| """Get list of programming languages this plugin supports""" | |
| def can_handle(self, file_path: str) -> bool: | |
| """Check if this plugin can handle the given file""" | |
| def index(self, file_path: str, content: Optional[str] = None) -> Result[IndexedFile]: | |
| """Index a file and extract symbols""" | |
| def get_definition( | |
| self, symbol: str, context: Dict[str, Any] | |
| ) -> Result[Optional[SymbolDefinition]]: | |
| """Get the definition of a symbol""" | |
| def get_references(self, symbol: str, context: Dict[str, Any]) -> Result[List[SymbolReference]]: | |
| """Get all references to a symbol""" | |
| def search(self, query: str, options: Dict[str, Any]) -> Result[List[SearchResult]]: | |
| """Search for code patterns""" | |
| def validate_syntax(self, content: str) -> Result[bool]: | |
| """Validate syntax of code content""" | |
| def get_completions(self, file_path: str, line: int, column: int) -> Result[List[str]]: | |
| """Get code completions at a position""" | |
| class ILanguageAnalyzer(ABC): | |
| """Interface for language-specific analysis capabilities""" | |
| def parse_imports(self, content: str) -> Result[List[str]]: | |
| """Parse import statements from content""" | |
| def extract_symbols(self, content: str) -> Result[List[SymbolDefinition]]: | |
| """Extract all symbols from content""" | |
| def resolve_type(self, symbol: str, context: Dict[str, Any]) -> Result[Optional[str]]: | |
| """Resolve the type of a symbol""" | |
| def get_call_hierarchy( | |
| self, symbol: str, context: Dict[str, Any] | |
| ) -> Result[Dict[str, List[str]]]: | |
| """Get call hierarchy for a symbol""" | |
| # ======================================== | |
| # Plugin Management Interfaces | |
| # ======================================== | |
| class IPluginRegistry(ABC): | |
| """Interface for plugin registry operations""" | |
| def register(self, plugin: IPlugin, metadata: PluginMetadata) -> Result[None]: | |
| """Register a plugin""" | |
| def unregister(self, plugin_name: str) -> Result[None]: | |
| """Unregister a plugin""" | |
| def get_plugin(self, plugin_name: str) -> Optional[IPlugin]: | |
| """Get a plugin by name""" | |
| def get_plugins_for_extension(self, extension: str) -> List[IPlugin]: | |
| """Get all plugins that support a file extension""" | |
| def get_plugins_for_language(self, language: str) -> List[IPlugin]: | |
| """Get all plugins that support a language""" | |
| def list_plugins(self) -> List[str]: | |
| """List all registered plugin names""" | |
| def get_metadata(self, plugin_name: str) -> Optional[PluginMetadata]: | |
| """Get metadata for a plugin""" | |
| class IPluginDiscovery(ABC): | |
| """Interface for discovering available plugins""" | |
| def discover_plugins(self, search_paths: List[str | Path]) -> Result[List[PluginMetadata]]: | |
| """Discover plugins in the given search paths""" | |
| def scan_directory(self, directory: str | Path) -> Result[List[PluginMetadata]]: | |
| """Scan a directory for plugins""" | |
| def validate_plugin(self, plugin_path: str | Path) -> Result[bool]: | |
| """Validate a plugin path before loading it""" | |
| class IPluginLoader(ABC): | |
| """Interface for loading and unloading plugins""" | |
| def load_plugin( | |
| self, plugin_path: str | Path, metadata: PluginMetadata | |
| ) -> Result[type[IPlugin]]: | |
| """Load a plugin class from the given path""" | |
| def unload_plugin(self, plugin_name: str) -> Result[None]: | |
| """Unload a plugin""" | |
| def reload_plugin(self, plugin_name: str) -> Result[None]: | |
| """Reload a plugin""" | |
| def is_loaded(self, plugin_name: str) -> bool: | |
| """Check if a plugin is loaded""" | |
| def get_load_errors(self, plugin_name: str) -> List[str]: | |
| """Get any load errors for a plugin""" | |
| class IPluginManager(IObservable): | |
| """Interface for overall plugin management""" | |
| def load_plugins(self, config_path: Optional[str | Path] = None) -> Result[List[str]]: | |
| """Discover, load, and optionally initialize configured plugins.""" | |
| def shutdown(self) -> Result[None]: | |
| """Shutdown the plugin manager and destroy active instances.""" | |
| def reload_plugin(self, plugin_name: str) -> Result[None]: | |
| """Reload a specific plugin.""" | |
| def enable_plugin(self, plugin_name: str) -> Result[None]: | |
| """Enable and initialize a plugin if configured.""" | |
| def disable_plugin(self, plugin_name: str) -> Result[None]: | |
| """Disable a plugin and stop any active instance.""" | |
| def get_plugin_by_language(self, language: str) -> Optional[IPlugin]: | |
| """Return an active plugin instance for a language.""" | |
| def get_plugin_for_file(self, file_path: str | Path) -> Optional[IPlugin]: | |
| """Return the best active plugin instance for a file path.""" | |
| def get_plugin_status(self) -> Dict[str, PluginRuntimeInfo]: | |
| """Return runtime status for all known plugins.""" | |
| def get_detailed_plugin_status(self) -> Dict[str, Dict[str, Any]]: | |
| """Return expanded runtime and configuration details for plugins.""" | |
| # ======================================== | |
| # Tree-sitter Integration Interfaces | |
| # ======================================== | |
| class ITreeSitterAdapter(ABC): | |
| """Interface for Tree-sitter parser integration""" | |
| def parse_content(self, content: str, language: str) -> Result[Any]: | |
| """Parse content using Tree-sitter""" | |
| def get_node_text(self, node: Any, content: str) -> str: | |
| """Get text content of a node""" | |
| def find_nodes_by_type(self, tree: Any, node_type: str) -> List[Any]: | |
| """Find all nodes of a specific type""" | |
| def get_node_position(self, node: Any) -> tuple[int, int]: | |
| """Get line and column position of a node""" | |
| def is_language_supported(self, language: str) -> bool: | |
| """Check if a language is supported""" | |
| # ======================================== | |
| # Language-Specific Plugin Interfaces | |
| # ======================================== | |
| class IPythonPlugin(IPlugin): | |
| """Interface specific to Python plugins""" | |
| def get_import_graph(self, file_path: str) -> Result[Dict[str, List[str]]]: | |
| """Get import dependency graph""" | |
| def resolve_module(self, module_name: str, context: Dict[str, Any]) -> Result[Optional[str]]: | |
| """Resolve a module to its file path""" | |
| class ICppPlugin(IPlugin): | |
| """Interface specific to C++ plugins""" | |
| def resolve_includes(self, file_path: str) -> Result[List[str]]: | |
| """Resolve #include directives""" | |
| def parse_templates(self, content: str) -> Result[List[SymbolDefinition]]: | |
| """Parse template definitions""" | |
| class IJavaScriptPlugin(IPlugin): | |
| """Interface specific to JavaScript/TypeScript plugins""" | |
| def parse_jsx(self, content: str) -> Result[List[SymbolDefinition]]: | |
| """Parse JSX components""" | |
| def resolve_modules(self, file_path: str) -> Result[Dict[str, str]]: | |
| """Resolve module imports""" | |
| class IDartPlugin(IPlugin): | |
| """Interface specific to Dart plugins""" | |
| def parse_flutter_widgets(self, content: str) -> Result[List[SymbolDefinition]]: | |
| """Parse Flutter widget definitions""" | |
| def resolve_packages(self, file_path: str) -> Result[List[str]]: | |
| """Resolve package dependencies""" | |
| class IHtmlCssPlugin(IPlugin): | |
| """Interface specific to HTML/CSS plugins""" | |
| def extract_selectors(self, css_content: str) -> Result[List[str]]: | |
| """Extract CSS selectors""" | |
| def find_css_usage(self, html_content: str) -> Result[List[str]]: | |
| """Find CSS class/ID usage in HTML""" | |
| class ICPlugin(IPlugin): | |
| """Interface specific to C plugins""" | |
| def parse_preprocessor(self, content: str) -> Result[List[str]]: | |
| """Parse preprocessor directives""" | |
| def resolve_headers(self, file_path: str) -> Result[List[str]]: | |
| """Resolve header file dependencies""" | |
Xet Storage Details
- Size:
- 11.6 kB
- Xet hash:
- 07e17392f2a3ad2fc00a468e60a20d2ff64f222e45d895264d9947688f0e202b
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.