Search code examples
gitphpstorm

PhpStorm load set of files based upon current git branch or subproject or context


I am using PhpStorm to manage a number of projects, all happening at the same time.

PhpStorm kindly remembers loaded files between projects, so when I go back to Project Foo, all of my most recent files are still open.

However, Project Bar is huge and has a number of sub-projects, many but not all of which are branches in git.

Is there a way to change context or subproject such that all of the files I had open for the Bar Window Widget get saved when I change to Bar Laravel Refactor? And again saves those and reopens my Bar Window Widget files when working on that sub-project?

Even being able to do that based up on the current git branch would be start.


Solution

  • It sounds like you use a single PhpStorm project that contains many separate projects or sub-projects of a bigger project.

    A possible solution is to create separate PhpStorm projects for each of your sub-projects (based on how they are stored in the VCS repositories, for example). If you need to create another PhpStorm project for your main project you can choose to let it exclude the directories that contain sub-projects (and are handled by different PhpStorm projects). You can do that by right-click on the directory in the Project view then Mark Directory As -> Excluded. The excluded directories can be managed in the Preferences dialog box under the Directories page.

    The drawback of this solution: you have to work with multiple PhpStorm windows (each project opens in a new window).


    Another way to group the files and directories is to create Scopes (Preferences -> Appearance & Behaviour -> Scopes). A scope defines rules to include and exclude files and directories based on their names and paths. It is not very flexible but it works. The scopes appear in the Projects window, in the upper side dropdown box that also contains Project, Project Files, Problems a.s.o.).

    This is not exactly what you asked for but it can be used to manage a complex project. When a new scope is selected, only the files and directories it contains are listed in the Project window.


    Something more close to what you need is the Context feature. It works hand in hand with the Task feature but it can be used separately too. Both can be found in menu -> Tools -> Tasks & Contexts.

    Open some files you need to work on feature Foo. Save the context as Foo. Close files, open other files you need to work on feature Bar. Save the context as Bar. Load the previously saved Foo context. It should do what you need.

    If you also use Tasks then a context can be associated with a task. Switching tasks automatically also switches the associated contexts (and the correct list of files is open).