Skip to content

Writing ; inside an enhanced enum without the constructor makes it get removed #5602

Closed

Description

@FMorschel

Describe the bug
When writing ; inside enhanced enum before it contains a constructor, it gets removed.

To Reproduce
Steps to reproduce the behavior:

  1. In a dart file, write enum Enhanced { e }
  2. Add ; after e and see the code will stay the same

Expected behavior
I expect the ; to stay there so I can write the constructor.

Please complete the following information:

Workspace Environment
Dart Code extension: 3.115.20250715
Flutter extension: 3.115.20250701 (activated)

App: Visual Studio Code
App Host: desktop
Version: win 1.102.2

Workspace type: Dart (LSP)
Workspace name: bug

Dart (3.10.0-edge.7e05022286da202d366091d3efa446e6fbf685ab): C:\Users\felip_0vh5fa6\dart
Flutter (3.32.7): C:\Users\felip_0vh5fa6\.puro\envs\stable\flutter (No device)

Output from 'dart info'

C:\Users\felip_0vh5fa6\dart\bin\dart.exe 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.10.0-edge.7e05022286da202d366091d3efa446e6fbf685ab (main) (Fri Jul 18 17:46:04 2025 -0700) on "windows_x64"
  • on windows / "Windows 11 Pro" 10.0 (Build 26100)
  • locale is pt-BR

Project info

  • sdk constraint: '^3.9.0-edge.bddcddfe6b0914c7f234cd4400e1e70e8a72d374'
  • dependencies: bloc, due_date, meta
  • dev_dependencies: lints, test, test_reflective_loader, very_good_analysis

Process info

Memory CPU Elapsed time Command line
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe
0 MB -- dart.exe

Activity

  1. DanTup commented on Jul 24, 2025

    @DanTup
    Member

    The reason this happens is the dart.formatOnType setting. This setting instructs VS Code to format your code as you are typing, and ; is a trigger character for that (because usually, completing a statement would be a logical time for format-on-type to fire).

    However, this doesn't work so well if the formatter might remove semicolons.

    Some possible options:

    1. Remove ; as a format-on-type trigger
      This would reduce the usefulness of format-on-type, but it would still be on }
    2. Try to detect this condition in the format-on-type handler and skip the format
      We do have the character that triggered the format, and a Position, however the spec (about the position) says:

      This is not necessarily the exact position where the character denoted by the property ch got typed.

    3. We have an option for the formatter that would allow us to suppress this behaviour (removing non-whitespace) that we pass when formatting on-type.
    4. (edit:) Have the formatter never remove semicolons

    @bwilkerson any thoughts or other ideas?

    @munificent any thoughts/opinions on something like (3)?

  2. added
    in editorRelates to code editing or language features
    on Jul 24, 2025
  3. added this to the On Deck milestone on Jul 24, 2025
  4. bwilkerson commented on Jul 24, 2025

    @bwilkerson

    While the semicolon is optional when there's nothing else following it, it isn't clear to me that the formatter should treat it like whitespace. I can see the argument for doing so because in some ways it feels like an optional trailing comma, but it seems different to me, maybe because the trailing semicolon has never been used to control formatting.

    I'm not thrilled with option (3) because that means that server would need to have logic to determine when to pass in the flag and when not to, and that seems error prone and/or confusing for the user. Or else we just always disable it within the IDE, but then why make it an option?

  5. DanTup commented on Jul 24, 2025

    @DanTup
    Member

    While the semicolon is optional when there's nothing else following it, it isn't clear to me that the formatter should treat it like whitespace.

    I guess not doing that is another option (and one for Bob's opinion) - I added as (4).

    I'm not thrilled with option (3) because that means that server would need to have logic to determine when to pass in the flag and when not to

    My idea was to always pass it when responding to format-on-type (this is a different LSP request to the general format, or format-range). Eg., if the formatter had two modes - one that only touches whitespace, and one that does also does other "cleanup", we could ensure that when typing, we only ever use the first, but on-save or explicit formats we did the second.

  6. FMorschel commented on Nov 14, 2025

    @FMorschel
    ContributorAuthor

    As linked above, for anyone who finds this and is interested in the discussions around this, we also have:

  7. DanTup commented on Dec 4, 2025

    @DanTup
    Member

    Fixed by dart-lang/sdk@ff5706e, ships in the SDK.

  8. modified the milestones: On Deck, v3.126.0 on Dec 4, 2025
  9. added
    relies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available
    on Dec 4, 2025
  10. munificent commented on Jan 12, 2026

    @munificent

    Thanks for the fix, Danny!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresis bugrelies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions