Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support folding for loops and arbitrary blocks #4780

Closed
andrewkolos opened this issue Oct 7, 2023 · 4 comments
Closed

Support folding for loops and arbitrary blocks #4780

andrewkolos opened this issue Oct 7, 2023 · 4 comments
Labels
in lsp/analysis server Something to be fixed in the Dart analysis server is enhancement relies on sdk changes Something that requires changes in the Dart/Flutter SDK to ship before it will become available
Milestone

Comments

@andrewkolos
Copy link

andrewkolos commented Oct 7, 2023

for blocks cannot be folded. Un-prefixed top-level blocks cannot be folded either.

One workaround is to select the lines containing the block and use the "Create Folding Region from Selection" command.

To Reproduce
Steps to reproduce the behavior:

  1. In a VSCode editor, create and save a Dart file with the following contents:
void main() {
  if ('i am foldable' != false) {
    print("i can be hidden by folding `main` or my containing `if` block");
  }

  for (int i = 0; i < 3; i++) {
    print("i can only be hidden by folding main—the `for` can't be folded");
  }

  {
    print("this block can't be folded");
  }
}
  1. Attempt to fold the for loop on line 6 or the block starting on line 10.

Expected behavior
All code blocks should foldable.

Interestingly, upon starting VSCode, these blocks appear foldable initially (the chevron is visible), but then they become unfoldable. You can see this in the last few seconds of this video:

2023-10-07_11-53-19.mp4

Please complete the following information:

You can run the Dart: Collect Diagnostic Information command from the VS Code command palette (F1) to easily capture this information or provide it manually.

Workspace Environment
Dart Code extension: 3.74.0
Flutter extension: 3.75.20231002 (activated)

App: Visual Studio Code
App Host: desktop
Version: mac 1.82.3

Workspace type: Dart, Flutter (LSP)

Dart (3.2.0-231.0.dev): /Users/andrewkolos/Documents/GitHub/flutter/bin/cache/dart-sdk
Flutter (3.16.0-6.0.pre.12): /Users/andrewkolos/Documents/GitHub/flutter

Output from 'dart info'

/Users/andrewkolos/Documents/GitHub/flutter/bin/cache/dart-sdk/bin/dart info

If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.

General info

  • Dart 3.2.0-231.0.dev (dev) (Wed Oct 4 13:04:13 2023 -0700) on "macos_arm64"
  • on macos / Version 13.6 (Build 22G120)
  • locale is en

Process info

Memory CPU Elapsed time Command line
23 MB 0.0% 02:37 dart devtools --machine --try-ports 10 --allow-embedding
23 MB 0.0% 02:35 dart devtools --machine --try-ports 10 --allow-embedding
257 MB 0.0% 02:37 dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.74.0
42 MB 0.0% 02:35 dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.74.0
228 MB 0.0% 01:17 dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.74.0
46 MB 0.0% 02:37 flutter_tools.snapshot daemon
48 MB 0.1% 02:35 flutter_tools.snapshot daemon
Output from 'flutter doctor'

/Users/andrewkolos/Documents/GitHub/flutter/bin/flutter doctor -v

[!] Flutter (Channel [user-branch], 3.16.0-6.0.pre.12, on macOS 13.6 22G120 darwin-arm64, locale en)
    ! Flutter version 3.16.0-6.0.pre.12 on channel [user-branch] at /Users/andrewkolos/Documents/GitHub/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    ! The flutter binary is not on your path. Consider adding /Users/andrewkolos/Documents/GitHub/flutter/bin to your path.
    ! The dart binary is not on your path. Consider adding /Users/andrewkolos/Documents/GitHub/flutter/bin to your path.
    ! Upstream repository https://github.com/andrewkolos/flutter.git is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to https://github.com/andrewkolos/flutter.git to dismiss this error.
    • Framework revision 158dc50840 (19 hours ago), 2023-10-06 16:53:26 -0700
    • Engine revision 59b6b94e1a
    • Dart version 3.2.0 (build 3.2.0-231.0.dev)
    • DevTools version 2.28.1
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/andrewkolos/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • ANDROID_SDK_ROOT = /Users/andrewkolos/Library/Android/sdk
    • Java binary at: /Users/andrewkolos/Desktop/Android Studio Preview.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.12.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (version unknown)
    • Android Studio at /Applications/Android Studio with Blaze Beta.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to determine Android Studio version.
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[!] Android Studio (version unknown)
    • Android Studio at /Users/andrewkolos/Desktop/Android Studio Preview.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to determine Android Studio version.
    • android-studio-dir = /Users/andrewkolos/Desktop/Android Studio Preview.app
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.1.3)
    • IntelliJ at /Users/andrewkolos/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/231.9161.38/IntelliJ IDEA.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.82.3)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.75.20231002

[✓] Connected device (4 available)
    • SM A025V (mobile)           • R9HR701BH0H   • android-arm    • Android 12 (API 31)
    • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64  • Android 13 (API 33) (emulator)
    • macOS (desktop)             • macos         • darwin-arm64   • macOS 13.6 22G120 darwin-arm64
    • Chrome (web)                • chrome        • web-javascript • Google Chrome 117.0.5938.149

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 3 categories.
@andrewkolos
Copy link
Author

andrewkolos commented Oct 8, 2023

It also appears immediately invoked function expressions (IIFEs) are also affected by the same bug or a similar bug:

void main() {
  (() { // This function expression cannot be folded.
    print('hi');
  })();
}

@DanTup DanTup changed the title some blocks cannot be folded Support folding for loops and arbitrary blocks Oct 9, 2023
@DanTup DanTup added this to the v3.76.0 milestone Oct 9, 2023
@DanTup DanTup added is enhancement in lsp/analysis server Something to be fixed in the Dart analysis server relies on sdk changes Something that requires changes in the Dart/Flutter SDK to ship before it will become available and removed is bug labels Oct 9, 2023
@DanTup
Copy link
Member

DanTup commented Oct 9, 2023

This choice was actually deliberate. When folding was first added, VS Code had a hard limit on the number of folding regions and would disable folding if there were more. So originally only some specific things were foldable (classes, methods, etc.).

Over time, we've added more as people have requested them, and VS Code moved the 5k limit from all folding provider to only the indent-based provider in microsoft/vscode@20885d5 / microsoft/vscode#36555.

Interestingly, upon starting VSCode, these blocks appear foldable initially (the chevron is visible), but then they become unfoldable

This happens because until the Dart language server is fully initialised, VS Code provides indent-based folding. When the server is available, it switches to the server-provided folding.

Now that VS Code was raised the limit (to 0xffff) I think it's fair to expand what's foldable here.

@VictorGorban
Copy link

I enabled indent-based folding in my VSCode settings. It's a shame that Dart extension disables folding for loops and other code blocks.

copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue Feb 6, 2024
Fixes Dart-Code/Dart-Code#4780
Fixes Dart-Code/Dart-Code#4723

Change-Id: I6a2f5eb616643df0aaec7fef1b87594f6e223c5f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350581
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
@DanTup
Copy link
Member

DanTup commented Feb 7, 2024

Fixed by dart-lang/sdk@5e1fb3e. The change is in the Dart SDK so will show up in a future SDK release (note a Dart-Code release).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in lsp/analysis server Something to be fixed in the Dart analysis server is enhancement relies on sdk changes Something that requires changes in the Dart/Flutter SDK to ship before it will become available
Projects
None yet
Development

No branches or pull requests

3 participants