zokugun / vscode-explicit-folding

Customize your Folding for Visual Studio Code
MIT License
99 stars 14 forks source link

Associate information in the gutter with each folding point #45

Open FALLAI-Denis opened 3 years ago

FALLAI-Denis commented 3 years ago

Describe the issue

With hierarchical folding (separator / separatorRegex + descendants), it becomes difficult to see the scope of a folding.

Would it be possible to materialize this scope visually at the level of VS Code?

To reproduce

Code Example

       IDENTIFICATION DIVISION.
       PROGRAM-ID. MYPROG.
       DATE-COMPILED.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER. IBM-370.
       OBJECT-COMPUTER. IBM-370.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           select DD-FICHIER assign to UT-S-DD.
      /
       DATA DIVISION.
       FILE SECTION.
       FD  DD-FICHIER
           block contains 0 records
           recording mode is F.
       01  ARECORD.
           05  R1      PIC X(10).
           05          PIC X(70).
       WORKING-STORAGE SECTION.  
       01  AGROUP.
           05  A1      PIC X(1).  
           05  A2      PIC X(5).
       01  ANOTHERGROUP.
           05  B1      PIC X(1).
           05  B2      PIC X(5).  
       LINKAGE SECTION.
       01  APARM.
           05          PIC X(10).
       PROCEDURE DIVISION using APARM.
       MAIN SECTION.
       START-OF-RUN.
           open output DD-FICHIER
           move "Hello World !" to ARECORD
           write ARECORD
           close DD-FICHIER
           .
       END-OF-RUN.
           goback.
       END PROGRAM MYPROG.

Settings

    "folding":
      {"cobol": [
         {// Division
          "separatorRegex": "(?<=^.{6}\\s{1,4})[A-Za-z0-9\\-_:]+(?=\\s+(?i:DIVISION))"
         ,"strict": false
         ,"descendants": [
            {// Section
             "separatorRegex": "(?<=^.{6}\\s{1,4})[A-Za-z0-9\\-_:]+(?=\\s+(?i:SECTION))"
            ,"strict": false
            ,"descendants": [
               {// Paragraph
                "separatorRegex": "(?<=^.{6}\\s{1,4})[A-Za-z0-9\\-_:]+(?!\\s+(?i:SECTION|DIVISION))"
                ,"strict": false
                ,"descendants": [
                   {// Page eject
                    "separatorRegex":"(?<=^.{6})\\/"
                   }
                 ]
               }
             ]
            }
          ]
         }
       ]
      }

Expected behavior

See the scope of a folding before making it.

Screenshots

FoldingCobol2

daiyam commented 3 years ago

The shortcuts Ctrl+K Ctrl+<niv> are already working fine. The folding ranges are provided to VSCode as expected by it. There is no level in the spec, there are calculated by VSCode. This extension will only provide folding ranges. Changing the visual behaviour would require another extension, if possible.

FALLAI-Denis commented 3 years ago

My request was not about using the Ctrl+K Ctrl+<niv> commands which actually work well (although behaving confusingly).

My suggestion concerned the possibility of having visual feedback on the scope of a folding, for example by adding information in the gutter. Something like what I tried to depict below: ExplicitFolding-20210507-01

The formalism is just for illustration and could take a whole other form.

If VS Code does not manage a level in the folding, nor the "Explicit Folder" extension currently, perhaps it would be possible to associate an information with each declaration of markers in the "folding" settings, and that this information then be used for display in the gutter. It would only be by pure convention that this information would be a level, it could also be any information.

The "Explicit Folder" extension could have a set of predefined icons, or give the possibility to provide your own icons, that we could associate with a group of markers, for display in the gutter.

For example by adding a "decoration" property to each group expressing a folding. Which could give:

    "folding":
      {"cobol": [
         {// Division
          "separatorRegex": "(?<=^.{6}\\s{1,4})[A-Za-z0-9\\-_:]+(?=\\s+(?i:DIVISION))"
         ,"strict": false
         ,"decoration": "icon01.png"
         ,"descendants": [
            {// Section
             "separatorRegex": "(?<=^.{6}\\s{1,4})[A-Za-z0-9\\-_:]+(?=\\s+(?i:SECTION))"
            ,"strict": false
            ,"decoration": "icon02.png"
            ,"descendants": [
               {// Paragraph
                "separatorRegex": "(?<=^.{6}\\s{1,4})[A-Za-z0-9\\-_:]+(?!\\s+(?i:SECTION|DIVISION))"
                ,"strict": false
                ,"decoration": "icon03.png"
                ,"descendants": [
                   {// Page eject
                    "separatorRegex":"(?<=^.{6})\\/"
                   ,"decoration": "icon04.png"
                   }
                 ]
               }
             ]
            }
          ]
         }
       ]
      }

Confer DecorationRenderOptions.

daiyam commented 3 years ago

I agree that it can be helpful.

VSCode manage the levels of folding since you can collapse the foldings based on their level. But a folding range provider can't and doesn't need to provide it (VSCode can combine folding ranges from several providers. So a range from a provider can be a sublevel of a range from another provider).

Here the definition of a range:

class FoldingRange {
    start: number;
    end: number;
    kind?: FoldingRangeKind;
    constructor(start: number, end: number, kind?: FoldingRangeKind);
}

Me too, I would like to change how to display a folding, like adding the number of lines when the folding is collapsed. If I had searched how to do it, it would have been the subject of another extension.

FALLAI-Denis commented 3 years ago

I modified my issue to no longer refer to a range, but just to associate visual information with each folding point.

I propose to leave this request pending and mark it as an "enhancement".