Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong imports in Stateless Widget snippet from analysis server #49081

Closed
nickmeinhold opened this issue May 23, 2022 · 9 comments
Closed

Wrong imports in Stateless Widget snippet from analysis server #49081

nickmeinhold opened this issue May 23, 2022 · 9 comments
Labels
analyzer-server area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request

Comments

@nickmeinhold
Copy link

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"
@DanTup DanTup added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-server labels May 23, 2022
@DanTup
Copy link
Collaborator

DanTup commented May 23, 2022

@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).

@bwilkerson
Copy link
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.

@fahami
Copy link

fahami commented Oct 21, 2022

any progress for this issue?

@bwilkerson
Copy link
Member

Not that I'm aware of.

@Samleet
Copy link

Samleet commented Nov 2, 2022

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

@Blayneliu
Copy link

Blayneliu commented Nov 27, 2022

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.

@htetlynnhtun
Copy link

We need a solution to this issue.

@Technorocker
Copy link

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

@DanTup
Copy link
Collaborator

DanTup commented Apr 20, 2023

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
Labels
analyzer-server area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request
Projects
None yet
Development

No branches or pull requests

9 participants