-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support "workspace folders" that are sub-folders of an existing open folder #45399
Comments
(Experimental duplicate detection) |
The idea in that one was, given the following structure:
By choosing to open "MyRepoFolder" would actually just open the three sub folders as workspace folders (so there is a 1-to-1 mapping of sub-folders to workspace folders, and the parent folder wouldn't actually appear in Code). This is pretty restrictive (you can't see the parent folder to access files in the root, it breaks the structure if your projects are not all at the same level, it requires you to open the project in a special way). What' I'd like to support is:
The idea is you open up MyRepoFolder and the user or extension can mark some folders (at any level of the tree) as WorkspaceFolders. If Code finds a This allows folders anywhere in the tree to get their own settings, launch configs, debugger launches etc. Since raising this I found a bunch of issues (a few are shown above because I commented on them, though others were locked) where people had raised issues that could be handled by this (for ex. not detecting tasks from package.jsons in sub-folders, etc.). It seems like the restriction of WorkspaceFolders having to be top-level in the tree shouldn't be required. Allowing them at any level within the tree makes things much more flexible. |
I've edited in a better example - using an |
@DanTup it seems to me all you want is that settings, launch and task configuration would be supported on any sub-folder location, is that true? Because if so, I would actually move this over to configuration land and make it independent from multi-root. |
@bpasero It's important to get the right "project folder" for many things, so being able to use getWorkspaceFolder(uri) and get that correct folder is important. If settings/launch/tasks/debug all start doing their own thing, it feels like they'll somewhat undermine WorkspaceFolders? Ultimately, how it's achieved is less important to me than it works, but as things are I'm not I can do what I need without an equiv of I could achieve some of it by tracking an array of "project folders" myself, but I've tried doing that on a branch and it's turning out to be a lot of work (for ex., being able to track when a new folder becomes a project/gets deleted/etc.) and have hit issues with things like the debugging. I thought this feature was a nice way to handle the whole lot and seemed to be useful to users - but if you propose another way, I will see if I can figure out whether it falls down anywhere for what I need. (it's likely there could be more smaller items like #45220 to get everything we need). |
#43902 was a bad attempt at trying to solve this problem, I'm happy for it to be rejected, I don't think it's a good solution anymore :)
I want to support any folder in the tree being capable of being a workspace folder (which means it can have its own
I think the problems with this are:
|
Possible with a
It is. Always the closest one.
True, this would probably only make sense in a saved workspace.
I think we could have that independently.
Simple: you remove all folders and add all folders the way you want. We take care of the diff and do the right thing. |
Yeah, and would only work the opposite way to the user wants (keeps the top-levels, hides the children)?
Ah, that's good to know. Someone told me something didn't work that I assumed was because this was returning the wrong thing - I'll dig into it and raise a bug if it seems to do the wrong thing anywhere.
Yeah, in this case I really want it to be transparent to the user. The user just wants to open a repo and have us do the right thing. Currently users keep asking why they can't debug their project in a sub-folder and it sounds kind ridiculous that I can't fix it (it needs #45220 - probably it didn't before I merged my debug types, but that was done for other good reasons).
Ah cool, didn't realise I could remove and add the same folders in one operation. Will this cause a reload, or can it be done sneakily without prompting the user or affecting open files/etc.? |
I am not sure I get that, but the real issue is that this setting is stored inside the folder but it only makes sense outside the folder (when opened as part of that workspace), so not a very good solution...
I assume you refer to this method: https://github.com/Microsoft/vscode/blob/master/src/vs/vscode.d.ts#L5444. We might need to tweak the JSDoc to clarify this and/or fix bugs if there are any.
Have you thought about just checking in a
It will only cause a reload if the first folder changes or if you transition from 0/1-folder into a workspace, but that is independent from that method, that is just the way how we support backwards compatibility. The method will do a diff of the folders that changed and then do the minimal update and the minimal set of events. |
Maybe I misunderstood, but I thought that your solution would hide the folders from inside the "main" (grandparent) root and than have it as its own root. This would mean it's displayed at the wrong place - the user wants to see it in its natural placing in the tree:
Yep, I do. I'll investigate and file bugs if I think it's not picking the closest one.
This isn't for a specific repo, it's for users own projects. It's more common than I expected for them to have Flutter projects in sub-folders and they're confused that it doesn't just work (on the surface it sounds simple, but when there are a bunch of commands - like package-restore - that need to be run at the right place, it gets complicated).
Ah, that would suck. User opens a folder - we find the pubspec.yamls and then try to add those folders as workspaces and they see an immediate reload right after they opened a folder. That said, I think the "I don't want sub-folders of my tree appearing at the top-level" is the biggest issue. |
If I got it right you want to hide those folders from the grand-parent that appear as workspace folders. The more I think about it the more I think this should maybe be just a multi-root related setting and not something that should go into the individual folders. Because this setting should only be defined on the level of the workspace file and not within folders. Something to control if any workspace folder should appear in the parent folder if the parent is a workspace folder too.
I think depending on the scenario, some things should work even without multi-root workpace. E.g. we should scan for
To be clear, this is a reload of the extension host, not the window. I do not think a user would notice. |
I'm still confused, but I think I might want the opposite. I do not want them to appear as new top-level items in explorer. I want them to continue to appear where they would if they were not workspace folders (eg. deep in the tree). I want what explorer shows to match what's on disk/in git and not have some folders magically promoted up to the top because they are projects. So in my previous "ascii drawings", the example apps should remain where they were there, but those folders would exist in
Yeah, there are two main reasons:
It's possible to do this another way - most likely it would involve some small tweaks/fixes around the place. I just thought the concept of a WorkspaceFolder extending to sub-folders was a good fit for it (because we could take advantage of a bunch of existing stuff - for ex. when a user wants to package restore, asking them which workspaceFolder would be a natural fit - if it was actually the project folders). If the intention for multi-root is solely to support multiple folders from different locations rather than to introduce something that resembles "project folders" then fair enough, but I think the concept of "project folders" that can be anywhere in the tree and used as the root for various things (like debugging launching, executing commands that want a "project root" etc, having their own .vscode folders for settings/tasks/etc.) would be a good one. |
Ok got it. Yeah that could be yet another setting for the Explorer specifically to not promote workspace folders to be root folders. Though a bit weird to be honest... because this makes the UI somewhat inconsistent. We have many places where workspace folders show up as unit (e.g. search) and it seems you could want to hide all those places.
I think the intention for multi-root is to allow to compose the workspace from many different folders that can have different roots. It is true that on top of that we have new APIs that make it easier to work with these folders. I also think that each workspace folder has more importance over any other folder, so you could argue that these folders become part of a higher concept (e.g. "projects"). I think your scenario can apply to any language and so I still think that only an extension for a specific language can understand the project nature of that language and that the extension should provide the functionality to convert the currently opened folder into a workspace. |
Actually, I think in other places treating them special is fine - if my_example_app_1 search results were shown separate from the main root, this wouldn't be a bad thing (as long as they're not also duped inside it), maybe even better - because it seems like their projects are being treated specially. It's only the explorer where I think it's bad, because the user expects that to mirror what's on their disk.
Yeah, I agree - I think the extension and/or the user should be able to set these. I'm not expecting Code to detect and promote things itself (I think if they have So, let's say a setting is added that allows workspace roots to be hidden from the top-level of explorer if they are children of another workspace root (obviously if the parent root is removed, it should re-appear, etc.). I think the remaining concerns are:
How does this sound? (btw having #45220 and #45214 in the shorter term would at least allow me to fix my biggest outstanding issue where Flutter apps in sub-folders are just totally broken) |
I have extracted #45470 for the explorer setting.
Again, this is "just" an extension host reload, not a window reload, I do not think the user would notice.
I think that is fine if the extension would have asked the user initially to convert into a multi-root workspace. The user can decide if he wants to stick with that workspace layout.
We could offer API to save a workspace from an extension (possibly asking the user for the location). I think that would solve 2. and 3. |
SGTM! I've
Sorry, missed that in your previous comment, this should be great then :-)
Yeah, that's true. I think it'd be nice not to need the prompt, but we can get it working like this first and see what feedback we get.
For 3, I was thinking more about people that go through this process (of converting to a workspace, and saving it into the .vscode folder) and then committing and pushing, and their teammates/whatever checking the repo out but just doing a File -> Open Folder. It'd be neat if just "opening the folder" actually opened the workspace. I actually already have this niggle - I have some workspaces but often forget to open them and open the "main" folders instead - which means I'm missing some of the useful things I've normally added them. Maybe it could be done with a setting and/or prompt? If you open a folder that has a single |
Yeah maybe. This reminds me of the recommendation notification of extensions that can popup to guide you into installing useful extensions for a workspace. If there was a way to recommend workspaces within a folder to open, this could help. |
Yeah, exactly! "This folder contains a workspace, would you like to open that?". I think that'd be a neat feature (and if extensions could auto-save a workspace they set up into that folder, I think it addresses everything :-)) |
Right, I found the issue I was having - it's not |
Closing this because I think the only significant thing left is covered by #45470. Our currently implementation works fine (with the noted exception that people don't like their projects being duplicated at the top level in the tree). |
Multiple projects open in Code has been an ongoing problem for Dart Code users. Users want to be able to open a folder that contains projects (eg. Flutter mobile apps) in sub-folders (or even example projects as sub-folders) however there are a bunch of complications, such as:
I tried to avoid fixing this for a long time telling my users to wait for and use multi-root workspaces when they arrive, however they're not very happy with this for a few reasons:
getWorkspaceFolder
if it exists in multiple rootsI've been trying to work around this and raised a couple of requests to try and handle this better (for #43902 and #45220, neither of which would be needed with this feature) but I think a better option is to support marking folders within a tree as workspace folders.
Here's how I think it could work:
Mark folder as Workspace Folder
This treats a folder as if it was added as a workspace folder but does not duplicate it at the root in the tree. It gets a slightly different icon to show it's a workspace folder (I think "project" is a better name, but I think Workspace folder is already somewhat stuck). This will fire
onDidChangeWorkspaceFolders
when the user sets/unsets itpackage.json
/pubspec.yaml
/app.config
) - this should not cause a "dirty" workspace - it should quietly write into the workspace file (or settings file if only a single folder is open).vscode
sub-folders as a WorkspaceFolder when opening a folder/workspaceworkspaceFolders
, appear in the debug config drop-downs, are returned fromgetWorkspaceFolder
, can have their own.vscode
folder with settings and launch configs (and getting resource-level settings will cascade up the tree)I think this would be a great change for code even outside of Dart/Flutter. It's really natural to have a repository with multiple "projects" in it and it's most natural to open the root. As far as I can tell there is nothing inherent in the WorkspaceFolder APIs that say they cannot appear within a tree, so I don't think is a big breaking change.
The text was updated successfully, but these errors were encountered: