You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Writing ; inside an enhanced enum without the constructor makes it get removed #5602
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.
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:
Remove ; as a format-on-type trigger
This would reduce the usefulness of format-on-type, but it would still be on }
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.
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.
(edit:) Have the formatter never remove semicolons
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?
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.
Activity
DanTup commentedon Jul 24, 2025
The reason this happens is the
dart.formatOnTypesetting. 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:
;as a format-on-type triggerThis would reduce the usefulness of format-on-type, but it would still be on
}We do have the character that triggered the format, and a
Position, however the spec (about theposition) says:@bwilkerson any thoughts or other ideas?
@munificent any thoughts/opinions on something like (3)?
bwilkerson commentedon Jul 24, 2025
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?
DanTup commentedon Jul 24, 2025
I guess not doing that is another option (and one for Bob's opinion) - I added as (4).
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.FMorschel commentedon Nov 14, 2025
As linked above, for anyone who finds this and is interested in the discussions around this, we also have:
;in enums interacts poorly with VSCode dart-lang/dart_style#1782[analysis_server] Exclude the enum body semicolon from format-on-type
DanTup commentedon Dec 4, 2025
Fixed by dart-lang/sdk@ff5706e, ships in the SDK.
munificent commentedon Jan 12, 2026
Thanks for the fix, Danny!