Skip to content

Implement files.dialog.defaultPath setting (fix #115730)#182908

Merged
bpasero merged 12 commits intomicrosoft:mainfrom
gjsjohnmurray:fix-115730
Jun 26, 2023
Merged

Implement files.dialog.defaultPath setting (fix #115730)#182908
bpasero merged 12 commits intomicrosoft:mainfrom
gjsjohnmurray:fix-115730

Conversation

@gjsjohnmurray
Copy link
Contributor

This PR resolves #115730 by adding a machine-level setting workbench.fileDialog.homePath that will override the user home folder, which is what the file and folder dialogs currently fall back to when no better choice is derived.

@hediet hediet assigned bpasero and unassigned hediet May 22, 2023
@bpasero bpasero added this to the Backlog milestone May 22, 2023
@gjsjohnmurray
Copy link
Contributor Author

@bpasero any chance you could take a look at this? I don't think it's controversial, and reckon it will please a lot of people.

@bpasero bpasero requested a review from alexr00 June 23, 2023 06:35
@bpasero
Copy link
Member

bpasero commented Jun 23, 2023

Since this impacts simple file dialogs as well, adding @alexr00 for a look.

@gjsjohnmurray some high level feedback:

  • we have an existing setting files.simpleDialog.enable so maybe this setting should be called files.dialog.homePath
  • there is another getUserHome() method that probably needs to adopt the setting too
  • I find the code labeled as Normalize homePath setting so simple file dialog works correctly strange, why is this.pathService.fileURI not sufficient alone?

@alexr00
Copy link
Member

alexr00 commented Jun 23, 2023

I find the code labeled as Normalize homePath setting so simple file dialog works correctly strange, why is this.pathService.fileURI not sufficient alone?

+1 I would like to understand this too.

@gjsjohnmurray
Copy link
Contributor Author

I find the code labeled as Normalize homePath setting so simple file dialog works correctly strange, why is this.pathService.fileURI not sufficient alone?

+1 I would like to understand this too.

IIRC the 59c9323 commit was required to fix test failure. I'll investigate exactly which (the relevant CI log has already been purged).

@gjsjohnmurray
Copy link
Contributor Author

I had misremembered. I added this when testing how my change behaved in the remote scenario, based on this advice:

#162874 (comment)

When debugging Code - OSS I used this command to open a remote:

image

Then I used Settings Editor to set a value for my setting (in screenshot below I have already renamed it as suggested by @bpasero ):

image

As my workstation is Windows, and the TestResolver remote treats my Windows filesystem as though on a remote, the intuitive format for the value I set is a Windows path.

But in the preferredHome() method this PR adds, userHomePromise resolves to a Uri whose _formatted property is 'vscode-remote://test%2Btest/c%3A/Users/JohnM' and calling its with method with the argument { path: dialogHomePath } throws:

[UriError]: If a URI contains an authority component, then the path component must either be empty or begin with a slash ("/") character

because I had set homePath to C:\Users\JohnM\Documents\GitHub

I'm not currently catching this, so the dialog never opens and the user doesn't get told why.

Copy link
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

Thank you for the details on Normalize homePath setting so simple file dialog works correctly.

there is another getUserHome() method that probably needs to adopt the setting too

userHome is used in 2 places in the simple file picker. I think we should only use the setting value in one of those places:

https://github.com/gjsjohnmurray/vscode/blob/b7034b80526c5b8ca5c27e1419868919898fceaa/src/vs/workbench/services/dialogs/browser/simpleFileDialog.ts#L204-L209

The other place is about replacing ~ and I don't think we should override that ever.

alexr00
alexr00 previously approved these changes Jun 23, 2023
Copy link
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@gjsjohnmurray gjsjohnmurray changed the title Implement workbench.fileDialog.homePath setting (fix #115730) Implement files.dialog.homePath setting (fix #115730) Jun 24, 2023
@bpasero bpasero requested review from alexr00 and bpasero June 25, 2023 06:36
@bpasero
Copy link
Member

bpasero commented Jun 25, 2023

I just found this method in the file picker:

private remoteUriFrom(path: string, hintUri?: URI): URI {
if (!path.startsWith('\\\\')) {
path = path.replace(/\\/g, '/');
}
const uri: URI = this.scheme === Schemas.file ? URI.file(path) : URI.from({ scheme: this.scheme, path, query: hintUri?.query, fragment: hintUri?.fragment });
// If the default scheme is file, then we don't care about the remote authority or the hint authority
const authority = (uri.scheme === Schemas.file) ? undefined : (this.remoteAuthority ?? hintUri?.authority);
return resources.toLocalResource(uri, authority,
// If there is a remote authority, then we should use the system's default URI as the local scheme.
// If there is *no* remote authority, then we should use the default scheme for this dialog as that is already local.
authority ? this.pathService.defaultUriScheme : uri.scheme);
}

Which looks like it is doing a similar thing. Maybe @alexr00 could comment and maybe this needs to be used in this case here? It seems to do a bit more what I had suggested though.

@alexr00
Copy link
Member

alexr00 commented Jun 26, 2023

Which looks like it is doing a similar thing. Maybe @alexr00 could comment and maybe this needs to be used in this case here? It seems to do a bit more what I had suggested though.

I don't think that full method is needed here. The simple file picker has to do two extra things that the setting doesn't need to:

  • Display uniform slashes (all / or all \)
  • Switch between the remote file system and local file system.

Copy link
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

Switch between the remote file system and local file system.

Actually, looks like this is needed, and you've already done it ✅

@alexr00 alexr00 modified the milestones: Backlog, June 2023 Jun 26, 2023
@bpasero bpasero enabled auto-merge (squash) June 26, 2023 11:03
@bpasero bpasero merged commit c1d726b into microsoft:main Jun 26, 2023
@bpasero
Copy link
Member

bpasero commented Jun 26, 2023

@gjsjohnmurray any thoughts on the name of the setting, only now I realise its called files.dialog.homePath, but isn't this rather files.dialog.defaultPath?

@gjsjohnmurray
Copy link
Contributor Author

@bpasero I don't feel strongly about the current name. Fine with me if you want to rename it. Thanks for accepting the PR.

@gjsjohnmurray gjsjohnmurray changed the title Implement files.dialog.homePath setting (fix #115730) Implement files.dialog.defaultPath setting (fix #115730) Jun 26, 2023
@gjsjohnmurray gjsjohnmurray deleted the fix-115730 branch June 26, 2023 13:45
@gjsjohnmurray
Copy link
Contributor Author

I updated the title of this PR to reflect the setting rename in #186156

gjsjohnmurray added a commit to gjsjohnmurray/vscode that referenced this pull request Jun 26, 2023
…rosoft#182908)

* Implement `workbench.fileDialog.homePath` setting (fix microsoft#115730)

* Make it work with TestResolver remote

* Rename setting to `files.dialog.homePath`

* Add `preferredHome` to `IFileDialogService` so SimpleFileDialog can use it

* Improve setting description following feedback from @alexr00

* Ignore home override when doing ~ replacement

* Stop preferredHome falling back to user-local setting when working remote

* Eliminate preferredHome hack
@github-actions github-actions bot locked and limited conversation to collaborators Aug 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default save / open location

5 participants