Repository navigation
WIP: Add support for project and path specific configs. - #16654
philipfweiss wants to merge 48 commits into
Conversation
|
Is it really the best API choice to overload Example alternative api |
|
Hi @skylize, The main reason we decided to go with this API design is that we want project specific settings to be applied to packages that are already using the In this case, existing packages are already calling Essentially, the reason we decided to overload is that moving the API to One other thing is that the project/path configs are read-only by design. There is no way to write to the project specific config files through atom.config. This is because we want these configs to act essentially as immutable default values for a particular project. If people were able to call something along the lines of If a package really wants to know what a user's global setting is, than they could use the (non-public) |
|
Thx for the reply @philipfweiss. Your argument definitely seems sensible at first glance. I certainly see the benefit of making the default API automatically add the new features for existing packages. You say that "project/path configs are read-only by design". This sounds nice from the perspective of simplicity, but that also means all project/path settings must be set explicitly by the user in the Settings pane. From a UI perspective, this can easily become a PITA for the user depending on the specific setting. If a package has a good method of adjusting certain configs based on user interaction and the user wants those changes stored at a project or path level, then developers should have the ability to store these interactive configs on the project. With that in mind, it would be much better, from the user's perspective, if the API gave developers a reasonable way to opt in to explicitly handling project/path configs separately from global ones, thus allowing users to opt in to allowing the package to make project and path specific adjustments on their behalf. |
|
Hi @skylize, I think there might be a confusion about what these changes are doing. It is not the case that "all project/path settings must be explicitly set by the user in the settings pane". The typical user will interact with these changes in the following way:
The above functionality is currently in VSCode, and requires very little from both package developers and users. There is no mechanism for the user to programmatically write to the project's config.js through atom. They can change their global settings by going into the settings pane, or they can make a change to the config file and commit it. Changing the settings in the settings pane will write to the global settings file, and change the setting for that instance of atom (since it will be written to dirty settings), but it will not change the project config and the next time the user loads the project it will read from the same project config and reset the settings. |
This sounds terrible!!! User interacts with a package that used to save some settings permanently to a global config, and now those settings get disposed of on every restart in favor of project config, with no opportunity for packages to "just do the right thing". 👎 👎 |
that's not what's happening. Any package that uses I'd give it a spin or read through the code if you have further questions. |
Ummmm.... If that's not what's happening, then why did @philipfweiss say this?
Okay. I guess I slightly mispoke when I said "disposed of". But what good is it to write to User should be able to customize her own editor, no matter what the project leader says the default config should be. Maybe you will make the Project Leader happy by always resetting to his chosen config. Maybe you will even make the New Junior Dev think that he is happy on his first day at work. But after a few weeks of having to rebuild his own custom config every single time he opens up his editor, he's probably going to lobby his boss to switch to VS Code. |
This conversation began as a discussion of API. Any attempt to "give it a spin" in this context would be a very significant time investment because I would need to build a package that puts a new and Since the concerns are very high-level, and not to do with any specific details of the code-quality (which I assume is amazing), it seems preferable to keep discussions at that same high level, rather than me spending hours digging through code to discover something that somebody here could be explain to me in a paragraph. I sincerely apologize if I am coming across aggressively to anybody. I shared what I thought was a possible flaw in the API, only to discover that the API was chosen because it supports an interface that (as so far described) sounds to me like it will be very unfriendly to users. If I am wrong, I am more than happy for someone to correct me. I am not here to argue, but rather to try and assist with making Atom the best it can be, and to get the jump on what I see as a potential problem before somebody needs to spend endless hours debugging it to make it ready for the master branch. |
ContextsFirst I'd like to talk about the contexts you are proposing here:
I think the fact that this exists at all points to a deeper problem with how this is working, which I'm pretty sure what @skylize is trying to point out here is a part of. I'll go into this in more detail in a bit.
Is this the same settings as are brought in via Also I'm assuming that calling a function to write settings Do you intend these to be the same settings
What do you mean by "root"? Do you mean what each open Benefits
You may want to read through atom/apm#385 where it seems like the idea you were most excited about here has already had quite a bit of discussion put into it.
Just a note, that if there are code changes here related to this, they should be moved to a separate PR, this is already going to be large enough without being super focused on just the config changes. Alternate designsThis should definitely be filled out, this is a huge change and if you haven't thought through at least some other ways of doing this you probably need to look harder at it 😉. In #16654 (comment) you mention that you did think about extending the API, so document it here! ProblemsSo let's get back to the "Dirty context" and how I think you can entirely get rid of this, and I think address the concerns that @skylize was bringing up, or at the least address the concern that I have looking at this. In #16654 (comment) and especially in #16654 (comment) you actually already hinted at the solution I'm proposing with this:
But then in this you completely go against it and actually introduce a breaking change in Atom:
Solution?I think overall this sounds like it's close to a solution to this, but instead of having a "Dirty context" and forcing project specific settings, these project specific settings should override the default schema for a setting. That means that if a user hasn't customized that setting then the project specific setting will be the new default value, allowing overrides. But if a user (or package through To use one of your examples let's say the project author just absolutely loves the Atom Light theme and thinks everyone should use it, so they set it as a default. Under your current proposal as soon as the project is loaded Atom will change its theme to Atom Light. Not everybody will want to use this theme though, so a user decides to change to One Dark. Everything works like they expect... until they restart Atom and suddenly it's back to Atom Light for that project. This is definitely not what a user would expect. If instead it simply changed the default value, once they changed the setting it would be stuck on that. |
|
What does 'project' mean in this context? Today it means the set of root folders with associated window state but such a concept doesn't have a project-specific location to store a settings config file. |
|
Hey all! Good points here! Hopefully I can clear some things up and enumerate the options and their tradeoffs 😊 We have broad agreement that there should be different "layers" of configuration, each with different precedence, and that The real question is "what does In other words, we always need to write to the layer of highest precedence. Possible solutions are (1) to make sure that the global config always has the highest precedence (as suggested by @Arcanemagus), (2) write to a different (or multiple) files, or (3) write to both the global config and an in-memory "dirty settings" which has the highest precedence (as currently done in the PR). The tricky part here is that precedence involves two concepts: ownership (user vs the project owner's) and breadth (global vs per-folder).
Just considering the "ownership axis", solution 1 seems good: the user's choice is favored over the owner's. However, this is ignoring the "breadth axis," which is a pretty severe limitation. Note that it would be impossible for a user to even override their own settings on a per-folder basis. (Incidentally, it looks like this is the case with Sublime while VSCode gives precedence to per-project settings.) On the other hand, an approach that didn't require the global user config to be given the highest precedence would allow us to fill in the user/per-folder slot of the matrix, say with a For these reasons, I think solution 1 isn't worth the tradeoffs. Solution 2 is a possibility but has many unanswered questions. (Do we write to more than one config? Do we need to implement
This is actually not meant to be public API and is a way for us (the Nuclide team) to experiment with the concept of a project that isn't directly analogous to the set of root folders. At Facebook, people tend to mount the root of a monorepo even when they're working on a conceptual "project" deeply nested within it. This would give us a way to tell Atom to use its config even though it wasn't a root. |
|
How will atom.config.get know which folder provides the right context-specific setting? It seems to me the safest option is to make atom.config.set and atom.config.get stay with just setting global and each should have an optional parameter that can specific a folder to get a more specific configuration from. The negative is that it does mean existing atom apps/plugins need to be updated to take advantage of this but I don't see how atom.config.get is going to know the context otherwise. Additionally this approach means we don't have to do the dirty settings hack. |
|
Meeting outcome from discussion with Facebook on project config:
|
Work in progress PR to give atom support for project specific configuration files.
Requirements
Description of the Change
The purpose of this change is to add the ability for atom to act upon path and project specific configuration files (instead of just a global
~/.atom/config.{json, cson}. After these changes, key/value pairs set within a.atom/config.{json, cson}on any mounted root will be honored by the editor. Additionally, packages will be able to set project specific settings onatom.config.This pull request includes mostly changes to the internals of atom.config. While all existing APIs (even private class methods of atom.config) still work, their implementation has in many cases been moved out to more generic functions that can be called on arbitrary setting contexts.
Previously, the only settings context in atom was the global context, which was acted upon by the various methods of the atom.config class. There are now multiple settings contexts, each with different precedences. While
atom.config.setstill acts upon only the global context,atom.config.getnow looks through all of the settingsContext objects, grabbing values in order of precedence. The settings contexts are:Dirty Settings. Any setting changed by atom.config.set within the current atom session will be added to the dirty settings, which have the highest precedence. This is to prevent issues where a value is set by a package, but then cannot be retrieved because a settings context of higher precedence has already defined it.
Project Settings. Atom config now has the concept of a "project", which packages can write settings to by calling
atom.config.resetProjectSettings.Path Settings. Atom config now stores settings contexts for each of the roots mounted in the current atom session.
Global Settings. This is the original settings context found in
~/.atom/config.{json, cson}Alternate Designs
Why Should This Be In Core?
Benefits
To allow users of atom to have project and path specific configuration, instead of just a personal .atom directory. It also lays the groundwork for other project-specific code within atom. Future directions include the ability to include suggested packages in a project(!!), and other features currently in
~/.atom, such as project specificinit.jsfiles.Possible Drawbacks
Although no APIs were changed, the behavior of
atom.config.gethas been changed.getnow searches through all the settings contexts, while it previously only looked through the global settings. These changes include new tests and pass previous tests, but because of the centrality of atom.config to the operation of many packages, and the many changes made to the file, we should be on the lookout for possible regressions introduced by these changes.Verification Process
New tests were added to ensure proper behavior and to protect against regressions.
Applicable Issues
WIP