8000 Add the concept of an `atomproject` file to atom. by philipfweiss · Pull Request #16845 · atom/atom · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Add the concept of an atomproject file to atom. #16845

Merged
merged 45 commits into from
Mar 12, 2018

Conversation

philipfweiss
Copy link
Contributor
@philipfweiss philipfweiss commented Feb 27, 2018

Description of the Change

Adds explicit project configs to Atom. Ie: One can now create a *.atomproject.{json, cson} containing an array of root paths, as well as an associated config. Opening this file from the command line with the -p flag (ie: atom -p ./foo.atomproject.json will, in a new window, open up all the paths specified in the file, as well as layer the configurations specified in the file in memory on top of the global config, at a level of precedence higher than settings from ~/atom/config.json. Atom windows not opened through the -p flag will not have any of the project specific settings.

This PR does not add the ability to launch atom from a project file through the UI, although it would be fairly simple to implement using the APIs (ie: atom.project.replace) added in this PR.

Please note that this PR is separate from (RFC-001](#16698). As @damieng has stated elsewhere, this RFC will be tweaked to be for the root-folder level config that LSP needs which IDE team will develop. That RFC will only deal with root folder configs (not project level).

Example of launching an atomproject on Giphy:
https://giphy.com/gifs/1wqpNX1QdxAflmELbh/fullscreen

EDIT: Project configs must now match personal configs - ie: the config in the above gif would need to be {'*': {'core': {'themes': ['one-light-ui', 'one-light-syntax']}}}

Alternate Designs

When a user invokes atom -p. *.atomproject.json, command-line-parser.js checks for a -p flag, and if it finds it, passes the data from the file over the process boundary to the newly created atom window. There, it calls atom.project.replace with the contents of this file. This API, atom.project.replace, uses project.setPaths to replace the paths on the atom window. An alternative way to do this could have been to use the pathsToOpen array in parse-command-line.js. Doing this would allow other command line options (ie: --test) to use the paths field of the atomproject file as well. I chose not to use this approach, and instead to just use project.setPaths. This is so that replace does all of the work of replacing an atomproject, instead of just doing most of it and delegating the paths bit to the Atom application process launcher. Additionally, this design simplifies the task of implementing UI to swap atomprojects.

In terms of layering project settings on top of the global config, this PR takes a very different approach to an earlier PR which was meant to add root-folder level config. First, there is no "dirty state" (settings that have been set within the current atom session), or "settingsContexts" (seperate in-memory settings objects) - instead, project configs are just implemented using the existing source properties on the config settings. No settings are saved to disk, and only layer on top of the atom window spawned for the project.

Why Should This Be In Core?

This change allows users to set config settings for a set of paths, which is useful for teams or individuals who want settings specific to a particular project. It also lays the groundwork for features like suggested packages (which could live inside a .atomproject file).

Verification Process

Unit testing in config-spec, project-spec, and extensive manual testing of atomproject files.

Applicable Issues

(RFC-001)(#16698)

@philipfweiss philipfweiss merged commit ef6c83f into master Mar 12, 2018
@jasonrudolph jasonrudolph deleted the fb-pw-simple-project-config branch March 12, 2018 13:04
Alhadis added a commit to Alhadis/.files that referenced this pull request Mar 18, 2018
@Alhadis
Copy link
Alhadis commented Mar 18, 2018

Sorry I'm late. ❤️Took me a full six days to notice this and add the new format to everybody's favourite file-icon package.

Oh yeah, I also updated Atom's manpage. You're welcome.

facebook-github-bot pushed a commit to facebookarchive/nuclide that referenced this pull request Mar 19, 2018
Summary:
Monkeypatch atom.config and atom.project to support project specific configs.

Once atom/atom#16845 is merged into atom, makes it into release, and then becomes supported by Nuclide, this should be removed.

Note that this monkeypatch is behind the nuclide-atomprojects GK.

Reviewed By: matthewwithanm

Differential Revision: D7118459

fbshipit-source-id: ee6605614db823914906746a9ba5939d86bd68aa
@jianhuafan
Copy link

should this line "pathsToOpen.push(path.dirname(projectSpecificationFile))" be changed to "pathsToOpen.push.apply(pathsToOpen, contents.paths)", cause when I open a new window it didn't open the path specified by the "paths" variable in ".atomproject.cson", instead opened the path that the ".atomproject.cson is at.

@manuelbieh
Copy link
manuelbieh commented Apr 9, 2018

That was long overdue, thank you for that awesome piece of work! But I still have one question: why do I have to explicitly add the -p flag? Can't Atom just automatically detect the presence of an .atomproject.cson file and load the config on top of the global config when opening any project folder?

Seems to be an unnecessary burden to me to start Atom using that -p flag. I'm used to quickly open the "Project Manager: List" and select the project I need at that moment. I guess custom settings files are not taken into consideration then? Or do I get that wrong?

@Alhadis
Copy link
Alhadis commented Apr 9, 2018

Can't Atom just automatically detect the presence of an .atomproject.cson file and load the config on top of the global config when opening any project folder?

It could, but that'll probably bite you someday when you open an unfamiliar path in Atom to make a quick edit, and wind up opening craploads of unfamiliar folders because you didn't notice there was an .atomproject.cson file in the current working directory.

Good command-line utilities should be dumb (in the sense of not trying to be "smart" by "guessing") and as predictable as possible. If writing out atom -p becomes cumbersome, add an alias to your .bashrc file:

alias @='atom -p .atomproject.?son'

Replace @ with whatever shortcut you'd like it to be.

@manuelbieh
Copy link

I honestly can't think of a use case where I would want to define files to open in a (project specific) config file. Why would anyone do that?

I have a very specific and current other use case though: I've just joined a new team a week ago and they're - for whatever reason - using the .md file suffix for their handlebars templates. I'd love to have a way to simply add a .atomconfig.cson to that project folder with:

'*':
  'file-types':
    'md': 'text.html.handlebars'

Which always gets automatically loaded whenever I open that project. No matter if via Dock, via Project Manager or Recent Files 😕

When talking about predictability: I'd throw consistency into the ring. I want to have always the same config when opening a project folder, no matter which way I open that project 😉

@Alhadis
Copy link
Alhadis commented Apr 9, 2018

I honestly can't think of a use case where I would want to define files to open in a (project specific) config file.

That was just an example. My point is that it goes against user expectations. There could be any number of reasons why an unfamiliar config file resides in a project directory - it could be a folder of test fixtures, files downloaded en masse from GitHub searches (it does happen...), or even a confused user who accidentally checked their config into a package's version control and forgot about it (and never noticed).

I want to have always the same config when opening a project folder, no matter which way I open that project

Back to that ol' "programs should not be smart-asses" thing again. =) If a user didn't want to load a project's config when opening a directory, they'd have no obvious way of saying "No Atom, don't load that damn file!"

@AlexWayfer
Copy link

@Alhadis What about some notification like "I found project file and loaded it" with button "No, don't!"?

@Alhadis
Copy link
Alhadis commented Apr 9, 2018

That's going way too far...

If automatic loading of project-configs are desired, I'd recommend setting something like this in your environment:

export ATOM_AUTOLOAD_PROJECTS=1

Alternatively, $ATOM_AUTOLOAD_PROJECTS could be set to a list of paths to restrict "autoloading" to (using the same : delimited format as $PATH).

So to always load .atomproject.* configs from any directories located inside ~/Projects or ~/.atom, you could do:

export ATOM_AUTOLOAD_PROJECTS="$HOME/Projects:$HOME/.atom"

Or just set it to 1 to unconditionally enable the behaviour if the user desires.

@djh329
Copy link
djh329 commented Apr 16, 2018

These settings will override global settings. Is this a problem for functionality such as zoom. From my quick playing around with this, it seems that the zoom function no longer works if I override fontSize in the editor configuration. This is because the project level configuration overwrites it. Should project configuration have listeners for these types of things

@YurySolovyov
Copy link

Is there a way to save current project layout as atomproject config?

@lee-dohm
Copy link
Contributor
lee-dohm 8000 commented Apr 19, 2018

@YurySolovyov No, that is out of scope for this change.

@YurySolovyov
Copy link
YurySolovyov commented Apr 19, 2018

@lee-dohm is there a ticket I can follow?

@lee-dohm
Copy link
Contributor

No, and I would be against a change like that since the concept of the atomproject file is to store project-wide settings that are shared between all people working on the project.

@lierdakil
Copy link
Contributor

Project.onDidReplace is left undocumented, and it's doesn't seem to be used anywhere, so it looks to be intended as public. I assume it's an oversight?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0