Skip to content

Bug report: Auto complete doesn't add import to show clause #5238

Closed

Description

@Wdestroier

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:

  1. Write part of an existing class name and press the key to complete the class name
    image

  2. Press Enter to confirm and check it's not imported
    image

Expected behavior
The symbol should be imported and highlighted correctly.
image

  • Operating System and version: Windows 11 (Build 22631)
  • VS Code version: 1.92.2
  • Dart extension version: 3.94.0
  • Dart/Flutter SDK version: 3.94.0

Activity

  1. 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
  2. DanTup commented on Aug 28, 2024

    @DanTup
    Member

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

    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

  3. added
    in editorRelates to code editing or language features
    in lsp/analysis serverSomething to be fixed in the Dart analysis server
    on Aug 28, 2024
  4. added this to the v3.98.0 milestone on Aug 28, 2024
  5. FMorschel commented on Aug 30, 2024

    @FMorschel
    Contributor

    /fyi @DanTup this is related to dart-lang/sdk#54786

  6. FMorschel commented on Aug 30, 2024

    @FMorschel
    Contributor

    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

  7. DanTup commented on Sep 4, 2024

    @DanTup
    Member

    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.

  8. FMorschel commented on Sep 20, 2024

    @FMorschel
    Contributor

    I've also opened a PR that - has no specific relation to this issue, but it - involves updating the hide clause: dart-lang/sdk#56762.

  9. DanTup commented on Sep 23, 2024

    @DanTup
    Member

    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 writeType would collect the Element so 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 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.

  10. modified the milestones: v3.98.0, v3.100.0 on Sep 26, 2024
  11. modified the milestones: v3.100.0, On Deck on Oct 27, 2024
  12. FMorschel commented on Oct 31, 2024

    @FMorschel
    Contributor

    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!

  13. FMorschel commented on Jan 16, 2025

    @FMorschel
    Contributor
  14. Wdestroier commented on Jan 16, 2025

    @Wdestroier
    Author

    Thanks legend!

  15. FMorschel commented on Feb 3, 2025

    @FMorschel
    Contributor

    The CL got merged @DanTup. This will be available on a new Flutter/Dart SDK release, not Dart-Code.

  16. modified the milestones: On Deck, v3.106.0 on Feb 3, 2025
  17. DanTup commented on Feb 3, 2025

    @DanTup
    Member
  18. added
    relies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available
    on Feb 3, 2025
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

    in editorRelates to code editing or language featuresin lsp/analysis serverSomething to be fixed in the Dart analysis serveris bugrelies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions