Skip to content

Commit 1d948bb

Browse files
committed
feat(vscode): generate .code-workspace file
Add `obsidianVFS.workspaceFile` setting that generates a named <project>.code-workspace file containing the vault folder entry and existing workspace settings from .vscode/settings.json. Prompts the user to open it (one-time reload), then manages files.exclude patterns in the workspace file's settings section on subsequent activations. Assisted-by: Claude
1 parent 83a3f31 commit 1d948bb

8 files changed

Lines changed: 640 additions & 556 deletions

File tree

packages/vscode/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Browse, search, and edit your [Obsidian](https://obsidian.md) vault directly in
1919
- **Auto-mount** configured folders on startup
2020
- **Status bar** showing vault name and connection mode (`full` / `degraded`)
2121
- **Workspace folder**, vault browsable in Explorer with Quick Open (`Cmd+P`) and Search (`Ctrl+Shift+F`) support
22+
- **Workspace file**, generate a named `.code-workspace` to avoid the "Untitled Workspace" label
2223
- **File watching**, changes in the vault are reflected in real time
2324

2425
## Commands
@@ -47,6 +48,7 @@ Configure via **Settings UI** or `settings.json`:
4748
| `obsidianVFS.explorer` | `boolean` | `true` | Show the Obsidian VFS tree view in the Explorer sidebar |
4849
| `obsidianVFS.statusBar` | `boolean` | `true` | Show vault name and mode in the status bar |
4950
| `obsidianVFS.workspace` | `boolean` | `true` | Add the vault as a workspace folder for Quick Open and Search (see below) |
51+
| `obsidianVFS.workspaceFile` | `boolean` | `false` | Generate a `.code-workspace` file named after the project folder. Eliminates the "Untitled (Workspace)" label. The file contains a `file://` vault folder entry; `files.exclude` patterns are written to its `settings` section. Opening the file triggers a one-time window reload. |
5052

5153
All three toggle settings (`explorer`, `statusBar`, `workspace`) take effect immediately — no reload required.
5254

@@ -79,6 +81,35 @@ Non-autoMount vault content (`.obsidian/`, `.trash/`, and any directories not in
7981
- The Explorer tree view and the workspace folder both appear in the sidebar. The tree view provides custom UI (welcome view, context menus, drag-and-drop), while the workspace folder enables Quick Open and full-text search.
8082
- The `obs://` FileSystemProvider remains registered for the TreeView sidebar, wikilink navigation, and drag-and-drop — it does not back a workspace folder.
8183

84+
### Workspace File (avoiding "Untitled Workspace")
85+
86+
When `obsidianVFS.workspace` adds the vault folder dynamically, VS Code transitions to a multi-root workspace. Because no `.code-workspace` file is involved, the title bar shows **"UNTITLED (WORKSPACE)"** — this is standard VS Code behavior for unsaved multi-root workspaces.
87+
88+
Enable `obsidianVFS.workspaceFile` to fix this. The extension generates a `<project-name>.code-workspace` file in your project root (e.g., `my-app.code-workspace`) and prompts you to open it.
89+
90+
**What happens when you enable it:**
91+
92+
1. The extension creates `<project-name>.code-workspace` in your project root containing the local folder(s) and the `file://` vault folder entry (named `obs://<VaultName>`).
93+
2. A notification asks: _"Open workspace file? This will reload the window."_
94+
3. If you click **Open**, the window reloads once. After that, the title bar shows the project name and the vault is part of the saved workspace.
95+
4. On subsequent activations, the extension detects you're already in a saved workspace and skips the prompt. `files.exclude` patterns are written to the `.code-workspace` file's `settings` section (via `ConfigurationTarget.Workspace`) instead of `.vscode/settings.json`.
96+
5. If you click **Not Now**, the extension falls back to adding the vault dynamically via `updateWorkspaceFolders` (with `files.exclude` patterns in `.vscode/settings.json`). You can open the generated workspace file later.
97+
98+
**UX trade-offs:**
99+
100+
- **One-time window reload** — opening the workspace file causes VS Code to reload the window. This only happens once; after that the workspace file is saved and reloads are not needed.
101+
- **File on disk** — a `.code-workspace` file is created in your project root. You can commit it to version control (so teammates get the same workspace layout) or add it to `.gitignore`.
102+
- **No overwrite** — if a `.code-workspace` file already exists (e.g., from a previous run or your own), the extension will not overwrite it. It offers to open the existing file instead.
103+
- **`files.exclude` containment** — with a `.code-workspace` file, `files.exclude` patterns are scoped to the workspace file rather than `.vscode/settings.json`. This reduces the risk of pattern collisions with project directories (see Known limitations above).
104+
105+
**When to use each setting:**
106+
107+
| Goal | Setting |
108+
|------|---------|
109+
| Browse vault in Explorer, Quick Open, Search (accept "Untitled Workspace" label) | `workspace: true` |
110+
| Same as above, but with a proper project name in the title bar | `workspace: true` + `workspaceFile: true` |
111+
| Browse vault only via the sidebar tree view (no workspace folder at all) | `workspace: false` |
112+
82113
## Related Tools
83114

84115
This VSCode extension provides file-system access and UI integration for Obsidian vaults. If you use **Claude Code**, the companion [`@obsidian-vfs/claude-plugin`](https://github.com/otaviof/obsidian-vfs/tree/main/packages/claude-plugin) enables Claude to read and search your vault via `@obs:` mentions and automatically resolves wikilinks in agent definitions and skills.

packages/vscode/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "obsidian-vfs",
33
"displayName": "Obsidian VFS",
44
"description": "Browse, search, and edit your Obsidian vault directly in VSCode via a virtual file system (obs://)",
5-
"version": "0.3.0",
5+
"version": "0.3.1",
66
"private": true,
77
"publisher": "otaviof",
88
"engines": {
@@ -128,6 +128,11 @@
128128
"type": "boolean",
129129
"default": true,
130130
"description": "Add the vault as a file:// workspace folder for Quick Open (Cmd+P) and Search (Ctrl+Shift+F). Non-autoMount content is hidden via files.exclude patterns managed by the extension. Requires at least one local folder open and at least one autoMount entry."
131+
},
132+
"obsidianVFS.workspaceFile": {
133+
"type": "boolean",
134+
"default": false,
135+
"description": "Generate a .code-workspace file named after the project. Avoids the 'Untitled (Workspace)' label caused by dynamic workspace folder injection. The file contains a file:// vault folder entry and the extension's files.exclude patterns are written to its settings section. Opening the file reloads the window."
131136
}
132137
}
133138
}

packages/vscode/src/bootstrap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function readConfig(): ExtensionConfig {
1515
explorer: cfg.get<boolean>("explorer", true),
1616
statusBar: cfg.get<boolean>("statusBar", true),
1717
workspace: cfg.get<boolean>("workspace", true),
18+
workspaceFile: cfg.get<boolean>("workspaceFile", false),
1819
};
1920
}
2021

0 commit comments

Comments
 (0)