zokugun / vscode-explicit-folding

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

Doesn't work in conjunction with indentation foldingStrategy. #27

Closed FicoPrieto closed 3 years ago

FicoPrieto commented 3 years ago

Settings

"folding": {
  "*": [
    {
      "begin": "{",
      "end":   "}",
    }
  ]
}

 

Code Example

class Foo{

  bar(){
    return 1
  }

  baz()
    {return 2}

}

 

"editor.foldingStrategy": "auto"

Code_2020-11-02_12-58-13

 

"editor.foldingStrategy": "indentation"

Code_2020-11-02_12-58-25

daiyam commented 3 years ago

When "editor.foldingStrategy": "indentation", vscode is only using the indentation folding provider. So this extension is never called to provide the folding to the document (or any other folding provider).

This extension and vscode don't support folding range on a single line.

FicoPrieto commented 3 years ago

@daiyam

Ok, based on README#editors-support it seemed as though this extension would work in conjunction with editor.foldingStrategy set to either auto or indentation.
 

VSCode is using the folding ranges provided:

  • by the folding range provider defined by the setting editor.foldingStrategy (auto or indentation)
  • and by the folding range provider defined by this extension
daiyam commented 3 years ago

oops! My bad. It's a mistake, I will have to fix it. sorry.

forivall commented 3 years ago

Based on your comment, i think that this could be solved by bringing the indentation folding provider inside this extension, so that it can optionally provide indentation-based folding in conjunction with manual folds (i want indentation folding for python + docstring folding by pattern)

With a configuration like:

  "folding": {
    "python": [
      { "indentation": true },
      {
        "beginRegex": "\"\"\"",
        "endRegex": "\"\"\"",
        "nested": false
      },
      {
        "beginRegex": "'''",
        "endRegex": "'''",
        "nested": false
      }
    ]
  },
daiyam commented 3 years ago

@forivall, to do what you propose would be outside the scope of this extension.

But that could be done if editor.foldingStrategy supports a list of providers :

I can implement it in my version of VSCode.

daiyam commented 3 years ago

@FicoPrieto For which purpose did you indented to use this extension? To be able to fold the functions bar() and baz()?

FicoPrieto commented 3 years ago

@daiyam

Yes, I was expecting that both functions would be folded if foldingStrategy was set to indentation and vscode-explicit-folding was configured with the settings from the original post.

daiyam commented 3 years ago

@FicoPrieto I've added the support for "editor.foldingStrategy": "explicit & indentation" in MrCode (my version of VSCode). With that, I was able to do exactly what you wanted to do.

FicoPrieto commented 3 years ago

@daiyam
Thanks for implementing it!

It's unfortunate that they haven't accepted your PRs @ microsoft/vscode, this would be a great feature to have in VSCode, and I'd definitely prefer to stick with the official distribution.

I've tried a few approaches for re-implementing indentation folding via RegEx, but haven't been successful yet. In theory, this should work - I tested it out in VSCode & RegEx101 and it seems to work pretty well:

 
 

However, I can't get it to work with vscode-explicit-folding. Here is a simpler scenario I tried:

Code_2020-12-25_20-13-33

/* attempt 1 */ {"beginRegex":"(([\\t ])+)[^\\n]+\\n", "endRegex":"\\1\\2+\\{[^\\n]+\\}"  },
/* attempt 2 */ {"beginRegex":"(([\\t ])+)[^\\n]+",    "endRegex":"\n\\1\\2+\\{[^\\n]+\\}"},
/* attempt 3 */ {"beginRegex":"(([\\t ])+)[^\\n]+",    "endRegex":"\\1\\2+\\{[^\\n]+\\}"  },
daiyam commented 3 years ago

Those expressions won't work because there are multilines expressions which aren't supported by this extension. (It works line by line)

daiyam commented 3 years ago

@forivall @FicoPrieto I've changed my mind! The extension will support the config { "indentation": true }. It should be done in next days. So many users are already using it way beyond its initial purpose. Why not push it a little bit further ;)

FicoPrieto commented 3 years ago

@daiyam Awesome! How did you end up getting it to work? I thought the functionality was being prevented by a limitation of VSCode.

daiyam commented 3 years ago

@FicoPrieto Basically, I'm duplicating the builtin indentation provider into this extension. Since I don't like the ideas to duplicate code and to add another provider into the extension. So I thought doing "editor.foldingStrategy": "explicit & indentation" was better (still is better). But at the end of the day, there were no "immediate" solutions for user who wanted to stick to VSCode. Then, yesterday, I had the issue #36 (about jupyter python) and I thought that the extension was kinda useless for python devs. So I decided to give you the choice.

daiyam commented 3 years ago

I've made the branch indentation. Here the steps to test it:

Or uninstall the extension and install explicit-folding-0.10.0.vsix (remove .zip) by dropping the file in the list of extensions.

Here the config, I've used:

"python": [
    {
        "beginRegex": "\"\"\"",
        "endRegex": "\"\"\"",
    },
    {
        "separator": "# %%"
    },
    {
        "indentation": true,
        "offSide": true
    }
],

@forivall @FicoPrieto @OSHI7 Could you test it?

FicoPrieto commented 3 years ago

@daiyam I just tested the .vsix you provided with the code example from the first post and the following settings:

"editor.foldingStrategy": "auto",

"folding": {
  "*": [
    {
      "begin": "{",
      "end":   "}",
    },
    {
      "indentation": true,
      "offSide":     true,
    },
  ]
}

Result

image

daiyam commented 3 years ago

@FicoPrieto yep, I need to make the indentation loop to play well with the regex loop...

daiyam commented 3 years ago

@FicoPrieto I've made some small changes. Here the updated file explicit-folding-0.10.0.vsix.zip

FicoPrieto commented 3 years ago

@daiyam Seems to be working as expected, thanks for implementing this!!

OSHI7 commented 3 years ago

I'd try to test this, but am learning here as i go. Can i install this .vsix on vsCode? Not sure what's up and how to do this yet. I'll try to figure it out, sounds awesome.

daiyam commented 3 years ago

I've published the new version of the extension.

@OSHI7 You can try with the config:

"folding": {
    "python": [
        {
            "separatorRegex": "#\\s*%%"
        },
        {
            "indentation": true,
            "offSide": true
        }
    ]
}
OSHI7 commented 3 years ago

@daiyam, I see!
Yes, I think it works well. I will continue to test and follow up soon.

image

Very exciting!