Skip to content

feat(files-dialog): support ~ in defaultPath#317730

Open
its-miroma wants to merge 1 commit into
microsoft:mainfrom
its-miroma:tilde
Open

feat(files-dialog): support ~ in defaultPath#317730
its-miroma wants to merge 1 commit into
microsoft:mainfrom
its-miroma:tilde

Conversation

@its-miroma
Copy link
Copy Markdown
Contributor

@its-miroma its-miroma commented May 21, 2026

add support for ~, ~/Projects, ~\Projects, etc.

warn for ~user/Projects, ~//Projects

fix #317729

How to test

  1. Set files.dialog.defaultPath to a value that starts with ~
  2. Press Ctrl+O in an empty workspace
  3. Notice that the path is interpreted correctly

Copilot AI review requested due to automatic review settings May 21, 2026 08:46
@its-miroma
Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@vs-code-engineering
Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@alexr00

Matched files:

  • src/vs/workbench/services/dialogs/browser/abstractFileDialogService.ts

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds ~ (home directory) support to the files.dialog.defaultPath setting so file dialogs can start in a user-configured home-relative directory, with validation updates in configuration schema.

Changes:

  • Expand ~, ~/..., and ~\\... in AbstractFileDialogService.preferredHome() when resolving files.dialog.defaultPath.
  • Refactor preferredHome() to handle both ~-prefixed paths and absolute paths via a single preferredHomeUri candidate flow.
  • Update files.dialog.defaultPath configuration validation regex and error message to allow ~-based values.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/vs/workbench/services/dialogs/browser/abstractFileDialogService.ts Implements ~ expansion for files.dialog.defaultPath and consolidates existence checking via a computed URI.
src/vs/workbench/contrib/files/browser/files.contribution.ts Updates config schema regex + error message to accept ~-prefixed paths.

Comment on lines 123 to 126
async preferredHome(schemeFilter = this.getSchemeFilterForWindow()): Promise<URI> {
const preferLocal = schemeFilter === Schemas.file;
const userHome = await this.pathService.userHome({ preferLocal });
const preferredHomeConfig = this.configurationService.inspect<string>('files.dialog.defaultPath');
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the performance hit of fetching the userHome significant enough to warrant additional code complexity for a lazy fetch?

Comment on lines +137 to +141
relativePath = preferLocal
? localPathNormalize(relativePath)
: (await this.pathService.path).normalize(relativePath);
const isRelativePath = preferLocal ? !localPathIsAbsolute(relativePath) : !(await this.pathService.path).isAbsolute(relativePath);
if (isRelativePath) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, for the existing code already awaited this.pathService.path twice in sequence

Comment on lines +144 to 148
this.logService.debug(`[FileDialogService] Preferred home path after ~ resolved to absolute: ${relativePath}`);
}
} else {
this.logService.debug(`[FileDialogService] Preferred home files.dialog.defaultPath does not support tilde expansion: ${preferredHomeCandidate}`);
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My implementation mirrors the pre-existing debug messages for non-existent and non-absolute paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support ~ in files.dialog.defaultPath

3 participants