microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.08k stars 29.24k forks source link

[handlebars] code-folding algorithm is less useful than Indentation-based one #48457

Closed peabnuts123 closed 6 years ago

peabnuts123 commented 6 years ago

I initially thought this was a bug but I managed to figure out what was happening. Very similar to #31756, #44520 and #13957.

See attached screen recording. Reproducible in any Handlebars/HTMLbars (.hbs) file with no Settings or Extensions enabled except for "editor.showFoldingControls": "always",. When you first open a HBS file there are folding controls for all the if statements etc. but once the editor loads these disappear leaving only HTML-based folding.

disappearing-folds

From what I can tell, this is because of the default Indentation-based algorithm running in the first instance, and then being taken-over once the Handlebars language loads. It would be nice if the default folding rules were sensitive to logical statements in the Handlebars markup.

VS Code version: Code 1.22.2 (3aeede733d9a3098f7b4bdc1f66b63b0f48c1ef9, 2018-04-12T16:32:53.389Z) OS version: Darwin x64 17.5.0

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz (8 x 2500)| |Load (avg)|5, 3, 3| |Memory (System)|16.00GB (0.05GB free)| |Process Argv|/Applications/Visual Studio Code.app/Contents/MacOS/Electron ./| |Screen Reader|no| |VM|0%|
aeschli commented 6 years ago

Ok, I see. Ideally, we had a handlebar aware folding provider. But probably I will just make the indentation based folding provider the default again for handlebars.

Note, you can switch back to the indentation based folding with

"[handlebars]": {
    "editor.foldingStrategy": "indentation"
  },
aeschli commented 6 years ago

Handlebar and Razor now use the indent based folding provider by default.

isidorn commented 6 years ago

@peabnuts123 did you check if this works fine for you in vscode insdiers? If not can you provide an example handlebar file that was not working nice so I could verify this issue got fixed

aeschli commented 6 years ago

@isidorn To verify, just make sure that handlebar files now use indentation again. The problem is that we don't know how to create folding ranges for the handlebar syntax. So all the user gets are regions for HTML. So users are better of with a indentation based folding (or an extension that provides handlebar specific folding)

peabnuts123 commented 6 years ago

This seems like the right fix for now. I have been using the indentation-based folding through a settings override since making this issue and it's been great.