Skip to content

Commit e10a5c0

Browse files
fix(Mountain): Add inline workspace folders to extension host init data
Add `folders` array directly to the WorkspaceDTO in InitData so extensions that read `vscode.workspace.workspaceFolders` synchronously in their `activate()` (vscode.git, eamodio.gitlens, typescript) see the real folders immediately instead of `[]` until a delta fires. Cocoon's `WorkspaceNamespace/Index.ts` reads this at shim construction time, so the folders must be present in the initial payload. Also add `configuration` field to pass the workspace config path, and change CWD-autoload default to ON in debug builds (OFF in release). Debug builds need folders for `vscode.git` / `eamodio.gitlens` to scan repositories and surface tree-views, while release keeps the stock VS Code UX. Override with `LAND_AUTOLOAD_CWD=0` or `=1`.
1 parent 26891b3 commit e10a5c0

2 files changed

Lines changed: 40 additions & 8 deletions

File tree

Source/Binary/Initialize/CliParse.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,24 @@ pub fn ParseWorkspaceFolders() -> Vec<PathBuf> {
103103
}
104104

105105
if Collected.is_empty() {
106-
// CWD-autoload is OPT-IN (set `LAND_AUTOLOAD_CWD=1`). VS Code's UX
107-
// convention is to open an empty window when no folder is given and
108-
// let the user pick via File → Open Folder; silently seeding CWD
109-
// caused the TypeScript extension's workspace scan to walk the
110-
// entire monorepo (node_modules included) during boot, stalling
111-
// the UI for minutes.
106+
// CWD-autoload default: ON in debug builds, OFF in release. Debug
107+
// iteration invariably needs a folder so `vscode.git` /
108+
// `eamodio.gitlens` can scan repositories, extensions can surface
109+
// tree-views, and `workspace.findFiles` returns something. Release
110+
// builds keep the stock VS Code "File → Open Folder" UX so users
111+
// don't get surprise filesystem scans. Either default is
112+
// overridable: `LAND_AUTOLOAD_CWD=0` disables, `LAND_AUTOLOAD_CWD=1`
113+
// enables.
114+
//
115+
// The earlier concern was that auto-seeding CWD from a mono-repo
116+
// root walked `node_modules` during TypeScript workspace scan and
117+
// stalled boot. That's still real in release but acceptable in
118+
// debug: developers running from their project root actually want
119+
// the scan.
120+
let DefaultAutoload = cfg!(debug_assertions);
112121
let AutoloadCwd = std::env::var("LAND_AUTOLOAD_CWD")
113-
.map(|Value| Value == "1" || Value == "true")
114-
.unwrap_or(false);
122+
.map(|Value| matches!(Value.as_str(), "1" | "true" | "yes" | "on"))
123+
.unwrap_or(DefaultAutoload);
115124
if AutoloadCwd {
116125
if let Ok(Cwd) = std::env::current_dir() {
117126
Collected.push(Cwd);

Source/ProcessManagement/InitializationData.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,27 @@ pub async fn ConstructExtensionHostInitializationData(Environment:&MountainEnvir
344344

345345
let WorkspaceFoldersGuard = ApplicationState.Workspace.WorkspaceFolders.lock().unwrap();
346346

347+
// Cocoon's `WorkspaceNamespace/Index.ts` reads
348+
// `ExtensionHostInitData.workspace.folders` at shim construction time,
349+
// then mutates the same array in place on `$deltaWorkspaceFolders`. If
350+
// `folders` is missing from the init payload, every
351+
// `vscode.workspace.workspaceFolders` read returns `[]` until a delta
352+
// fires - which means the git extension boots with zero folders to
353+
// scan and never calls `createSourceControl`. Emit the folder list
354+
// inline so extensions that read `workspaceFolders` synchronously in
355+
// their `activate()` (vscode.git, eamodio.gitlens, typescript) see
356+
// the real folders.
357+
let FoldersWire:Vec<Value> = WorkspaceFoldersGuard
358+
.iter()
359+
.map(|Folder| {
360+
json!({
361+
"uri": Folder.URI.to_string(),
362+
"name": Folder.GetDisplayName(),
363+
"index": Folder.Index,
364+
})
365+
})
366+
.collect();
367+
347368
let WorkspaceDTO = if WorkspaceFoldersGuard.is_empty() {
348369
Value::Null
349370
} else {
@@ -353,6 +374,8 @@ pub async fn ConstructExtensionHostInitializationData(Environment:&MountainEnvir
353374

354375
"name": WorkspaceName,
355376

377+
"folders": FoldersWire,
378+
356379
"configuration": ApplicationState.Workspace.WorkspaceConfigurationPath.lock().unwrap().as_ref().map(|p| p.to_string_lossy()),
357380

358381
"isUntitled": ApplicationState.Workspace.WorkspaceConfigurationPath.lock().unwrap().is_none(),

0 commit comments

Comments
 (0)