Expand description
ยงWorkspaceProvider (Environment)
RESPONSIBILITIES:
- Implements
WorkspaceProviderandWorkspaceEditAppliertraits forMountainEnvironment - 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
ApplicationStatefor persistent workspace folder storage
ERROR HANDLING:
- Uses
CommonErrorfor all operations - Application state lock errors are mapped using
Utility::ErrorMapping::MapApplicationStateLockErrorToCommonError - Some operations are stubbed with logging (FindFilesInWorkspace, OpenFile, ApplyWorkspaceEdit)
PERFORMANCE:
- Workspace folder lookup uses O(n) linear search through folder list
- Lock contention on
ApplicationState.Workspace.WorkspaceFoldersshould be minimized - File discovery and workspace edit application are not yet optimized
VS CODE REFERENCE:
vs/workbench/services/workspace/browser/workspaceService.ts- workspace service implementationvs/workbench/contrib/files/common/editors/textFileEditor.ts- file editor integrationvs/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:
WorkspaceProviderimplementation:GetWorkspaceFoldersInfo- enumerate all workspace foldersGetWorkspaceFolderInfo- find folder containing a URIGetWorkspaceName- workspace identifier from stateGetWorkspaceConfigurationPath- .code-workspace pathIsWorkspaceTrusted- trust status checkRequestWorkspaceTrust- trust acquisition (stub)FindFilesInWorkspace- file discovery (stub)OpenFile- file opening (stub)WorkspaceEditApplierimplementation:ApplyWorkspaceEdit- edit application (stub)- Data types: [
(Url, String, usize)] tuple for folder info (URI, name, index)
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.