Expand description
§DiagnosticProvider (Environment)
Implements the DiagnosticManager trait, managing diagnostic information
from multiple sources (language servers, extensions, built-in providers). It
aggregates diagnostics by owner, file URI, and severity, notifying the UI
when changes occur.
§RESPONSIBILITIES
§1. Diagnostic Collection
- Maintain collections of diagnostics organized by owner (TypeScript, Rust, ESLint)
- Store diagnostics per resource URI for efficient lookup
- Support multiple severity levels (Error, Warning, Info, Hint)
- Track diagnostic source and code for quick fixes
§2. Diagnostic Aggregation
- Combine diagnostics from multiple sources into unified view
- Merge diagnostics for same location from different owners
- Sort diagnostics by severity and position
- De-duplicate identical diagnostics
§3. Change Notification
- Emit events to UI (Sky) when diagnostics change
- Identify changed URIs efficiently for incremental updates
- Format diagnostic collections for IPC transmission
- Support diagnostic refresh requests
§4. Owner Management
- Allow independent language servers to manage their diagnostics
- Support adding/removing diagnostic owners
- Prevent interference between different diagnostic sources
- Track owner metadata (name, version, etc.)
§5. Diagnostic Lifecycle
SetDiagnostics(owner, uri, entries): Set diagnostics for owner+URIClearDiagnostics(owner, uri): Remove diagnosticsRemoveOwner(owner): Remove all diagnostics from an ownerGetDiagnostics(uri): Retrieve all diagnostics for a URI
§ARCHITECTURAL ROLE
DiagnosticProvider is the diagnostic aggregation hub:
Language Server ──► SetDiagnostics ──► DiagnosticProvider ──► UI Event ──► Sky
Extension ──► SetDiagnostics ──► DiagnosticProvider ──► UI Event ──► Sky§Position in Mountain
Environmentmodule: Error and diagnostic management- Implements
CommonLibrary::Diagnostic::DiagnosticManagertrait - Accessible via
Environment.Require<dyn DiagnosticManager>()
§Data Storage
ApplicationState.Feature.Diagnostics: HashMap<String, HashMap<String,Vec<MarkerDataDTO>>>- Outer key: Owner (e.g., “typescript”, “rust-analyzer”)
- Inner key: URI string
- Value: Vector of diagnostic markers
§Dependencies
ApplicationState: Diagnostic storageLog: Diagnostic change loggingIPCProvider: To emit diagnostic change events
§Dependents
- Language servers: Report diagnostics via provider
DispatchLogic: Route diagnostic-related commands- UI components: Display diagnostics in editor
§DIAGNOSTIC DATA MODEL
Each diagnostic is a MarkerDataDTO:
Severity: Error(8), Warning(4), Information(2), Hint(1)Message: Human-readable descriptionStartLineNumber/StartColumn: Start position (0-based)EndLineNumber/EndColumn: End positionSource: Diagnostic source string (e.g., “tslint”)Code: Diagnostic code for quick fix lookupModelVersionIdentifier: Document version for tracking
§NOTIFICATION FLOW
- Language server calls
SetDiagnostics(owner, uri, entries) - Provider validates and stores in
ApplicationState.Feature.Diagnostics - Provider identifies which URIs changed in this update
- Provider emits
sky://diagnostics/changedevent with:owner: Diagnostic sourceuris: List of changed file URIs
- Sky receives event and requests updated diagnostics for those URIs
- Sky updates UI (squiggles, Problems panel, etc.)
§ERROR HANDLING
- Invalid owner/uri: Logged but operation continues
- Empty diagnostic list: Treated as “clear” operation
- Serialization errors: Logged and skipped
- State lock errors:
CommonError::StateLockPoisoned
§PERFORMANCE
- Diagnostic storage uses nested HashMaps for O(1) lookup
- Change detection compares old vs new URI sets
- Events are debounced to prevent spam (configurable)
- Large diagnostic sets may impact UI responsiveness (consider paging)
§VS CODE REFERENCE
Patterns from VS Code:
vs/workbench/services/diagnostic/common/diagnosticCollection.ts- Collection managementvs/platform/diagnostics/common/diagnostics.ts- Diagnostic data modelvs/workbench/services/diagnostic/common/diagnosticService.ts- Aggregation and events
§TODO
- Implement diagnostic severity filtering (hide certain levels)
- Add diagnostic code actions/quick fixes integration
- Support diagnostic inline messages and hover
- Implement diagnostic history and undo/redo
- Add diagnostic export (to file, clipboard)
- Support diagnostic linting and rule configuration
- Implement diagnostic suppression comments
- Add diagnostic telemetry (frequency, severity distribution)
- Support remote diagnostics (from cloud services)
- Implement diagnostic caching for offline scenarios
§MODULE CONTENTS
DiagnosticProvider: Main struct implementingDiagnosticManager- Diagnostic storage and retrieval methods
- Change notification and event emission
- Owner management functions
- Diagnostic validation helpers