Closed FicoPrieto closed 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.
@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
orindentation
)- and by the folding range provider defined by this extension
oops! My bad. It's a mistake, I will have to fix it. sorry.
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
}
]
},
@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 :
auto
can become language | indentation
explicit & indentation
would provide what you looking forI can implement it in my version of VSCode.
@FicoPrieto For which purpose did you indented to use this extension? To be able to fold the functions bar()
and baz()
?
@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.
bar
via the explicit strategybaz
via the indentation strategy@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.
@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:
/* 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]+\\}" },
Those expressions won't work because there are multilines expressions which aren't supported by this extension. (It works line by line)
@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 ;)
@daiyam Awesome! How did you end up getting it to work? I thought the functionality was being prevented by a limitation of VSCode.
@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.
I've made the branch indentation
.
Here the steps to test it:
npm i
to install the dependenciesF5
to debug the extension.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?
@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,
},
]
}
bar
is partially collapsed
(expected line 5 to be collapsed into line 3, as when omitting the {indentation
, offSide
} group)
baz
is collapsed
(as expected)
@FicoPrieto yep, I need to make the indentation loop to play well with the regex loop...
@FicoPrieto I've made some small changes. Here the updated file explicit-folding-0.10.0.vsix.zip
@daiyam Seems to be working as expected, thanks for implementing this!!
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.
I've published the new version of the extension.
@OSHI7 You can try with the config:
"folding": {
"python": [
{
"separatorRegex": "#\\s*%%"
},
{
"indentation": true,
"offSide": true
}
]
}
@daiyam, I see!
Yes, I think it works well. I will continue to test and follow up soon.
Very exciting!
Settings
Code Example
"editor.foldingStrategy": "auto"
bar
is collapsed by the explicit strategy(expected)
baz
is not collapsed(expected, not matched by current strategies)
"editor.foldingStrategy": "indentation"
bar
is not collapsed by the explicit strategy(unexpected, this is the titular issue)
baz
is collapsed by the indentation strategy(expected)