I am trying to figure out just who would be responsible for this one. Ever since VS 2022 v.17.9.0 release, whenever I open a PHP file that uses the #region / #endregion convention, all regions are automatically collapsed. Doesn't matter if every region was expanded when I closed the file, when I open it again everything is collapsed.

This also occurs when a file is open in a tab and I close Visual Studio at the end of the day. When I open the project again, the file is opened in the tab but all the regions have automatically collapsed.

I found the setting under Tools->Options->Text Editor->C#->Advanced->Outlining (Visual Basic as well as C#) that prevents the auto collapse on file open but that has no affect on PHP files unfortunately. I see no such setting for PHP files.

This is annoying because I can no longer collapse all regions except the one I am working on, save and close VS at the end of the day, and then open the project the next day I have to find where I stopped the day before because all regions are now collapsed.

Thanks in advance!

    Thank you for the question,

    The file outlining should be persisted by Visual Studio - so regions are saved when you close the file and restored to their previous state when the file is opened.

    The settings are under Text Editor / PHP / Advanced, and all should be turned to True (it's the default):

    Collapsing the blocks with the Collapse to Definition command (Ctrl+M,O by default) indeed collapses regions - we don't have an option for that - I'll add it! That's a good point.

      I think it has something to do with the latest update itself, they definitely did something with the outlining, first indication is the arrows at the left, now little tick marks because I guess someone thought it looked more streamlined.

      My settings have always been true as shown in your screenshot, but still have the problem. I'll keep an eye out in the VS forum, and will ask this there tomorrow.

        jeHawWebdesign It's possible, I've noticed even though the PHP outlining is disabled, VIsual Studio adds it's own outlining, and incorrectly :/

          5 days later

          Good news, the VS Team just contacted me and requested I do that Submit Video and Logs functionality so they can find out what is happening.

          I told them what you said about turning PHP outlining off and it still outlining, and that they should contact you for more information if they need it.

          I'll keep you posted.

            jeHawWebdesign awesome! thank you very much for the updates and for talking to the VS team.

              6 days later

              Good Morning,

              The thread was just updated, they found the error, something to do with PHP Tools. Here is their answer:


              Thanks for your feedback. After our FTE investigated it was thought to be an issue with the PHP tool, as he saw a related error in ActivityLog.xml:
              <entry>
              <record>1961</record>
              <time>2024/02/22 07:41:58.756</time>
              <type>Error</type>
              <source>PhpLanguage</source>
              <description>Language Block Manager, VsTextViewCreated fail: Value cannot be null. Parameter name: serviceManager</description>
              </entry>
              “Language Block Manager” failing sounds like something that can cause collapsible regions to not behave as expected.

              I found out that you had already submitted the issue (#Region Auto-Collapsing on File Open - PHP Tools Community Forum | DEVSENSE) in PHP Tool’s official website. So go ahead and let the PHP group investigate to resolve your issue.


              Hope that helps, the original can be found at the link I provided earlier.

                Thank you for the update, and for keeping in touch with all of us)

                We'll check if it's related.

                  As a quick workaround, I would suggest disabling #region/#endregion outlining in Tools/Options/Text Editor/PHP/Advanced.

                  We're looking into it.

                    It seems this only happens if you open .php files without having a project/solution.

                    Without a solution, Visual Studio doesn't save the outlining state and doesn't restore it properly after reopening the file. Since #region is collapsed by default, Visual Studio always collapses it.

                    Also, without a project/solution, most of the features just won't work.

                    Is this the case?


                    In this case,

                    • it's always better to use projects or open a folder (File / Open / Folder)
                    • don't delete .vs directory created by Visual Studio - it contains the region's collapsed state
                    • or eventually, we can create an option to not collapse #region by default

                      The project is opened using the start window through an .sln solution file. (*.sln)
                      The .vs directory is intact.

                      Still collapses automatically.

                        jeHawWebdesign

                        I guess, the .php file is a part of the project?

                        I can't repro the issue, but I can change the defaults, so region won't get collapsed implicitly - will be done or configurable in next update.

                          5 days later

                          JakubMisek Sorry for the late reply, things got very hectic for the last few days. Many thanks, appreciate the effort.

                            jeHawWebdesign Thank you for the reply, I hope everything is OK.

                            I'll prepare a new update soon, it won't collapse #region by default.

                              13 days later

                              It works, too well. After setting it to false:

                              If all regions are collapsed and I open one region to work on it, then either close the file and then open it or close VS and then restart it, all regions are expanded.

                              Thanks for trying though.

                              The offending VS update (17.9.0) has caused a lot more problems than just this, interface changes without justification, collapsed TypeScript / JavaScript regions not showing tags, etc., they really did a job on this one.

                                jeHawWebdesign At least, we expand the regions by default, so you can see the code :) although, as you said, this needs to be handled by VS (fixed in a future update of VS). In some cases, it just forgets the state of the regions.