Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

WIP: Add support for project and path specific configs. - #16654

Closed
philipfweiss wants to merge 48 commits into
masterfrom
fb-pw-project-config-3
Closed

philipfweiss wants to merge 48 commits into
masterfrom
fb-pw-project-config-3

Conversation

@philipfweiss

@philipfweiss philipfweiss commented Jan 30, 2018 •

Copy link
Copy Markdown

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 on atom.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.set still acts upon only the global context, atom.config.get now looks through all of the settingsContext objects, grabbing values in order of precedence. The settings contexts are:

  1. 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.

  2. Project Settings. Atom config now has the concept of a "project", which packages can write settings to by calling atom.config.resetProjectSettings.

  3. Path Settings. Atom config now stores settings contexts for each of the roots mounted in the current atom session.

  4. 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 specific init.js files.

Possible Drawbacks

Although no APIs were changed, the behavior of atom.config.get has been changed. get now 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

@skylize

skylize commented Feb 5, 2018

Copy link
Copy Markdown

Is it really the best API choice to overload atom.config.get like this? What if a package very specifically wants to know what the user's global setting is, and has some particular reason to ignore project or path settings? It's now inaccessible, unless there are no "higher priority" settings.

Example alternative api

atom.config.set('myGlobalSetting')
atom.config.get('myGobalSetting')

atom.config.project.set('myProjectSetting', 'value')
atom.config.project.get('myProjectWideSetting')

atom.config.rootPath.set('myRootPathSetting', 'value')
atom.config.rootPath.get('myRootPathSetting')

// Explicitly request automatic resolution
atom.config.autoResolve.get('mySettingThatMayBeInAnyScope')

@philipfweiss

philipfweiss commented Feb 5, 2018 •

Copy link
Copy Markdown
Author

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 atom.config.set and atom.config.get APIs. For example, lets say a project wants to set the default tabwidth to 4. To do this, they put inside their project's config.json something along the lines of tabwidth: 4.

In this case, existing packages are already calling atom.config.get('tabwidth') to get the tab width. If we were to implement the separate API atom.config.project.get..., then the existing packages would not be getting these new project specific settings, and the changes would not be applied.

Essentially, the reason we decided to overload is that moving the API to atom.config.project... or atom.config.paths... would make these new configs useless for any package that isn't written to respect the new API. If we just had a atom.project.config.get, then this would only be used by people actually aware of and wishing to honor the API. Having to call this every time you get a value from config (or else potentially missing an important project specific configuration) would get pretty confusing for a package author, and ultimately probably wouldn't be used.

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 atom.project.config.set, then these files would change all the time, and it would be confusing for people working within the same project who are sharing the same config file to have their files get quickly out of sync.

If a package really wants to know what a user's global setting is, than they could use the (non-public) atom.config.getRaw{Scoped}ValueFromAPI.

@matthewwithanm

@skylize

skylize commented Feb 5, 2018 •

Copy link
Copy Markdown

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.

@philipfweiss

philipfweiss commented Feb 5, 2018 •

Copy link
Copy Markdown
Author

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:

  1. Project owner writes a .atom/config.js in the project's home directory. The can put things in here such as suggested packages, default tabwidth, editor color, or whatever.
  2. A user loading this project will get these settings by default whenever they have mounted the project root, since .get will resolve to the project specific settings context. One can imagine a new team member joining a project getting their team's settings just because their directory already has the config file within it (and doing no work otherwise). No other work is involved from the user's perspective.

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.

@matthewwithanm

@skylize

skylize commented Feb 5, 2018 •

Copy link
Copy Markdown

@philipfweiss

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". 👎 👎

@wbinnssmith

Copy link
Copy Markdown
Contributor

and now those settings get disposed of on every restart in favor of project config

that's not what's happening. Any package that uses config.set still ends up writing to the user's ~/.atom/config.json as it always has.

I'd give it a spin or read through the code if you have further questions.

@skylize

skylize commented Feb 6, 2018 •

Copy link
Copy Markdown

and now those settings get disposed of on every restart in favor of project config

that's not what's happening. Any package that uses config.set still ends up writing to the user's ~/.atom/config.json as it always has.

Ummmm.... If that's not what's happening, then why did @philipfweiss say this?

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.

Okay. I guess I slightly mispoke when I said "disposed of". But what good is it to write to .atom/config.json if those settings will always be shadowed by some other file somewhere else in the system? There is effectively zero difference to the user between shadowed and disposed of. The point is that every time they restart, they lose all the custom settings they worked out for themselves to make their own workflow a little easier.

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.

@skylize

skylize commented Feb 6, 2018 •

Copy link
Copy Markdown

I'd give it a spin or read through the code if you have further questions.

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 unfamiliar (I guess not unfamiliar, since designed to look like the old one, but still new, with its similarity being deceptive) API through its paces.

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.

@Arcanemagus

Copy link
Copy Markdown
Contributor

Contexts

First I'd like to talk about the contexts you are proposing here:

  1. 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.

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.

  1. Project Settings. Atom config now has the concept of a "project", which packages can write settings to by calling atom.config.resetProjectSettings.

Is this the same settings as are brought in via <project root>/.atom/config.{json, cson}?

Also I'm assuming that calling a function to write settings resetProjectSettings was a typo and that buried in the code is something that actually writes to a project setting. 😆

Do you intend these to be the same settings

  1. Path Settings. Atom config now stores settings contexts for each of the roots mounted in the current atom session.

What do you mean by "root"? Do you mean what each open TextBuffer::getPath() would return?

Benefits

include suggested packages in a project(!!)

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.

and other features currently in ~/.atom, such as project specific init.js files.

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 designs

This 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!

Problems

So 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:

This is because we want these configs to act essentially as immutable default values for a particular project.

But then in this you completely go against it and actually introduce a breaking change in Atom:

the next time the user loads the project it will read from the same project config and reset the settings.

atom.config.set('key') should always set that setting, no matter what. Any change to that is a breaking change that would have to wait till Atom 2.0. The fact that you have a "dirty context" means it only doesn't break it for that session, loading Atom back up again will mean that setting change has been invalidated.

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 atom.config.set) has customized the setting then that should always be respected, and allowing the project settings to only change the default value means the customized values will still come 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.

@iolsen

iolsen commented Feb 7, 2018

Copy link
Copy Markdown
Contributor

/cc @damieng @daviwil

@damieng

damieng commented Feb 7, 2018

Copy link
Copy Markdown
Contributor

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.

@matthewwithanm

Copy link
Copy Markdown
Contributor

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 config.get() should get the value from the layer of the highest precedence that contains the setting.

The real question is "what does config.set() update?" (Of course, we can add arguments or other API to make it target a specific layer if needed, but what is its default behavior?) It seems reasonable that it should update the global config (~/.atom/config.json) since that's the current behavior. But we also need to maintain the invariant that getting a value after setting it returns the value you set it to.

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).

Per-folder Global
User ~/.atom/config.json
Project Owner ./.atom/config.json

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 ./.atom/config-user.json. This file would specify per-project overrides, have the highest priority, and (unlike ./.atom/config.json) wouldn't be checked in to version control. (This is actually something we've already discussed but figured could be added later.) Again, solution 1 precludes this because it requires the global user config to have the highest precedence.

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 config-user.json immediately to avoid changing version controlled configs?). Solution 3 ("dirty settings") has the issues you've outlined but I'm not sure I agree about the severity; it seems pretty sensible that owner-contributed settings wouldn't be updated automatically, and that it's the responsibility of the project owner not to put crazy stuff (themes) in there.

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.

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.

@damieng

damieng commented Feb 12, 2018

Copy link
Copy Markdown
Contributor

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.

@damieng

damieng commented Feb 16, 2018 •

Copy link
Copy Markdown
Contributor

Meeting outcome from discussion with Facebook on project config:

  • FB are redefining this PR to just be an explicit project config proposal. i.e. myProject.atomProject.json will be a file that will contain an array of root paths and associated config. If you open from new File menu option or -p on command line it will open it as a project not as a text file. atom.config.get will read from this config then global. There will be no folder-level stuff here.
  • (RFC-001](RFC-001: Project-Specific Configuration #16698) will be tweaked to be for the root-folder level config that LSP needs which IDE team will develop. It will only deal with root folder configs (not project level) and any atom.config.get/set call will specify the folder name (because we can't magically guess which folder the call was running in as we don't have separate contexts for each root folder that they could honor for it)
  • We'll rework the File/Atom menu a bit to make the project stuff clearer
  • Initial config file editing/viewing will be to open the file in Atom as a file and edit as text - I have some ideas on how we can make settings-view provide something down the line that is understandable that I bounced off Simurai at mini-summit (edited)

@jasonrudolph
jasonrudolph deleted the fb-pw-project-config-3 branch May 17, 2018 20:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants