Module CreateEffectForRequest

Module CreateEffectForRequest 

Source
Expand description

§CreateEffectForRequest (Track)

§RESPONSIBILITIES

This module provides the central routing table that maps string-based commands/RPC methods to typed effects. It creates MappedEffect (type-erased async closures) for dispatch execution and integrates with the effect system (ActionEffect) and provider traits. Some operations use direct provider calls for performance.

§Core Functions:

  • Map string-based method names to effect constructors
  • Create MappedEffect (boxed closures) for execution
  • Support direct provider calls for hot paths
  • Handle parameter deserialization and validation

§ARCHITECTURAL ROLE

CreateEffectForRequest acts as the effect mapper in Track’s dispatch system:

Dispatch Logic ──► CreateEffectForRequest (Match) ──► MappedEffect ──► ApplicationRunTime Execution

§KEY COMPONENTS

  • Fn: Main effect creation function (pub fn Fn<R:Runtime>)
  • MappedEffect: Type alias for boxed async closure (imported from MappedEffect module)

§ERROR HANDLING

  • All effects return Result<Value, String> (serializable errors for IPC)
  • Parameter validation with descriptive error messages
  • Unknown command handling returns error instead of panic
  • Serialization/deserialization errors caught and reported
  • Provider errors propagate with context

§LOGGING

§PERFORMANCE CONSIDERATIONS

  • Effect creation is cheap: match + constructor call + box
  • Direct provider calls avoid allocation (for hot paths)
  • TODO: Consider implementing an effect pool to cache frequently created effects
  • TODO: Add configurable command timeouts per command type and rate limiting

§DIRECT PROVIDER CALLS

Some operations bypass the effect system for performance:

  • Configuration: GetConfiguration, UpdateConfiguration
  • Diagnostics: SetDiagnostics, ClearDiagnostics
  • Language Features: ProvideHover, ProvideCompletions, etc.
  • Terminal: direct text send/receive
  • Why? Avoid effect overhead for high-frequency operations

§SUPPORTED COMMAND CATEGORIES

Commands: Execute, GetAll, Register Configuration: Inspect, Update Documents: Save, SaveAs FileSystem: ReadFile, WriteFile, ReadDirectory Debug: Start, RegisterConfigurationProvider Diagnostics: Set, Clear Keybinding: GetResolved LanguageFeatures: $languageFeatures:registerProvider Search: TextSearch SourceControlManagement: $scm:createSourceControl, updateSourceControl, updateGroup, registerInputBox StatusBar: $statusBar:set, dispose, $setStatusBarMessage, $disposeStatusBarMessage Storage: Get, Set Terminal: $terminal:create, sendText, dispose TreeView: $tree:register UserInterface: ShowMessage, ShowOpenDialog, ShowSaveDialog Webview: $webview:create, $resolveCustomEditor

§TODO

High Priority:

  • Add command parameter schema validation (JSON schema per command)
  • Implement command permission checking (capability-based security)
  • Add command deprecation warnings and migration
  • Cache frequently created effects (reuse boxed closures)
  • Add command timeout configuration (per-command TTL)
  • Implement command rate limiting (DoS protection)
  • Add command metrics collection (latency, success rate)

Medium Priority:

  • Implement command aliasing (user-defined shortcuts)
  • Add command migration support (rename, deprecate)
  • Add comprehensive command audit logging
  • Support command chaining and composition
  • Implement command undo/redo integration
  • Split CreateEffectForRequest into individual effect modules

Low Priority:

  • Add request tracing across the entire pipeline

Functions§

CreateEffectForRequest
Maps a string-based method name (command or RPC) to its corresponding effect constructor, returning a boxed closure (MappedEffect) that can be executed by the ApplicationRunTime.