zokugun / vscode-explicit-folding

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

Add support for management of hierarchical level based on headers. #41

Closed FALLAI-Denis closed 3 years ago

FALLAI-Denis commented 3 years ago

Hi,

Some constructions, which may require folding, are not based on start / end markers, or on separators, but on a logic of levels marked by headers, such as chapters / sub-chapters in a document.

For example in html, the H1, H2, ... Hn tags are headers marking hierarchies:

Another example is given in issue #39 for the COBOL language and the DIVSION, SECTION, and paragraph headers (paragraph folding not implemented on this issue).

The specificity of folding based on headers and hierarchical levels is that there is no explicit end marker. It is the start marker of another hierarchical level of the same rank or parent rank which is also the end marker of the current level.

Apparently, for the extension it is not possible that the same marker can participate in several folds, same end marker for several folding ranges, or both end of folding marker and start of folding marker for different ranges.

I would like to have the ability to fold according to hierarchical levels defined by headers.

Thanks.

daiyam commented 3 years ago

I agree that would be helpful

FALLAI-Denis commented 3 years ago

Hi @daiyam

I experimented with the separator mechanism with level hierarchies (dependencies).

I identified a case that is not taken into account: missing firt hierarchy level at start of source text.

Either the construction:

If the hierarchy does not start on the 1st level (H1), then there is no folding on the lower levels, until the 1st level (H1) appears in the hierarchy.

The problem would only concern the 1st level of the hierarchy, and seems to be related to regex: 0. The lack of intermediate levels does not seem to be a problem.

I have the same problem with COBOL:

    "folding": {
       "cobol": [
       {// Page eject
        "separatorRegex":"^.{6}\\/"
       ,"descendants": [  
           {// Division
            "separatorRegex": "^.{6}\\s{1,4}\\S+\\s+DIVISION"
            ,"descendants": [
                {// Section
                 "separatorRegex": "^.{6}\\s{1,4}\\S+\\s+SECTION"
                ,"descendants": [
                    {// Paragraph
                     "separatorRegex": "^.{6}\\s{1,4}\\S+(?!\\s+(SECTION|DIVISION))"
                    } ] 
                } ] 
            } ] 
       } ]
    } 

Result if no page break (1st hierarchy level): no folding ExplicitFolding-nopagebreak

lang: cobol, regex: /(?<_5_0>^.{6}\/)|(?<_5_1>^.{6}\s{1,4}\S+\s+DIVISION)|(?<_5_2>^.{6}\s{1,4}\S+\s+SECTION)|(?<_5_3>^.{6}\s{1,4}\S+(?!\s+(SECTION|DIVISION)))/
line: 1, offset: 0, type: SEPARATOR, match:        IDENTIFICATION DIVISION, regex: 1
line: 2, offset: 0, type: SEPARATOR, match:        PROGRAM-ID., regex: 3
line: 3, offset: 0, type: SEPARATOR, match:        DATE-COMPILED., regex: 3
line: 4, offset: 0, type: SEPARATOR, match:        ENVIRONMENT DIVISION, regex: 1
line: 5, offset: 0, type: SEPARATOR, match:        CONFIGURATION SECTION, regex: 2
line: 6, offset: 0, type: SEPARATOR, match:        SOURCE-COMPUTER., regex: 3
line: 7, offset: 0, type: SEPARATOR, match:        OBJECT-COMPUTER., regex: 3
line: 8, offset: 0, type: SEPARATOR, match:        INPUT-OUTPUT SECTION, regex: 2
line: 9, offset: 0, type: SEPARATOR, match:        FILE-CONTROL., regex: 3
line: 11, offset: 0, type: SEPARATOR, match:        DATA DIVISION, regex: 1
line: 12, offset: 0, type: SEPARATOR, match:        FILE SECTION, regex: 2
line: 13, offset: 0, type: SEPARATOR, match:        FD, regex: 3
line: 17, offset: 0, type: SEPARATOR, match:        WORKING-STORAGE SECTION, regex: 2
line: 18, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 19, offset: 0, type: SEPARATOR, match:        LINKAGE SECTION, regex: 2
line: 20, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 21, offset: 0, type: SEPARATOR, match:        PROCEDURE DIVISION, regex: 1
line: 21, offset: 0, type: SEPARATOR, match:  using APARM., regex: 3
line: 22, offset: 0, type: SEPARATOR, match:        MAIN SECTION, regex: 2
line: 23, offset: 0, type: SEPARATOR, match:        START-OF-RUN., regex: 3
line: 26, offset: 0, type: SEPARATOR, match:        END-OF-RUN., regex: 3

Result if page break at middle of text: folding missing before page break ExplicitFolding-pagebreakatmiddle

lang: cobol, regex: /(?<_5_0>^.{6}\/)|(?<_5_1>^.{6}\s{1,4}\S+\s+DIVISION)|(?<_5_2>^.{6}\s{1,4}\S+\s+SECTION)|(?<_5_3>^.{6}\s{1,4}\S+(?!\s+(SECTION|DIVISION)))/
line: 1, offset: 0, type: SEPARATOR, match:        IDENTIFICATION DIVISION, regex: 1
line: 2, offset: 0, type: SEPARATOR, match:        PROGRAM-ID., regex: 3
line: 3, offset: 0, type: SEPARATOR, match:        DATE-COMPILED., regex: 3
line: 4, offset: 0, type: SEPARATOR, match:        ENVIRONMENT DIVISION, regex: 1
line: 5, offset: 0, type: SEPARATOR, match:        CONFIGURATION SECTION, regex: 2
line: 6, offset: 0, type: SEPARATOR, match:        SOURCE-COMPUTER., regex: 3
line: 7, offset: 0, type: SEPARATOR, match:        OBJECT-COMPUTER., regex: 3
line: 8, offset: 0, type: SEPARATOR, match:        INPUT-OUTPUT SECTION, regex: 2
line: 9, offset: 0, type: SEPARATOR, match:        FILE-CONTROL., regex: 3
line: 11, offset: 0, type: SEPARATOR, match:        DATA DIVISION, regex: 1
line: 12, offset: 0, type: SEPARATOR, match:        FILE SECTION, regex: 2
line: 13, offset: 0, type: SEPARATOR, match:        FD, regex: 3
line: 17, offset: 0, type: SEPARATOR, match:       /, regex: 0
line: 18, offset: 0, type: SEPARATOR, match:        WORKING-STORAGE SECTION, regex: 2
line: 19, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 20, offset: 0, type: SEPARATOR, match:        LINKAGE SECTION, regex: 2
line: 21, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 22, offset: 0, type: SEPARATOR, match:        PROCEDURE DIVISION, regex: 1
line: 22, offset: 0, type: SEPARATOR, match:  using APARM., regex: 3
line: 23, offset: 0, type: SEPARATOR, match:        MAIN SECTION, regex: 2
line: 24, offset: 0, type: SEPARATOR, match:        START-OF-RUN., regex: 3
line: 27, offset: 0, type: SEPARATOR, match:        END-OF-RUN., regex: 3

Result if page break at start of text: folding at all level ExplicitFolding-pagebreakatstart

lang: cobol, regex: /(?<_5_0>^.{6}\/)|(?<_5_1>^.{6}\s{1,4}\S+\s+DIVISION)|(?<_5_2>^.{6}\s{1,4}\S+\s+SECTION)|(?<_5_3>^.{6}\s{1,4}\S+(?!\s+(SECTION|DIVISION)))/
line: 1, offset: 0, type: SEPARATOR, match:       /, regex: 0
line: 2, offset: 0, type: SEPARATOR, match:        IDENTIFICATION DIVISION, regex: 1
line: 3, offset: 0, type: SEPARATOR, match:        PROGRAM-ID., regex: 3
line: 4, offset: 0, type: SEPARATOR, match:        DATE-COMPILED., regex: 3
line: 5, offset: 0, type: SEPARATOR, match:        ENVIRONMENT DIVISION, regex: 1
line: 6, offset: 0, type: SEPARATOR, match:        CONFIGURATION SECTION, regex: 2
line: 7, offset: 0, type: SEPARATOR, match:        SOURCE-COMPUTER., regex: 3
line: 8, offset: 0, type: SEPARATOR, match:        OBJECT-COMPUTER., regex: 3
line: 9, offset: 0, type: SEPARATOR, match:        INPUT-OUTPUT SECTION, regex: 2
line: 10, offset: 0, type: SEPARATOR, match:        FILE-CONTROL., regex: 3
line: 12, offset: 0, type: SEPARATOR, match:        DATA DIVISION, regex: 1
line: 13, offset: 0, type: SEPARATOR, match:        FILE SECTION, regex: 2
line: 14, offset: 0, type: SEPARATOR, match:        FD, regex: 3
line: 18, offset: 0, type: SEPARATOR, match:        WORKING-STORAGE SECTION, regex: 2
line: 19, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 20, offset: 0, type: SEPARATOR, match:        LINKAGE SECTION, regex: 2
line: 21, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 22, offset: 0, type: SEPARATOR, match:        PROCEDURE DIVISION, regex: 1
line: 22, offset: 0, type: SEPARATOR, match:  using APARM., regex: 3
line: 23, offset: 0, type: SEPARATOR, match:        MAIN SECTION, regex: 2
line: 24, offset: 0, type: SEPARATOR, match:        START-OF-RUN., regex: 3
line: 27, offset: 0, type: SEPARATOR, match:        END-OF-RUN., regex: 3

If I comment on the "sections", the folding remains operational on the "paragraphs" inside the "divisions" (as long as the "page break" is present at the beginning of the source text): ExplicitFolding-nosection

lang: cobol, regex: /(?<_5_0>^.{6}\/)|(?<_5_1>^.{6}\s{1,4}\S+\s+DIVISION)|(?<_5_2>^.{6}\s{1,4}\S+\s+SECTION)|(?<_5_3>^.{6}\s{1,4}\S+(?!\s+(SECTION|DIVISION)))/
line: 1, offset: 0, type: SEPARATOR, match:       /, regex: 0
line: 2, offset: 0, type: SEPARATOR, match:        IDENTIFICATION DIVISION, regex: 1
line: 3, offset: 0, type: SEPARATOR, match:        PROGRAM-ID., regex: 3
line: 4, offset: 0, type: SEPARATOR, match:        DATE-COMPILED., regex: 3
line: 5, offset: 0, type: SEPARATOR, match:        ENVIRONMENT DIVISION, regex: 1
line: 7, offset: 0, type: SEPARATOR, match:        SOURCE-COMPUTER., regex: 3
line: 8, offset: 0, type: SEPARATOR, match:        OBJECT-COMPUTER., regex: 3
line: 10, offset: 0, type: SEPARATOR, match:        FILE-CONTROL., regex: 3
line: 12, offset: 0, type: SEPARATOR, match:        DATA DIVISION, regex: 1
line: 14, offset: 0, type: SEPARATOR, match:        FD, regex: 3
line: 19, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 21, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 22, offset: 0, type: SEPARATOR, match:        PROCEDURE DIVISION, regex: 1
line: 22, offset: 0, type: SEPARATOR, match:  using APARM., regex: 3
line: 24, offset: 0, type: SEPARATOR, match:        START-OF-RUN., regex: 3
line: 27, offset: 0, type: SEPARATOR, match:        END-OF-RUN., regex: 3

Note: I don't understand why "using APARM." matches regex: 3, paragraphs, (but that's another problem, relating to the management of the start of line?).

daiyam commented 3 years ago

In the updated extension explicit-folding-0.11.0.vsix, I'm fixing:

Here the config I'm using:

"cobol": [
  {
    // Page eject
    "separatorRegex": "^.{6}\\/",
    "descendants": [
      {
        // Division
        "separatorRegex": "^.{6}\\s{1,4}\\S+\\s+DIVISION.*",
        "descendants": [
          {
            // Section
            "separatorRegex": "^.{6}\\s{1,4}\\S+\\s+SECTION.*",
            "descendants": [
              {
                // Paragraph
                "separatorRegex": "^.{6}\\s{1,4}\\S+(?!\\s+(?:SECTION|DIVISION)).*"
              }
            ]
          }
        ]
      }
    ]
  }
]

Screenshot

FALLAI-Denis commented 3 years ago

I observe a regression with the version of April 26: in the absence of the 1st level marker at the beginning of the source text, the analysis of regular expressions stops on the 1st occurrence of the 1st level marker. ExplicitFolding

If I suppress all 1st level separator from source text, ("/" in column 7), all works fine...

Problem is: 1st level separator present, but not at 1st line of source text.

daiyam commented 3 years ago

I've added unit tests at https://github.com/zokugun/vscode-explicit-folding/tree/master/test/fixtures/cobol so I should be able to avoid a regression in the future. Here the updated extension with the fix: explicit-folding-0.11.0.vsix

FALLAI-Denis commented 3 years ago

I got this new version. Everything seems OK to me. Once again, great work!

I improved my configuration a little to be more in compliance with the COBOL standard for naming labels. This also apparently fixed the issue of wrongly selecting some texts:

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

ExplicitFolding-20210427-01

lang: cobol, regex: /(?<_5_0>^.{6}\/)|(?<_5_1>^.{6}\s{1,4}[A-Za-z0-9\-_:]+\s+(?=DIVISION))|(?<_5_2>^.{6}\s{1,4}[A-Za-z0-9\-_:]+\s+(?=SECTION))|(?<_5_3>^.{6}\s{1,4}[A-Za-z0-9\-_:]+(?!\s+(SECTION|DIVISION)))/g
line: 1, offset: 0, type: SEPARATOR, match:        IDENTIFICATION , regex: 1
line: 2, offset: 0, type: SEPARATOR, match:        PROGRAM-ID, regex: 3
line: 3, offset: 0, type: SEPARATOR, match:        DATE-COMPILED, regex: 3
line: 4, offset: 0, type: SEPARATOR, match:        ENVIRONMENT , regex: 1
line: 5, offset: 0, type: SEPARATOR, match:        CONFIGURATION , regex: 2
line: 6, offset: 0, type: SEPARATOR, match:        SOURCE-COMPUTER, regex: 3
line: 7, offset: 0, type: SEPARATOR, match:        OBJECT-COMPUTER, regex: 3
line: 8, offset: 0, type: SEPARATOR, match:        INPUT-OUTPUT , regex: 2
line: 9, offset: 0, type: SEPARATOR, match:        FILE-CONTROL, regex: 3
line: 11, offset: 0, type: SEPARATOR, match:       /, regex: 0
line: 12, offset: 0, type: SEPARATOR, match:        DATA , regex: 1
line: 13, offset: 0, type: SEPARATOR, match:        FILE , regex: 2
line: 14, offset: 0, type: SEPARATOR, match:        FD, regex: 3
line: 17, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 20, offset: 0, type: SEPARATOR, match:        WORKING-STORAGE , regex: 2
line: 21, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 24, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 27, offset: 0, type: SEPARATOR, match:        LINKAGE , regex: 2
line: 28, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 30, offset: 0, type: SEPARATOR, match:        PROCEDURE , regex: 1
line: 31, offset: 0, type: SEPARATOR, match:        MAIN , regex: 2
line: 32, offset: 0, type: SEPARATOR, match:        START-OF-RUN, regex: 3
line: 38, offset: 0, type: SEPARATOR, match:        END-OF-RUN, regex: 3
line: 40, offset: 0, type: SEPARATOR, match:        END, regex: 3
foldings: [{"start":0,"end":2,"kind":3},{"start":4,"end":6,"kind":3},{"start":8,"end":9,"kind":3},{"start":7,"end":9,"kind":3},{"start":3,"end":9,"kind":3},{"start":13,"end":15,"kind":3},{"start":16,"end":18,"kind":3},{"start":12,"end":18,"kind":3},{"start":20,"end":22,"kind":3},{"start":23,"end":25,"kind":3},{"start":19,"end":25,"kind":3},{"start":27,"end":28,"kind":3},{"start":26,"end":28,"kind":3},{"start":11,"end":28,"kind":3},{"start":31,"end":36,"kind":3},{"start":37,"end":38,"kind":3},{"start":30,"end":39,"kind":3},{"start":29,"end":39,"kind":3},{"start":10,"end":39,"kind":3}]
FALLAI-Denis commented 3 years ago

Or not....

The absence of an intermediate level, for example "section", deactivates the folding of the dependent levels. It seems to me that in previous versions this was not a problem.

ExplicitFolding-20210427-02

lang: cobol, regex: /(?<_5_0>^.{6}\/)|(?<_5_1>^.{6}\s{1,4}[A-Za-z0-9\-_:]+(?=\s+DIVISION))|(?<_5_2>^.{6}\s{1,4}[A-Za-z0-9\-_:]+(?=\s+SECTION))|(?<_5_3>^.{6}\s{1,4}[A-Za-z0-9\-_:]+(?!\s+(SECTION|DIVISION)))/g
line: 1, offset: 0, type: SEPARATOR, match:        IDENTIFICATION, regex: 1
line: 2, offset: 0, type: SEPARATOR, match:        PROGRAM-ID, regex: 3
line: 3, offset: 0, type: SEPARATOR, match:        DATE-COMPILED, regex: 3
line: 4, offset: 0, type: SEPARATOR, match:        ENVIRONMENT, regex: 1
line: 5, offset: 0, type: SEPARATOR, match:        CONFIGURATION, regex: 2
line: 6, offset: 0, type: SEPARATOR, match:        SOURCE-COMPUTER, regex: 3
line: 7, offset: 0, type: SEPARATOR, match:        OBJECT-COMPUTER, regex: 3
line: 8, offset: 0, type: SEPARATOR, match:        INPUT-OUTPUT, regex: 2
line: 9, offset: 0, type: SEPARATOR, match:        FILE-CONTROL, regex: 3
line: 11, offset: 0, type: SEPARATOR, match:       /, regex: 0
line: 12, offset: 0, type: SEPARATOR, match:        DATA, regex: 1
line: 13, offset: 0, type: SEPARATOR, match:        FILE, regex: 2
line: 14, offset: 0, type: SEPARATOR, match:        FD, regex: 3
line: 17, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 20, offset: 0, type: SEPARATOR, match:        WORKING-STORAGE, regex: 2
line: 21, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 24, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 27, offset: 0, type: SEPARATOR, match:        LINKAGE, regex: 2
line: 28, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 30, offset: 0, type: SEPARATOR, match:        PROCEDURE, regex: 1
line: 31, offset: 0, type: SEPARATOR, match:        MAIN, regex: 2
line: 32, offset: 0, type: SEPARATOR, match:        START-OF-RUN, regex: 3
line: 38, offset: 0, type: SEPARATOR, match:        END-OF-RUN, regex: 3
line: 40, offset: 0, type: SEPARATOR, match:        END, regex: 3
foldings: [{"start":0,"end":2,"kind":3},{"start":4,"end":6,"kind":3},{"start":8,"end":9,"kind":3},{"start":7,"end":9,"kind":3},{"start":3,"end":9,"kind":3},{"start":13,"end":15,"kind":3},{"start":16,"end":18,"kind":3},{"start":12,"end":18,"kind":3},{"start":20,"end":22,"kind":3},{"start":23,"end":25,"kind":3},{"start":19,"end":25,"kind":3},{"start":27,"end":28,"kind":3},{"start":26,"end":28,"kind":3},{"start":11,"end":28,"kind":3},{"start":31,"end":36,"kind":3},{"start":37,"end":38,"kind":3},{"start":30,"end":39,"kind":3},{"start":29,"end":39,"kind":3},{"start":10,"end":39,"kind":3}]

ExplicitFolding-20210427-03

lang: cobol, regex: /(?<_5_0>^.{6}\/)|(?<_5_1>^.{6}\s{1,4}[A-Za-z0-9\-_:]+(?=\s+DIVISION))|(?<_5_2>^.{6}\s{1,4}[A-Za-z0-9\-_:]+(?=\s+SECTION))|(?<_5_3>^.{6}\s{1,4}[A-Za-z0-9\-_:]+(?!\s+(SECTION|DIVISION)))/g
line: 1, offset: 0, type: SEPARATOR, match:        IDENTIFICATION, regex: 1
line: 2, offset: 0, type: SEPARATOR, match:        PROGRAM-ID, regex: 3
line: 3, offset: 0, type: SEPARATOR, match:        DATE-COMPILED, regex: 3
line: 4, offset: 0, type: SEPARATOR, match:        ENVIRONMENT, regex: 1
line: 5, offset: 0, type: SEPARATOR, match:        CONFIGURATION, regex: 2
line: 6, offset: 0, type: SEPARATOR, match:        SOURCE-COMPUTER, regex: 3
line: 7, offset: 0, type: SEPARATOR, match:        OBJECT-COMPUTER, regex: 3
line: 8, offset: 0, type: SEPARATOR, match:        INPUT-OUTPUT, regex: 2
line: 9, offset: 0, type: SEPARATOR, match:        FILE-CONTROL, regex: 3
line: 11, offset: 0, type: SEPARATOR, match:       /, regex: 0
line: 12, offset: 0, type: SEPARATOR, match:        DATA, regex: 1
line: 13, offset: 0, type: SEPARATOR, match:        FILE, regex: 2
line: 14, offset: 0, type: SEPARATOR, match:        FD, regex: 3
line: 17, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 20, offset: 0, type: SEPARATOR, match:        WORKING-STORAGE, regex: 2
line: 21, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 24, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 27, offset: 0, type: SEPARATOR, match:        LINKAGE, regex: 2
line: 28, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 30, offset: 0, type: SEPARATOR, match:        PROCEDURE, regex: 1
line: 32, offset: 0, type: SEPARATOR, match:        START-OF-RUN, regex: 3
line: 38, offset: 0, type: SEPARATOR, match:        END-OF-RUN, regex: 3
line: 40, offset: 0, type: SEPARATOR, match:        END, regex: 3
foldings: [{"start":0,"end":2,"kind":3},{"start":4,"end":6,"kind":3},{"start":8,"end":9,"kind":3},{"start":7,"end":9,"kind":3},{"start":3,"end":9,"kind":3},{"start":13,"end":15,"kind":3},{"start":16,"end":18,"kind":3},{"start":12,"end":18,"kind":3},{"start":20,"end":22,"kind":3},{"start":23,"end":25,"kind":3},{"start":19,"end":25,"kind":3},{"start":27,"end":28,"kind":3},{"start":26,"end":28,"kind":3},{"start":11,"end":28,"kind":3},{"start":29,"end":39,"kind":3},{"start":10,"end":39,"kind":3}]
daiyam commented 3 years ago

Yes, because of your comment:

If I comment on the "sections", the folding remains operational on the "paragraphs" inside the "divisions"

I thought that the paragraphs shouldn't fold inside a commented section. I will add the option strict. If false, the descendants can be matched even if a parent hasn't been matched.

PS: your logs aren't matching the screenshots... ;) (edit: it does but only the end)

daiyam commented 3 years ago

Here it is: explicit-folding-0.11.0.vsix

If you add "strict": false to the section config, the paragraphs can be folded.

FALLAI-Denis commented 3 years ago

Hi @daiyam

I think this time is the right one!

My last configuration (I put "strict": false at all levels)::

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

Result: ExplicitFolding-20210428-01

lang: cobol, regex: /(?<_5_0>^.{6}\/)|(?<_5_1>^.{6}\s{1,4}[A-Za-z0-9\-_:]+(?=\s+DIVISION))|(?<_5_2>^.{6}\s{1,4}[A-Za-z0-9\-_:]+(?=\s+SECTION))|(?<_5_3>^.{6}\s{1,4}[A-Za-z0-9\-_:]+(?!\s+(SECTION|DIVISION)))/g
line: 1, offset: 0, type: SEPARATOR, match:        IDENTIFICATION, regex: 1
line: 2, offset: 0, type: SEPARATOR, match:        PROGRAM-ID, regex: 3
line: 3, offset: 0, type: SEPARATOR, match:        DATE-COMPILED, regex: 3
line: 4, offset: 0, type: SEPARATOR, match:        ENVIRONMENT, regex: 1
line: 5, offset: 0, type: SEPARATOR, match:        CONFIGURATION, regex: 2
line: 6, offset: 0, type: SEPARATOR, match:        SOURCE-COMPUTER, regex: 3
line: 7, offset: 0, type: SEPARATOR, match:        OBJECT-COMPUTER, regex: 3
line: 8, offset: 0, type: SEPARATOR, match:        INPUT-OUTPUT, regex: 2
line: 9, offset: 0, type: SEPARATOR, match:        FILE-CONTROL, regex: 3
line: 11, offset: 0, type: SEPARATOR, match:       /, regex: 0
line: 12, offset: 0, type: SEPARATOR, match:        DATA, regex: 1
line: 13, offset: 0, type: SEPARATOR, match:        FILE, regex: 2
line: 14, offset: 0, type: SEPARATOR, match:        FD, regex: 3
line: 17, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 20, offset: 0, type: SEPARATOR, match:        WORKING-STORAGE, regex: 2
line: 21, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 24, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 27, offset: 0, type: SEPARATOR, match:        LINKAGE, regex: 2
line: 28, offset: 0, type: SEPARATOR, match:        01, regex: 3
line: 30, offset: 0, type: SEPARATOR, match:        PROCEDURE, regex: 1
line: 32, offset: 0, type: SEPARATOR, match:        START-OF-RUN, regex: 3
line: 38, offset: 0, type: SEPARATOR, match:        END-OF-RUN, regex: 3
line: 40, offset: 0, type: SEPARATOR, match:        END, regex: 3
foldings: [{"start":0,"end":2,"kind":3},{"start":4,"end":6,"kind":3},{"start":8,"end":9,"kind":3},{"start":7,"end":9,"kind":3},{"start":3,"end":9,"kind":3},{"start":13,"end":15,"kind":3},{"start":16,"end":18,"kind":3},{"start":12,"end":18,"kind":3},{"start":20,"end":22,"kind":3},{"start":23,"end":25,"kind":3},{"start":19,"end":25,"kind":3},{"start":27,"end":28,"kind":3},{"start":26,"end":28,"kind":3},{"start":11,"end":28,"kind":3},{"start":31,"end":36,"kind":3},{"start":37,"end":38,"kind":3},{"start":29,"end":39,"kind":3},{"start":10,"end":39,"kind":3}]
FALLAI-Denis commented 3 years ago

Solved.