Skip to content

Wrong imports in Stateless Widget snippet from analysis server #49081

Closed

Description

@nickmeinhold

In VS Code when using the stlss snippet:

Screen Shot 2022-05-23 at 19 01 49

The resulting code has the imports included:

Screen Shot 2022-05-23 at 19 02 04

For me these are the wrong imports and I have to go up and delete them and then add the correct imports.

I discussed with @DanTup on the VS Code Discord and he thought this is a bug with how the server decides which imports to add.

Thanks!

  • Dart SDK Version 2.17.1 (stable) on "macos_arm64"

Activity

  1. DanTup commented on May 23, 2022

    @DanTup
    Collaborator

    @bwilkerson do I recall you saying this may have already been solved somewhere outside of the server? The import is being added automatically by the edit builder (via writeType or similar). I'm not sure how it would know which exported library to add though (Flutter has many overlapping).

    We could perhaps list the preferred imports with the snippet and add them (although we'd probably also need to either suppress the edit builder adding its own, or ensure it can tell that the written types are covered by an existing import that isn't where the type is declared).

  2. added
    P3A lower priority bug or feature request
    on May 23, 2022
  3. bwilkerson commented on May 24, 2022

    @bwilkerson
    Member

    The problem is that the analysis server doesn't currently have any support for keeping track of which public libraries export symbols declared in internal libraries. The dartdoc package has support for this, but the code isn't currently in a form that can efficiently be shared, nor does it deal with changes to the code (rightly so because it's a command-line tool rather than a long lived server).

    Although we could special case this support for snippets, we need this information in lots of other places so I'd really prefer to just solve the problem once (most likely via DartEditBuilder) and share the solution across all of the features that need it.

    It's possible that we could compute the information efficiently enough that we wouldn't need to cache anything (we should only need to look at the public libraries in a package, and there often aren't very many of those). That would be idea. Otherwise we'll need a cache and a reliable way of determining when the cache needs to be flushed.

  4. fahami commented on Oct 21, 2022

    @fahami

    any progress for this issue?

  5. bwilkerson commented on Oct 21, 2022

    @bwilkerson
    Member

    Not that I'm aware of.

  6. Samleet commented on Nov 2, 2022

    @Samleet

    @DanTup This is a still a major issue. as it slows developing time. I'm really looking forward to this update.

  7. Blayneliu commented on Nov 27, 2022

    @Blayneliu

    I'm new to Flutter, but I found this issue annoying as this pops up every time when creating widget in new file. One workaround I'm using right now is adding import manually with some 3rd party snippet extension (details) first before running stlss.

  8. htetlynnhtun commented on Dec 5, 2022

    @htetlynnhtun

    We need a solution to this issue.

  9. Technorocker commented on Apr 20, 2023

    @Technorocker

    This is still doing this in vscode, is there a way to manually go change the snippet file to change the imports to material, very annoying when its the first snippet to show up in the context menu all the time

  10. DanTup commented on Apr 20, 2023

    @DanTup
    Collaborator

    There's no file you can modify as the imports don't come from a file but are inserted automatically by the Dart analysis server when references to types are added by the snippet.

    This issue has been fixed, but the fix has not yet shipped in a stable release of Flutter. It is available on the Flutter beta channel and will be included in the next stable release.

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

    P3A lower priority bug or feature requestdevexp-serverIssues related to some aspect of the analysis serverlegacy-area-analyzerUse area-devexp instead.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions