-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Widget snippets generate unused import #56627
Comments
Summary: Flutter widget snippets in version 3.24 generate an unused import of |
Since we had issues like this in the past, perhaps we should have the Flutter team communicate if a change could "break" a snippet? Having the snippets need to pass static analysis might also catch this. |
Should the Flutter team be the ones adding the Flutter snippets to the Flutter SDK version of the analyzer, instead of the analyzer in the Dart SDK containing (generators for) code that can't be tested with just the Dart SDK? |
I don't seem to be able to reproduce this in 3.24.1 in an empty file: snippet.mp4The imports aren't hard-coded, but are computed by the server from the types that are referenced in the snippets (there are many places where we might write a reference to a type and need to import it, so there is code to determine the "best" import to add - eg. we don't want to import the real @navaronbracke is it possible you could capture a log while reproducing this? Ideally in a new project (to minimize differences between us):
Thanks!
Currently there's no mechanism for snippets that aren't built into the server (written in Dart). Probably the ideal solution is that any package can provide snippets - there's an issue for that at #32103, although it only has three 👍 's so far so I don't know how much demand there is from 3p packages. |
Looking back at my video, cupertino also seems an odd (though valid) choice here. I wonder if snippets should have some preferred imports that are added first (or whether there's some way a package could express some preference for which libraries to prefer). |
@DanTup I also cannot reproduce it on a new project. Strangely enough the project that I reproduced it with was upgraded to Flutter 3.24.0 (I can still repro it there, though) Edit: I just now updated that project's pubspec from (My local Flutter checkout was up to date for 3.24.1 though) |
If you mean you updated the I wonder if some server state caused us to enumerate the libraries in a different order and that resulted in us adding different imports. I can't see any obvious reason for this, though I do see that we discover files in the server using Out of interest, when you try now - does it select the same |
I never had any snippets provide cupertino imports. That said, I did an SDK upgrade to Flutter 3.24.2 / Dart 3.5.2 and the bug reappeared in that old project. I did capture the log this time: I can't really tell why an existing project would be affected, but a new one isn't. (although the existing project was originally created a while back and had a few SDK upgrades since, so it's not a "fresh" workspace) |
Thanks, the logs show a file being opened (
When I try to reproduce on 3.42.2 I get different imports, but ones that produce the same problem:
The first import is added as we try to resolve Some ideas:
One slight concern I have is that these edits are all built in-line when computing code completions (these edits are not delayed until @bwilkerson any thoughts about this? |
I don't have a definitive answer, but yes, I have thoughts. :-)
That's an interesting optimization. I don't know how often snippets are causing performance problems, though, so I don't know whether it's a problem worth solving. @keertip Something to keep in mind as we start to look at the performance of completion post-refactoring. |
The first part is correct, we do check existing pending imports to see if they cover the new element, but we don't check if any existing imports may now be redundant. We'd need to store some additional info against pending imports for this (because we can only remove a pending import if it's only being used to provide those elements, and the caller hasn't explicitly called I think doing this might be the nicest solution though - it does mean a bit more looping as we're adding imports, but given the number of imports being added is likely very small, it's probably significantly less than the existing work to locate a non-src import, for example. I'll try doing this.
We did have some reports of perf issues here in the past (because each snippet would perform some of the same work) which we solved in 092bdb1. I don't know of any complaints since then so perhaps it's not worth changing now, but it's something to keep in mind (we don't build the edits up-front for other kinds of completions as they're handled via |
The
stateless/stateful/animation controller widget
snippets generate an unused import in Flutter 3.24, so I think that the snippets should be updated. (might need to determine when the foundation import was made obsolete for the snippet)For example, given an empty Dart file, selecting the stateless snippet generates
If you then run
dart analyze
on the snippet, you getUnused import: 'package:flutter/foundation.dart'. Try removing the import directive. • unused_import
Related issue: #49081
Flutter Doctor
The text was updated successfully, but these errors were encountered: