Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird behavior with "nested":false, "foldLastLine":false #51

Closed
HolyBlackCat opened this issue Jun 20, 2021 · 12 comments
Closed

Weird behavior with "nested":false, "foldLastLine":false #51

HolyBlackCat opened this issue Jun 20, 2021 · 12 comments
Labels
bug Something isn't working

Comments

@HolyBlackCat
Copy link

HolyBlackCat commented Jun 20, 2021

Found a rather obscure issue.

Describe the issue

The end of a folding range is determined incorrectly.

I have following settings:

    "folding": {
        "cpp": [
            { // R"(...)" (C++ only)
                "beginRegex": "\"\\(",
                "endRegex": "\\)\"",
                "nested": false,
                "foldLastLine": false,
            },
            {
                "begin": "(",
                "end": ")",
                "foldLastLine": false,
            },
        ],
    },

Now, in the following code...

(

"(
    
)"

)

If I fold the topmost (, the folding stops at )", rather than at ).
In other words, I get this:

▶ (   
  )"

  )

While I expected this:

▶ (
  )

This doesn't happen if I do any of the following:

  • Remove "nested": false
  • Remove "foldLastLine": false
  • In the settings, change )" to something else, to not start with ).

To reproduce

  • VSCode: 1.57.0
  • Explicit Folding: 0.14.3
  • Language: cpp
@daiyam
Copy link
Member

daiyam commented Jun 20, 2021

I can't reproduce the issue.
Can you add the configuration "explicitFolding.debug": true, and post the log?

Here what I get:

document] lang: cpp, fileName: test.cpp
[main] regex: /(?<_0_0>"\()|(?<_2_0>\)")|(?<_0_1>\()|(?<_2_1>\))/g
[main] line: 1, offset: 0, type: BEGIN, match: (, regex: 1
[main] line: 3, offset: 0, type: BEGIN, match: "(, regex: 0
[main] line: 5, offset: 0, type: END, match: )", regex: 0
[main] line: 7, offset: 0, type: END, match: ), regex: 1
[document] foldings: [{"start":2,"end":3,"kind":3},{"start":0,"end":5,"kind":3}]

@HolyBlackCat
Copy link
Author

@daiyam Ah sorry, I accidentally commented out "nested":false in my first post. Edited it.
Here's the log (after uncommenting), just in case:

[document] lang: cpp, fileName: Untitled-1
[main] regex: /(?<_0_0>"\()|(?<_0_1>\()|(?<_2_1>\))/g
[main] line: 1, offset: 0, type: BEGIN, match: (, regex: 1
[main] line: 3, offset: 0, type: BEGIN, match: "(, regex: 0
[loop=0] regex: /(?<_2_0>\)")/g
[loop=0] line: 5, offset: 0, type: END, match: )", regex: 0
[main] line: 5, offset: 0, type: END, match: ), regex: 1
[main] line: 7, offset: 0, type: END, match: ), regex: 1
[document] foldings: [{"start":2,"end":3,"kind":3},{"start":0,"end":3,"kind":3}]

@daiyam
Copy link
Member

daiyam commented Jun 21, 2021

Yep. It's a bug!

@daiyam daiyam added the bug Something isn't working label Jun 21, 2021
@daiyam
Copy link
Member

daiyam commented Jun 21, 2021

I've having a conflict with a rule like:

{
	"name": "comment",
	"kind": "comment",
	"beginRegex": "^\\/\\/\\*",
	"endRegex": "^\\/\\/[^*]",
	"foldLastLine": false,
	"nested": false
}

where the last line shouldn't be consumed.

In your case, the last line has to be consumed.

I'm thinking to add the property consumeLast but not sure of the default value...

@daiyam
Copy link
Member

daiyam commented Jun 21, 2021

I will add consumeEnd astrue by default

@daiyam
Copy link
Member

daiyam commented Jun 21, 2021

It should be fixed in c5cdea4.

@FALLAI-Denis
Copy link

FALLAI-Denis commented Jun 23, 2021

I think I have a similar problem for handling comment line blocks.

Depending on the rules used, I don't get the same result.

Consider the following source code:

//MYJOB    JOB ,'MY JOB',CLASS=A,NOTIFY=&SYSUID
//****
//* FIRST COMMENT BLOCK
//****
//MYPROC   PROC P1='P1',                                               
//         P2='P2'
//*
//* SECOND COMMENT BLOCK
//* 
//MYSTEP   EXEC PGM=MYPROG
//STEPLIB  DD DISP=SHR,DSN=MY.LOADLIB
//IN       DD DISP=SHR,DSN=&P1
//OUT      DD DSN=&P2,
//            DISP=(NEW,CATLG),
//            SPACE=(CYL,(5,5),RLSE)
//*
//A         DD  dfjdlfj,
//            ldfjdflkj,
//            fkmfkdfpk
/*
//MYPROC   PEND
//*
//STEP     EXEC PROC=MYPROC,
//              P1='MY.FIC.ALPHA',
//              P2='MY.FIC.BETA'
//* That's all

The following rule works for all comment blocks, even those included in separator hierarchies ("First" and "Second" comment block):

             "name": "comment"
            ,"beginRegex": "^\\/\\/\\*"
            ,"endRegex": "^\\/\\/[^*]"
            ,"nested": false
            ,"foldLastLine": false
            ,"kind": "comment"

While the following rule only works for the 1st level of separator (only "First" comment block):

            "name": "comment",
            "beginRegex": "^\\/\\/\\*",
            "whileRegex": "^\\/\\/\\*",
            "foldLastLine": true,
            "nested": false,
            "kind": "comment"

Set of rules used:

    "[jcl]": {
        "files.autoGuessEncoding": true,
        "editor.rulers": [0,{"column":11,"color":"#603020"},{"column":15,"color":"#603020"},{"column":71,"color": "#603020"},{"column":72,"color": "#603020"},{"column":80,"color": "#ff0000"}],
        /* Requirement for Explicit Folding */
        "editor.folding": true,
        "editor.showFoldingControls": "always",
        "editor.foldingStrategy": "auto",
        "editor.foldingHighlight": true,
        /* Explicit Folding */
        "explicitFolding.debug": true,
        "explicitFolding.rules": [
           {// Bloc commentaires
            //"name": "comment",
            //"beginRegex": "^\\/\\/\\*",
            //"whileRegex": "^\\/\\/\\*",
            //"foldLastLine": true,
            //"nested": false,
            //"kind": "comment"

             "name": "comment"
            ,"beginRegex": "^\\/\\/\\*"
            ,"endRegex": "^\\/\\/[^*]"
            ,"nested": false
            ,"foldLastLine": false
            ,"kind": "comment"

           },
           {// DD
            "name": "dd",
            //"separatorRegex": "^\\/\\/[^*]\\S* +DD "
            "beginRegex": "^\\/\\/[^*]\\S* +DD ",
            "continuationRegex": "^\\/\\/(\\*|\\S* +DD \\S+,(?: |$)| +\\S+,(?: |$))",
            "nested": true
           },

           {// JOB
            "name": "job",
            "separatorRegex": "^\\/\\/[^*]\\S* +JOB(?: |$)",
            "strict": "never",
            "nested": [
               {// PROC - PEND
                "name": "proc",
                "beginRegex": "^\\/\\/[^*]\\S* +PROC(?: |$)",
                "endRegex": "^\\/\\/[^*]\\S* +PEND(?: |$)",
                "foldLastLine": true,
                "strict": "never",
                "nested": [
                    {// EXEC
                     "name": "exec",
                     "separatorRegex": "^\\/\\/[^*]\\S* +EXEC ",
                     "strict": "never",
                     "nested": true
                     //"nested": [
                     //   {// DD
                     //    "name": "dd",
                     //    //"separatorRegex": "^\\/\\/[^*]\\S* +DD "
                     //    "beginRegex": "^\\/\\/[^*]\\S* +DD ",
                     //    "continuationRegex": "^\\/\\/(\\*|\\S* +DD \\S+,(?: |$)| +\\S+,(?: |$))"
                     //   }
                     // ]
                    }
                  ]
                }
              ]
            }
          ]
      },

Same kind of problem with the rule concerning the row sequence "DD": works with the first occurrence ("OUT DD"), but does not work on the second occurrence ("A DD").

Note : full regex stop at "PROC"... do'nt understand wy...

[main] regex: /(?<_0_0>^\/\/\*)|(?<_4_1>^\/\/[^*]\S* +JOB(?: |$))|(?<_0_2>^\/\/[^*]\S* +PROC(?: |$))/g

Using version 0.14.4.

@daiyam
Copy link
Member

daiyam commented Jun 23, 2021

@FALLAI-Denis For DD, can you reply in #48 (comment)?

With the exception of DD, here the rule I have:

{ // JOB
    "name": "job",
    "separatorRegex": "^\\/\\/[^*]\\S* +JOB(?: |$)",
    "strict": "never",
    "nested": [
        { // PROC - PEND
            "name": "proc",
            "beginRegex": "^\\/\\/[^*]\\S* +PROC(?: |$)",
            "endRegex": "^\\/\\/[^*]\\S* +PEND(?: |$)",
            "nested": [
                { // EXEC
                    "name": "exec",
                    "separatorRegex": "^\\/\\/[^*]\\S* +EXEC ",
                    "nested": [
                        { // Bloc commentaires
                            "whileRegex": "^\\/\\/\\*",
                            "kind": "comment"
                        },
                    ]
                }
            ]
        }
    ]
}
  • "strict": "never" is allowing to avoid to repeat "strict": false.
  • foldLastLine is by default true
  • I've pushed the comment rule at the bottom of the tree since the arraynested is the list of authorized rules inside the folding region.
  • the comment rule with begin/end must use "consumeEnd": false instead of foldLastLine (cf Using begin/end/nested and separator #48 (comment))

Note : full regex stop at "PROC"... do'nt understand wy...

Yep, there is an issue with the repeated "strict": "never"...

@FALLAI-Denis
Copy link

FALLAI-Denis commented Jun 24, 2021

So I understand that the declaration "strict": "never" must be declared at the first level of a hierarchy of separators and each lower level inherits this declaration.

In my implementation, foldLastine is present in the rules to assess its impact depending on whether it takes the value true or false.

@daiyam
Copy link
Member

daiyam commented Jun 24, 2021

Yep, there is an issue with the repeated "strict": "never"...

@FALLAI-Denis The issue has been fixed in v0.14.5

@daiyam
Copy link
Member

daiyam commented Jun 24, 2021

@HolyBlackCat Can you tell me if you are still having issues?

@HolyBlackCat
Copy link
Author

Yep, everything works now, thanks!
I didn't realize you rolled out a new version, sorry for the delay.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants