-
Notifications
You must be signed in to change notification settings - Fork 6
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 multiroot workspaces #17
Comments
Hey @jonnytest, thank you for showing interest in the extension! The extension initially wasn't intended to be used in multiroot workspaces, to not overload it with complexity from the start. The weird behaviour you experienced is the product of that, it will grab the first match and replace it. I'm open to the possibility of supporting multiroot workspaces. There are a few gotchas with multiroot workspaces:
I'd love to hear your thoughts/ideas on how would you expect to use this feature, since I lack the experience of working with multiroot workspaces. |
it might also be a good idea to allow some settings in the folder settings instead of user or workspace settings depending on wether they make sense (for example allowing a different glob pattern per folder) |
I'll most likely leave granular settings out of the scope for now. |
well my idea was most language extensions have a project specific setup - but i think thats usually a byproduct of going from the current file up to the next for example package.json or tsconfig.json or similar https://marketplace.visualstudio.com/items?itemName=liximomo.sftp anyhow if the idea is to change multiple envs with one click then its not strictly neccessary to determine the current project as long as its possible to differentiate them |
I understand, took a look at the extension, thank you for your input :) |
Would like to chime in to say I would love for this feature as its the only thing holding me back from using this extension as its exactly what I was looking for. Would love to try and support the development in whatever way I can. |
Hey @natefabian18, thank you for the comment. Personally, I've been mostly working with monorepos for the past couple of years, although I don't use multiroot workspaces. The amount of approaches on how to structure and manage monorepos feels daunting. Developing this extension, the guiding principle was that you dont need any additional files in the target repo, besides the presets, to make it work. |
@EcksDy Personally I tend to work in many disjointed projects that all link together for my primary work so we cant structure them as mono repos. I tend to like the suggestion made by @jonnytest1
Especially with the v0.4.3 release of showing the absolute path to greatly reduce the confusion of what exactly your switching to what. I have no input on if having 2 files with the same name should switch them both, Ideally it could be left as a setting and support both. |
@natefabian18 That constraint is a good guideline, I agree, as for the other points:
Neither do I. The repo will have to ignore it, which is not optimal, but it will allow for a more generic and inclusive solution. The more I think about it the more it makes sense, as it allows to set behavior settings that will dictate strategies of handling missing files in some of the sub-roots or how you should resolve what you want to switch: all or just current sub-root, etc.
Relying on
Aha, here's the catch, currently the switch command assumes there is only one target file, so when you switch it will just show you all presets found by the glob and switch the contents of the target to the selected preset. The button in the status bar is also tied to the contents of the target file.
With so many steps at this point I feel like the extension isn't saving that much time anymore and it does feel like multiroot/monorepo setups will require a different UI element to represent them. |
🤔 maybe a unique file in the .vscode folder is the better solution - then it can be individually .gitignored if a team decided its not shared confiugartion |
@jonnytest1 I do support the dedicated file in the .vscode folder as it is meta information as to how VSCode treats the project and not specific to the project itself. The question then becomes how to manage the multiple .vscode folders across m.workspaces. Having an |
🤔 yeah i tihnk merging would be ok
|
I appreciate that you all are using multi-root workspaces, it introduces me to a different use case than I'm accustomed to. Initially, I had the idea of organizing everything within one file in parent-root folder, given that I'm primarily a monorepo user. I see that it can make sense to let each sub-root define it's own presets and globs. Following that logic, the main-root would establish global behavior while sub-roots would serve as overrides. Here's how I envision the file tree in a multi-root workspace:
The contents of the files would be as follows, starting with the main-root: {
"*": {
"target": ".env",
"targetExclude": ["**/node_modules/**"],
"presets": "presets/*.env",
"presetsExclude": ["**/node_modules/**"]
},
"exclude": ["documentation/**"]
} a-project: {
".": {
"target": "target.env",
"presets": "envs/*.env",
}
} c-project: {
".": {
"presets": "presets/.env.*",
}
}
When sub-root configs are merged into the main-root config, the I think this covers the multi-root scenario. |
The monorepo scenario is a little different, but the concepts remain the same: wildcards and overrides. Let's take an NX monorepo setup as an example:
In a monorepo, I would personally avoid cluttering the project folders, which are dedicated to code, with global tooling configurations. Instead, I'd place the configuration either in the With just one configuration file, it would appear as follows: {
"apps/*": {
"target": ".env",
"targetExclude": "**/node_modules/**",
"presets": "presets/*.env",
"presetsExclude": "**/node_modules/**",
"overrides": {
"a-project": {
"target": "target.env",
"presets": "envs/*.env"
},
"c-project": {
"presets": "presets/.env.*"
}
}
}
}
These are my thought on monorepo implementation. There may be specific edge cases that I haven't considered, but I believe this provides a solid starting point. |
@EcksDy #17 (comment)
I assume the merging would be very similar if not exactly the same just that the a-project would have both {
"*": {
"target": ".env",
"targetExclude": ["**/node_modules/**"],
"presets": "presets/*.env",
"presetsExclude": ["**/node_modules/**"]
},
"exclude": ["documentation/**"]
} and {
".": {
"target": "target.env",
"presets": "envs/*.env",
}
} Into something like {
"*": {
"target": ".env",
"targetExclude": ["**/node_modules/**"],
"presets": "presets/*.env",
"presetsExclude": ["**/node_modules/**"]
},
"exclude": ["documentation/**"]
".": {
"target": "target.env",
"presets": "envs/*.env",
}
} Let me know if im just not understanding something |
you can also write configs directly into the workspace config json |
Good that you've brought it up, I wasn't aware that's the case.
Oooh, that's no bueno, folder order can change with every new folder added.
This can be a good solution, some questions to both of you:
|
A workspace-config.json is not required for a multiroot workspace but it is to save the workspace. You can open vscode right now click add folder to workspace and you have technically created a multiroot workspace. The catch is outside of vscode remembering what you recently had open there is no way to recall this workspace. See documentation
In my opinion its a reasonable expectation to have as I dont know anyone using complex multi-root workspaces that doesn't also use
I personally havent seen tooling be added to the |
@natefabian18 |
@EcksDy |
Progress updateStarted working on config file detection and found out that there's an issue with that, here are the thoughts on workaround:
|
writing to workspace settings should be the same as writing to .code-workspace (if the workspace is saved) |
Yeah, that's correct. I remembered why initially I was trying to avoid writing to I'm currently working on adapting the config module to be workspace aware. |
personally i think committing the .vscode/settings.json is precicely the advantage ^^ , if you have a team setup where everyone uses the same envs then comitting it is probably preferable (only works if all paths are relative tho ) |
I didn't find anyway to access the relative paths in the "folders" directive in
|
is sthere a way to get the workspace root or code-workspace file ? |
You have workspace roots(m.workspaces), but they're just the absolute paths to open folders. There is no way that I know of to get the Having absolute paths in I guess I can prompt the user to provide the path to the file on first activation if I find that the paths specified there aren't absolute and then save it( This is the best solution I can come up with so far. |
🤔 wasnt even as bad as i rember - i was almost certain it was by reading the process args of the currently running vscode processes 😅 |
🤔 i dont think we need the relative paths though , all the relative paths we use should be relative to the corresponding workspace root (or its ok for them to be absolute ) or am i forgetting something ? |
Where did you get this snippet from? That's some deep VSCode black magic! :) Unfortunately in my testing of it, it's picking up the wrong
Part AUse absolute paths in config by default:
Part BWhen extension detects relative path in config:
It's not clean and I'm sure there will be edge cases, but this should be foolproof for 99% of the use cases. |
I've re-read what you said, and you might be onto something...
We can take an approach where configs look like:
Then match the directory base name from the workspace roots against the config. Problem is that nothing prevents you from having 2 directories with the same name and then it falls apart:
We can try recursively go up a level until uniqueness is achieved, but how will you know when to stop and which of the directories will get the uniqueness treatment? How likely is it even to have 2 same named folders in m.workspaces? Nothing prevents it, but how likely is it? Maybe it affects a small enough group that can be politely asked to rename their directories to be able to use the tool? EditI've made this github search and looked at a few pages. Didn't find any file with duplicate directory names. |
To once again add my two cents. Normally I havent seen the code-workspace commited as with relative paths everything would be bundled together and your might as well have a monorepo at that point. I dont know why you would ever want two folders named the same in one workspace as it would just making features of multiroot workspaces confusing to use. |
oh 🤔i think vscode may have changed the name format - instead of a timestamp it is now a (semi)random string |
Progress update
Next steps would be:
|
Progress update
Next steps:
|
i currently have multiple folders in my vscode workspace that have a .env file - icant switch the one i want because it always writes to the other one
The text was updated successfully, but these errors were encountered: