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.tsvs/platform/workspace/common/workspace.ts
Structsยง
- Find
Files ๐Cache Entry - Find
Files ๐Cache Key
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ยง
- Apply
Edits ๐ToDisk - Splice a list of
TextEditDTO-shaped edits into the file atUriString. Edits are applied in descending start offset so each subsequent editโs offsets stay valid. Errors propagate asCommonError::FromStandardIOErrorfor read/write failures andCommonError::InvalidArgumentfor malformed edits. - Clear
Find Files Cache - 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 mostFIND_FILES_CACHE_TTLanyway, so missing an invalidation point here is bounded latency, not correctness. - Compute
Line ๐Offsets - Pre-compute the byte offset of the start of every line.
- Extract
Glob ๐Pattern - Extract a glob string from any of the shapes a caller can hand us:
- Extract
Relative ๐Base - Extract a
basedirectory from aRelativePattern-shaped value. VS CodeโsRelativePatterncarries{ base, pattern }(or{ baseUri, pattern }); when present, the walk must be restricted tobase. ReturnsNonefor plain glob strings. - Find
Files ๐Cache - Find
Files ๐Cache Get - Find
Files ๐Cache Put - 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.
- Find
Files ๐InFlight - Single-flight registry: keys with a walk currently in progress
share the same
Notifyso concurrent callers awaiting the same(folders, include, exclude, cap, flags)donโt each kick off their own filesystem walk. - HexDigit ๐
- Line
PosTo ๐Offset - Resolve
(line, character)to an absolute byte offset. Character is counted in UTF-16 code units to match VS CodeโsRange/Positionsemantics. 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.