Skip to main content

Module WorkspaceProvider

Module WorkspaceProvider 

Source
Expand description

ยงWorkspaceProvider (Environment)

RESPONSIBILITIES:

  • Implements WorkspaceProvider and WorkspaceEditApplier traits for MountainEnvironment
  • Manages multi-root workspace folder operations and configuration
  • Provides workspace trust management and file discovery capabilities
  • Handles workspace edit application and custom editor routing

ARCHITECTURAL ROLE:

  • Core provider in the Environment system, exposing workspace-level functionality to frontend via gRPC through the AirService
  • Workspace provider is one of the foundational services alongside Document, Configuration, and Diagnostic providers
  • Integrates with ApplicationState for persistent workspace folder storage

ERROR HANDLING:

PERFORMANCE:

  • Workspace folder lookup uses O(n) linear search through folder list
  • Lock contention on ApplicationState.Workspace.WorkspaceFolders should be minimized
  • File discovery and workspace edit application are not yet optimized

VS CODE REFERENCE:

  • vs/workbench/services/workspace/browser/workspaceService.ts - workspace service implementation
  • vs/workbench/contrib/files/common/editors/textFileEditor.ts - file editor integration
  • vs/platform/workspace/common/workspace.ts - workspace types and interfaces

TODO:

  • Implement actual file search with glob pattern matching
  • Implement file opening with workspace-relative paths
  • Complete workspace edit application logic
  • Add workspace event propagation to subscribers
  • Implement custom editor routing by view type

MODULE CONTENTS:

  • WorkspaceProvider implementation:
  • GetWorkspaceFoldersInfo - enumerate all workspace folders
  • GetWorkspaceFolderInfo - find folder containing a URI
  • GetWorkspaceName - workspace identifier from state
  • GetWorkspaceConfigurationPath - .code-workspace path
  • IsWorkspaceTrusted - trust status check
  • RequestWorkspaceTrust - trust acquisition (stub)
  • FindFilesInWorkspace - file discovery (stub)
  • OpenFile - file opening (stub)
  • WorkspaceEditApplier implementation:
  • ApplyWorkspaceEdit - edit application (stub)
  • Data types: [(Url, String, usize)] tuple for folder info (URI, name, index)

Structsยง

FindFilesCacheEntry ๐Ÿ”’
FindFilesCacheKey ๐Ÿ”’

Constantsยง

FIND_FILES_CACHE_CAPACITY ๐Ÿ”’
FIND_FILES_CACHE_TTL ๐Ÿ”’
Process-wide LRU cache for FindFilesInWorkspace. Cache key folds every input that influences the walk; TTL is short so we never serve a stale result after a file-system mutation. Entry budget is small to bound memory across many workspace folders + glob shapes.

Functionsยง

ApplyEditsToDisk ๐Ÿ”’
Splice a list of TextEditDTO-shaped edits into the file at UriString. Edits are applied in descending start offset so each subsequent editโ€™s offsets stay valid. Errors propagate as CommonError::FromStandardIOError for read/write failures and CommonError::InvalidArgument for malformed edits.
ClearFindFilesCache
Drop every cached find-files result. Callers: workspace folder add/remove (UpdateWorkspaceFolders), file system watcher events from Mountainโ€™s notifier, explicit refresh from the renderer. Cache holds for at most FIND_FILES_CACHE_TTL anyway, so missing an invalidation point here is bounded latency, not correctness.
ComputeLineOffsets ๐Ÿ”’
Pre-compute the byte offset of the start of every line.
ExtractGlobPattern ๐Ÿ”’
Extract a glob string from any of the shapes a caller can hand us:
ExtractRelativeBase ๐Ÿ”’
Extract a base directory from a RelativePattern-shaped value. VS Codeโ€™s RelativePattern carries { base, pattern } (or { baseUri, pattern }); when present, the walk must be restricted to base. Returns None for plain glob strings.
FindFilesCache ๐Ÿ”’
FindFilesCacheGet ๐Ÿ”’
FindFilesCachePut ๐Ÿ”’
Insert into the cache with simple bounded-size eviction. When the table reaches capacity we drop the oldest half in one pass; this avoids tracking access order per entry while still keeping memory bounded under sustained workbench traffic.
FindFilesInFlight ๐Ÿ”’
Single-flight registry: keys with a walk currently in progress share the same Notify so concurrent callers awaiting the same (folders, include, exclude, cap, flags) donโ€™t each kick off their own filesystem walk.
HexDigit ๐Ÿ”’
LinePosToOffset ๐Ÿ”’
Resolve (line, character) to an absolute byte offset. Character is counted in UTF-16 code units to match VS Codeโ€™s Range/Position semantics. Falls back gracefully when line/char is past EOF.
percent_decode ๐Ÿ”’
Minimal percent-decode for file:// URI paths. Reuses the projectโ€™s existing helpers when possible; this self-contained version avoids an extra crate import.