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

Bad autocompletion for type inside import alias when declaring a function inside a class #59865

Open
stephane-archer opened this issue Jan 8, 2025 · 9 comments
Labels
analyzer-completion Issues with the analysis server's code completion feature area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.

Comments

@stephane-archer
Copy link

output.17.33.13.mov
import 'package:image/image.dart' as img;
@stephane-archer stephane-archer added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Jan 8, 2025
@bwilkerson
Copy link
Member

I'm guessing that you're referring to the suggestion of fun as a completion after img..

Can you provide a small reproduction?

@bwilkerson bwilkerson added the analyzer-completion Issues with the analysis server's code completion feature label Jan 8, 2025
@stephane-archer
Copy link
Author

@bwilkerson yes

import 'package:image/image.dart' as img;

class A {
  img.
}

@stephane-archer
Copy link
Author

Screenshot 2025-01-08 at 21 09 05 Screenshot 2025-01-08 at 21 09 09

@FMorschel
Copy link
Contributor

FMorschel commented Jan 8, 2025

Hover when it is detected to be an alias:

image

Hover int when detected to be a member name:

image

Hover img without . (same as for int above):

image

Hover img. (I think it is considering this as a constructor for some reason):

image


Edit

So @bwilkerson I`m not 100% sure this is an auto-complete issue necessarily but actually a parsing error which leads to this. Not sure if we have a tag for that.

@stephane-archer
Copy link
Author

I think looking at this particular example img. should suggest things declared inside package:image/image.dart regardless of any parsing error. I don't expect the autocomplete to stop working because I forgot a ;

@bwilkerson
Copy link
Member

I agree. We ought to have recovered well enough to be able to have reasonable suggestions there. I haven't had time to look into why completion is failing in this particular case, but I doubt it's because of a missing semicolon.

@FMorschel
Copy link
Contributor

FMorschel commented Jan 8, 2025

I think looking at this particular example img. should suggest things declared inside package:image/image.dart regardless of any parsing error. I don't expect the autocomplete to stop working because I forgot a ;

@stephane-archer just so I'm clear, I agree. My comment was about it not identifying img as an alias and that would be the reason for the suggestions not showing up.

The parsing needs to identify it as an alias for the auto-completion to work. If you had for example:

import 'package:image/image.dart' as img;

class A {
  void foo(int img) { // I know this naming makes no sense but bear with me
    img.^
  }
}

Inside A.foo, dart considers int img as having a higher priority for this scope so auto-completion would show only methods/proprieties for an int and not things from the import.

The parser does the job of identifying what img means in that scope. That is why I meant this
is actually a parser problem that leads to bad auto-completion.


@bwilkerson I'll take a look at this when I have some time too. If I find anything I'll update it here.

@bwilkerson
Copy link
Member

Technically, it isn't a parser problem. The parser only verifies that the code conforms to the grammar; it doesn't do any resolution, that's done by the resolver.

But either way, completion should work even when there's incomplete information.

@stephane-archer
Copy link
Author

@FMorschel I agree with you. In your example img. should show the int method rather than the definition from 'package:image/image.dart' but in the case of the parser being lost, showing methods for each symbol that can match the identifier is better than showing nothing. In our example the autocomplete is just lost and shows nothing. Heping the autocomplete to not be lost would be great, but a better default behavior might be nice too.
I imagine is easy to get the parser lost because the code is not yet in the correct shape.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-completion Issues with the analysis server's code completion feature area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
Projects
None yet
Development

No branches or pull requests

3 participants