Skip to content

Formatting does not produce minimal edits when empty collections are unwrapped onto a single line #5198

Closed

Description

@DanTup

Splitting this from #5169 as there are two issues.

  • "Format Selection" can format the entire file #5169 will deal with Format Selection incorrectly formatting the entire document (this should never happen, regardless of whether or not we can minimize the format edits)
  • The formatter unwrapping [\n] should not result in us failing to compute minimal edits

With just the first issue fixed, we'll produce no edits instead of formatting the entire document. However, we should really produce an edit just for unwrapping the empty collection.

Example:

var a = <String>[
];
var b = '';

Should format to:

var a = <String>[];
var b = '';

...without falling back to full-document formats.

Currently it fails because the start code gets two tokens (an open bracket and a close bracket) but the end code gets a single simpletoken that is [].

Activity

  1. added
    in editorRelates to code editing or language features
    in lsp/analysis serverSomething to be fixed in the Dart analysis server
    on Jul 24, 2024
  2. added this to the v3.94.0 milestone on Jul 24, 2024
  3. DanTup commented on Jul 24, 2024

    @DanTup
    MemberAuthor

    This is fixed by dart-lang/sdk@b1f0b08. This is a fix in the language server that ships as part of the SDK, so the fix will show up in a future SDK release (not a Dart-Code release).

  4. added
    relies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available
    on Jul 25, 2024
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 featuresin lsp/analysis serverSomething to be fixed in the Dart analysis serveris 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