Skip to main content

Module WorkspaceProvider

Module WorkspaceProvider 

Source
Expand description

WorkspaceProvider: exposes workspace folders, trust state, and edits.

ยงWorkspaceProvider (Environment)

Implements WorkspaceProvider and [WorkspaceEditApplier] traits for MountainEnvironment, exposing workspace-level functionality to the frontend via gRPC through AirService.

ยงResponsibilities

  • Multi-root workspace folder enumeration and URI matching
  • Workspace trust management (IsWorkspaceTrusted / RequestWorkspaceTrust)
  • File discovery (FindFilesInWorkspace) with LRU cache + single-flight dedup (see inline doc on that method)
  • Workspace edit application - two-tier: emit Sky event for open documents; atomic on-disk splice for closed files

ยงVS Code reference

  • vs/workbench/services/workspace/browser/workspaceService.ts
  • vs/platform/workspace/common/workspace.ts

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.