You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug report: Auto complete doesn't add import to show clause #5238
Describe the bug
Completing a symbol name does not add it in the import show clause. Therefore, becoming very hard to use explicit imports with a show clause all the time.
Steps to reproduce the behavior:
Write part of an existing class name and press the key to complete the class name
Press Enter to confirm and check it's not imported
Expected behavior
The symbol should be imported and highlighted correctly.
Operating System and version: Windows 11 (Build 22631)
changed the title [-]Auto complete doesn't add import to show clause[/-][+]Bug report: Auto complete doesn't add import to show clause[/+]on Aug 27, 2024
Thanks, I can reproduce this. It appears when we try to automatically import the right library, we don't use knowledge of the Element we're trying to import, so we just accept any existing import, even if it wasn't showing the required Element.
I started on a fix, but realised it's a little more complicated than just providing the element, because these completions may add multiple imports (such as return types and parameter types if completing an override completion), so we're lacking some information in the resolution data (instead of an Element and a List<Uri>, we actually need a mapping of Uri to List<Element>).
Although those issues are similar, the implementation is quite different - the way code completion works and adds imports is very specific to how completion works so they'll need their own implementations.
I need to think a bit more about this... probably the fix is to do something in between, where we separate the main import URI (that is paired with the Element being imported), but keep additionalImportUris instead of element references for imports).
Long-term, it would might be better if things like writeType kept track of the types being written (not only the URIs) so that there's more information for things like completion to work with.
Just to inform, after some time working on this, I managed to close all the issues I mentioned being related above. After dart-lang/sdk#54786 this issue has a workaround fully functional (to the best of my knowledge) by using quick-fixes - at least on the latest master.
There are also some other QOL improvements from other issues I closed so hopefully this is easier to wait.
I'll also take a look at dart-lang/sdk#56608 as soon as I can so hopefully I can make this really work for you!
Activity
[-]Auto complete doesn't add import to show clause[/-][+]Bug report: Auto complete doesn't add import to show clause[/+]DanTup commentedon Aug 28, 2024
Thanks, I can reproduce this. It appears when we try to automatically import the right library, we don't use knowledge of the Element we're trying to import, so we just accept any existing import, even if it wasn't
showing the required Element.I started on a fix, but realised it's a little more complicated than just providing the element, because these completions may add multiple imports (such as return types and parameter types if completing an
overridecompletion), so we're lacking some information in the resolution data (instead of anElementand aList<Uri>, we actually need a mapping ofUritoList<Element>).I'll try to come back to this soon. For my reference, the work I started is at https://github.com/DanTup/sdk/tree/auto-import-completions-show-combinator-dc-5238 / DanTup/sdk@ec69a37
FMorschel commentedon Aug 30, 2024
/fyi @DanTup this is related to dart-lang/sdk#54786
FMorschel commentedon Aug 30, 2024
Also somewhat related dart-lang/sdk#36737
Edit
Just so you don't get a third email hahaha.
Also somewhat related dart-lang/sdk#30503
DanTup commentedon Sep 4, 2024
Although those issues are similar, the implementation is quite different - the way code completion works and adds imports is very specific to how completion works so they'll need their own implementations.
I started working on this, but found some other snags along the way. I've got some other fixes open (https://dart-review.googlesource.com/c/sdk/+/383322 and https://dart-review.googlesource.com/c/sdk/+/383260) and once they've landed, I'll come back to this.
FMorschel commentedon Sep 20, 2024
I've also opened a PR that - has no specific relation to this issue, but it - involves updating the
hideclause: dart-lang/sdk#56762.DanTup commentedon Sep 23, 2024
I got a bit further with this (https://github.com/DanTup/sdk/tree/auto-import-completions-show-combinator-dc-5238 / DanTup/sdk@73e9f59) however it broke some other tests due to bad assumptions I made (that
writeTypewould collect theElementso we could use "additionalElementReferences" for imports).I need to think a bit more about this... probably the fix is to do something in between, where we separate the main import URI (that is paired with the
Elementbeing imported), but keepadditionalImportUrisinstead of element references for imports).Long-term, it would might be better if things like
writeTypekept track of the types being written (not only the URIs) so that there's more information for things like completion to work with.FMorschel commentedon Oct 31, 2024
Just to inform, after some time working on this, I managed to close all the issues I mentioned being related above. After dart-lang/sdk#54786 this issue has a workaround fully functional (to the best of my knowledge) by using quick-fixes - at least on the latest master.
There are also some other QOL improvements from other issues I closed so hopefully this is easier to wait.
I'll also take a look at dart-lang/sdk#56608 as soon as I can so hopefully I can make this really work for you!
[DAS] Fix auto complete update combinators
FMorschel commentedon Jan 16, 2025
@Wdestroier, I've opened a CL to fix this: https://dart-review.googlesource.com/c/sdk/+/404525.
Wdestroier commentedon Jan 16, 2025
Thanks legend!
[DAS] Fix auto-complete update combinators
FMorschel commentedon Feb 3, 2025
The CL got merged @DanTup. This will be available on a new Flutter/Dart SDK release, not Dart-Code.
DanTup commentedon Feb 3, 2025
Fixed by dart-lang/sdk@6de0ef3, thanks @FMorschel!