Broken code folding (javascript)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Broken code folding (javascript)

Kyle Kirbatski
I’ve noticed this a lot and I’m wondering if there is anyway to fix it.

If I have this code:

function findEnvironmentConfig(environment, config) {
if (!Array.isArray(environment)) {
environment = [environment];
} else {
// Clone the array so any mutations aren't received on the other end
environment = [...environment];
}
}

And try to code fold on the line "if ( !Array.isArraty(environment)) {“ then it ends up folding the entire function declaration.

How can I make this work as expected? I have a sneaky suspicion that this is a fatal flaw with TextMate.

Note, this works if  the “else {“ is on its own line.

Thanks!


_______________________________________________
TextMate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|

Re: Broken code folding (javascript)

Kyle Kirbatski
Good to know. Thank you.

Sent from my iPhone

On Oct 14, 2019, at 2:54 AM, Allan Odgaard <[hidden email]> wrote:



On 7 Oct 2019, at 16:31, Kyle Kirbatski wrote:

And try to code fold on the line "if ( !Array.isArraty(environment)) {“ then it ends up folding the entire function declaration.

How can I make this work as expected? I have a sneaky suspicion that this is a fatal flaw with TextMate.

It’s a limitation of how foldings are defined, as foldable lines are determined by a regular expression match.

So a line either starts a fold or stops a fold, it can’t do both, as the regular expression match is run against the full line, so TextMate wouldn’t know at what column the respective patterns think the folding should start/stop.

The Language Server Protocol has a command/extension to request folding ranges from a language server, so if TextMate gets support for LSP, it could make use of this to get better ranges, assuming the language server for the respective language supports it, as TextMate itself has no problem folding your code as desired (you can fold manually by selecting the contents of the braces and press F1).


_______________________________________________
TextMate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate


_______________________________________________
TextMate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate