Skip to content

Inline Values is not aware of conditional branches and may show for code that's not executed #5454

Closed

Description

@DanTup

For example here, the branch was not taken, but it's where we're showing the inline value:

Image

There's no way the analysis server can know which code paths were taken, so we need to use some rules that aren't affected which branches are taken. That might leaving it as it is, or might mean excluding all branches (except the current one - although that itself may be risky because we don't know how reliable the "execution pointer" position we're given is).

Activity

  1. DanTup commented on Jun 5, 2025

    @DanTup
    MemberAuthor

    I did some testing with Java, and it appears that they do not show inline values for any branches unless you are inside that branch:

    java.inline.values.mp4

    This means once you step out of the conditional block, those values disappear. While it'd be nicer IMO if they stayed there, that's not possible with the current API and I think what they're doing is better than what we're currently doing and I think we should do the same.

    I think this might be as simple as in our visitor, skipping the super call for any Block if stoppedLocation.end is not within that block.

    (cc @bwilkerson @jwren @FMorschel in case you have any opinions on this before I do)

    Edit: I'll also note that Java does not only show the last instance of a variable like we do, but I do not think that is better - I think it gets quite noisy.

  2. added this to the v3.114.0 milestone on Jun 5, 2025
  3. added
    in editorRelates to code editing or language features
    in lsp/analysis serverSomething to be fixed in the Dart analysis server
    relies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available
    on Jun 5, 2025
  4. FMorschel commented on Jun 5, 2025

    @FMorschel
    Contributor

    I agree that it feels more intuitive than our current behaviour.

  5. bwilkerson commented on Jun 5, 2025

    @bwilkerson

    Sounds reasonable to me.

  6. DanTup commented on Jun 5, 2025

    @DanTup
    MemberAuthor

    Great - I tried it out and this looks much better. I'll add some tests and send a CL. Thanks!

    inline.values.dart.mp4
  7. DanTup commented on Jun 5, 2025

    @DanTup
    MemberAuthor

    Fixed by dart-lang/sdk@9df0000 (ships in the SDK).

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