Repository navigation
Find nearest existing resource for showOpenDialog in interactive forms - #6175
Conversation
VS Code ignores the `defaultUri` passed to `showOpenDialog` if it does not exist. For interactive forms, we have a single default value for open+save dialogs. In the case you choose Existing File, it's very likely the default value (which may be a suggested target filename) does not exist, and this results in VS Code just selecting the last folder you had open. By walking up the tree changing the default value to the first existing parent, we will start in that folder instead. Fixes #6164
ecfa9d8 to
0322863
Compare
|
@h9jiang do you have any thought/opinions on doing this? |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6175 +/- ##
=======================================
Coverage 70.77% 70.77%
=======================================
Files 170 170
Lines 13158 13169 +11
Branches 2649 2651 +2
=======================================
+ Hits 9313 9321 +8
- Misses 3324 3326 +2
- Partials 521 522 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
h9jiang
left a comment
There was a problem hiding this comment.
I think this is a great idea, the destination and the source (default value provided by language server) normally has certain proximity. (I assumed that the language server will provide a uri that is close to the src) And it is also intuitive for user to navigate starting from the source to the dest like cd ../../something/new/foo.dart.
In addition, if the language server does not provide a default, should we consider setting the default to the workspace root?
I don't know if that would necessarily be better than the last one you picked. If a server doesn't provide defaults and you are refactoring in some specific folder, the last one might be a better default. I think that's different to this case where the server is providing a default path, but VS Code is completely ignoring it because it doesn't already exist, so we're just trying to get as close to the one the server provided as we can. I don't feel strongly though, hopefully in general servers will provide default values. I'm happy to go with your preference (also cc @bwilkerson in case he has thoughts or a preference). |
|
I'll land this as-is for now, and file a separate PR if we want to make the other change. (or not... as GitHub seems to be falling over....) |
Which workspace root? I usually have several, by which I mean around 25) folders open in my workspace. I don't know what the workspace root would be in that case.
Most applications that I can think of will open the file dialog to the last directory used in a file dialog. This often works well. If I'm opening a file there's a higher probability that I want to open a file near the previously opened file. The same is true for files I'm creating. For example, consider the 'move declarations to file' refactoring. If I'm using it to break up a large file then chances are good that I want to create multiple new files in the same directory. |
I was more imagining the current workspace root that is aware by the extension. I think there are several natural ways for user to navigate through their current workspace. (their current repo).
I think previously recorded value makes a lot of sense and I think that might be very good solution as complicated refactoring may fail in the first time (like some merge conflicts) so the user might have to try again later. |
LSP supports multiple workspace folders (
In the case where the server didn't provide a default value, that's what we have today. But in the case where the server does provide a default, this PR tries to get us as close to that location as possible. This means if you retry a refactor, you would go back to the default and not the one that you'd previously selected (because of this PR). If we revert this PR, you'd get the same value as you previously selected on a retry, but you'd also get this behaviour for the first attempt, which could be a completely unrelated folder (for example if you were just working in a different project - if you haven't opened any folders via the Open Dialog at all in this session). |
Sorry I missed that. I think this makes total sense. Thanks for the clarification. |
To be clear (since it might not have been obvious), that behaviour comes from VS Code. The starting folder appears to be decided like:
Other editors might behave differently here, but of course we can't influence them from this code, it would have to be handled in their own plugins accordingly. |
…alog VS Code ignores the defaultUri passed to showOpenDialog if it does not exist. For interactive forms, we have a single default value for open+save dialogs. In the case you choose Existing File, it's very likely the default value (which may be a suggested target filename) does not exist, and this results in VS Code just selecting the last folder you had open. By walking up the tree changing the default value to the first existing parent, we will start in that folder instead. This CL is a sync from: Dart-Code/Dart-Code#6175 Change-Id: I3b254b29c4b0b091b0095a25afabc2cc366bde1b Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/832844 LUCI-TryBot-Result: [email protected] <[email protected]> Reviewed-by: Alex Putman <[email protected]> Auto-Submit: Hongxiang Jiang <[email protected]> Reviewed-by: Danny Tuppeny <[email protected]>
VS Code ignores the
defaultUripassed toshowOpenDialogif it does not exist. For interactive forms, we have a single default value for open+save dialogs. In the case you choose Existing File, it's very likely the default value (which may be a suggested target filename) does not exist, and this results in VS Code just selecting the last folder you had open.By walking up the tree changing the default value to the first existing parent, we will start in that folder instead.
Fixes #6164