Expand description
Main DI container struct.
§MountainEnvironment (Environment)
The primary dependency injection (DI) container for the Mountain application. It implements all provider traits defined in the Common crate, acting as the central orchestrator that provides access to all platform services.
§RESPONSIBILITIES
§1. Dependency Injection Container
- Implements
Requires<T>for all 25+ provider traits via macro - Enable other components to request dependencies through
Require()method - Provide lazy initialization with proper lifetime management
- Support circular dependencies via
Arc-wrapped self-references
§2. Application Lifecycle Management
- Hold references to Tauri
AppHandleandApplicationState - Manage the core application context and state
- Coordinate initialization sequence for all providers
- Support graceful shutdown and cleanup
§3. Air Integration (Optional)
- Manage the Air gRPC client for cloud-based services when
AirIntegrationfeature enabled - Enable dynamic switching between local and cloud services
- Provide health checking for Air daemon availability
- Support fallback to local services when Air unavailable
§4. Extension Management
- Implement
ExtensionManagementServicefor discovering extensions - Scan registered paths for valid extensions
- Manage extension metadata in
ApplicationState - Provide extension list to extension host (Cocoon)
§5. Service Orchestration
- Act as central coordinator between all providers (FileSystem, Document, Command, etc.)
- Ensure proper initialization order and dependency resolution
- Facilitate inter-provider communication via IPC or direct calls
- Provide capability resolution through
Requires<T>trait
§ARCHITECTURAL ROLE
MountainEnvironment is the central DI container and service locator for the entire application:
Component ──► Requires<T> ──► MountainEnvironment ──► Arc<dyn T>§Position in Mountain
Environmentmodule: Root of the dependency injection system- Implements Common crate’s
EnvironmentandRequirestraits - All providers accessed through capability-based lookups
- Created early in startup and shared via
Arc<MountainEnvironment>
§Dependencies (Incoming)
CommonLibrary::*provider traits (25+ interfaces)tauri::AppHandle: UI and platform integrationApplicationState: Shared application stateAirServiceClient(optional): Cloud service integration
§Dependents (Outgoing)
- All command handlers: Require capabilities from environment
ApplicationRunTime: Uses environment for effect execution- Provider implementations: self-referencing via
Arc<dyn Trait> InitializationData: Uses environment to gather extensions and workspace data
§DEPENDENCY INJECTION PATTERN
Mountain uses a service locator pattern with trait-based lookup:
impl Requires<dyn FileSystemReader> for MountainEnvironment {
fn Require(&self) -> Arc<dyn FileSystemReader> {
Arc::new(self.clone()) // Self implements FileSystemReader
}
}This enables:
- Loose coupling: Components depend on traits, not concrete types
- Circular dependencies: All providers can require each other through Environment
- Testability: Environment can be mocked or stubbed for tests
- Flexibility: New providers added without changing dependents
§INITIALIZATION SEQUENCE
- Create Environment:
MountainEnvironment::Create(app_handle, app_state) - Provider Instantiation: Lazy through
Requires<T>trait calls - State Access: Each provider can access
ApplicationStateandAppHandlevia self - Inter-Provider Communication: Via trait methods (direct Rust calls) or IPC
Note: Provider implementations are separate modules in Environment/
directory. Each module implements a specific trait and can be
included/excluded via feature flags.
§AIR INTEGRATION
When AirIntegration feature is enabled:
AirClientfield isOption<Arc<AirServiceClient<tonic::transport::Channel>>>CreateWithAir()allows passing pre-configured Air clientSetAirClient()allows dynamic switching at runtimeIsAirAvailable()performs health check on Air daemon- Providers like
SecretProviderandUpdateServicecan delegate to Air
When feature is disabled:
AirClientfield is absentIsAirAvailable()always returnsfalse- Local-only service implementations are used
§VS CODE REFERENCE
Patterns borrowed from VS Code’s service architecture:
vs/platform/instantiation/common/instantiation.ts- Service collection and instantiationvs/platform/workspace/common/workspace.ts- Service locator patternvs/workbench/services/extensions/common/extensions.ts- Extension point management
Key concepts:
- Service lifetime management through
Arcreference counting - Trait-based service definitions for loose coupling
- Lazy initialization on first use
- Thread-safe service access
§PROVIDER TRAITS IMPLEMENTED
The following 25+ provider traits are implemented using the
impl_provider! macro:
CommandExecutor- Execute commands and actionsConfigurationProvider- Access application configurationConfigurationInspector- Inspect configuration valuesCustomEditorProvider- Custom document editor supportDebugService- Debug adapter protocol integrationDiagnosticManager- Diagnostic/lint/error managementDocumentProvider- Document lifecycle and content accessFileSystemReader/FileSystemWriter- File system operationsIPCProvider- Inter-process communicationKeybindingProvider- Keybinding resolution and executionLanguageFeatureProviderRegistry- LSP and language featuresOutputChannelManager- Output panel channel managementSecretProvider- Credential and secret storageSourceControlManagementProvider- Git/SCM integrationStatusBarProvider- Status bar item managementStorageProvider- Key-value storageSynchronizationProvider- Remote sync and collaborationTerminalProvider- Integrated terminal managementTestController- Test discovery and executionTreeViewProvider- Tree view UI componentsUserInterfaceProvider- UI dialog and interaction servicesWebviewProvider- Webview panel managementWorkspaceProvider- Workspace and folder managementWorkspaceEditApplier- Workspace edit application (text changes)ExtensionManagementService- Extension scanning and metadataSearchProvider- Search and replace functionality
§TODO
- Add telemetry integration for performance monitoring
- Implement proper provider health checking
- Add provider dependency validation on initialization
- Consider async initialization for providers
- Add circuit breaker pattern for external service calls (Air)
- Implement graceful degradation when providers fail
- Add metrics collection for provider usage
- Consider provider initialization order dependencies
Structs§
- Mountain
Environment - The concrete
Environmentfor the Mountain application.