feat(files-dialog): support ~ in defaultPath#317730
Conversation
|
@microsoft-github-policy-service agree |
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @alexr00Matched files:
|
There was a problem hiding this comment.
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~\\...inAbstractFileDialogService.preferredHome()when resolvingfiles.dialog.defaultPath. - Refactor
preferredHome()to handle both~-prefixed paths and absolute paths via a singlepreferredHomeUricandidate flow. - Update
files.dialog.defaultPathconfiguration 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. |
| 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'); |
There was a problem hiding this comment.
Is the performance hit of fetching the userHome significant enough to warrant additional code complexity for a lazy fetch?
| relativePath = preferLocal | ||
| ? localPathNormalize(relativePath) | ||
| : (await this.pathService.path).normalize(relativePath); | ||
| const isRelativePath = preferLocal ? !localPathIsAbsolute(relativePath) : !(await this.pathService.path).isAbsolute(relativePath); | ||
| if (isRelativePath) { |
There was a problem hiding this comment.
Ditto, for the existing code already awaited this.pathService.path twice in sequence
| 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}`); | ||
| } |
There was a problem hiding this comment.
My implementation mirrors the pre-existing debug messages for non-existent and non-absolute paths.
add support for
~,~/Projects,~\Projects, etc.warn for
~user/Projects,~//Projectsfix #317729
How to test
files.dialog.defaultPathto a value that starts with ~