question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow fold when function declaration is in multiple lines Dart

See original GitHub issue

Type: Bug

I’m filing this issue in the Dart extension because I have not been able to reproduce this exact behavior in languages like Python or C, even with the same parameter formatting. It’s relevant because this type of formatting is provided by dartfmt and makes the fold feature useless.

Environment: OS: Windows Version: 1.73.1 Reproducibility rate: 100%

Steps to reproduce:

  1. Create a Dart function such as: Future<void> function(String param1, String param2, String param3) async { // content // content // content }
  2. Try to fold the function

Expected Result: The function folds and all the content and parameters are hidden.

Actual Result: Only the function parameters are folded and the content stays visible.

Extension version: 3.52.1 VS Code version: Code 1.73.1 (6261075646f055b99068d3688932416f2346dd3b, 2022-11-09T04:27:29.066Z) OS version: Windows_NT x64 10.0.22000 Modes: Sandboxed: No

System Info
Item Value
CPUs 11th Gen Intel® Core™ i7-11850H @ 2.50GHz (16 x 2496)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) undefined
Memory (System) 31.67GB (16.43GB free)
Process Argv –crash-reporter-id 923bf38f-184f-4b44-8523-aba43b319e5f
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242:30382549
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscoreces:30445986
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593:30376534
pythonvs932:30410667
cppdebug:30492333
vsclangdc:30486549
c4g48928:30535728
dsvsc012cf:30540253
azure-dev_surveyone:30548225
pyindex848:30577860
nodejswelcome1cf:30587006
fc301958:30595537
3biah626:30602489
gswce1:30612156
3d0df643:30608728
dbltrim-noruby:30604474
89544117:30607850

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
DanTupcommented, Nov 18, 2022

With https://github.com/dart-lang/sdk/commit/35d3015ed5006b0a66ce9bbf742c7fe28453735f, whole function declarations (instead of just bodies) can be folded. There are also some other minor tweaks to ranges to improve handling of parameter lists when they start on the same line as the declaration (so they can still be folded).

This change is in the Dart language server so the fixes will show up with a future SDK update (rather than a Dart VS Code extension update).

0reactions
DanTupcommented, Nov 17, 2022

TypeScript (which I generally use as a template because it’s maintained by the VS Code team) does fold the whole declaration, but doesn’t allow folding of parameter lists:

https://user-images.githubusercontent.com/1078012/202503853-3d5106f5-e141-499d-b3b9-3560c7b0aa87.mp4

I think there may be some value in folding parameter lists (I suspect on average Flutter code has longer parameter lists and/or more likely has them split over a larger number of lines) but I’m not against removing them if they feel redundant.

Review on the way shortly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code folding not working properly in certain circumstances
dart (packages/flutter_tools/lib/src); Fold all code. This can be done by opening the command palette (Cmd/Ctrl+Shift+P) and typing Fold All.
Read more >
How to call multi statements when flutter is started with =>?
i dont know why no one answered but yes its possible to call many statements with an arrow function but you need a...
Read more >
Linter rules - Dart
For information on how to enable and disable individual linter rules, see individual rules sections ... Don't declare multiple variables on a single...
Read more >
Functions (With Optional & Required Parameters) - Flutter | Dart
Hey Coders! I like to think of functions similar to variables when coding in Dart. The difference is when creating a variable, ...
Read more >
Fpdart, Functional Programming in Dart and Flutter
Functional means telling only what you care about, and let the machine doing its work. Using the fold method, you declare where to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found