Skip to content

Add an option to always show libraries against completions even if they're already in-scope and won't add an import #5239

Open

Description

@Wdestroier

Describe the bug
Symbol doesn't show where it is from.

To Reproduce

  1. Write part of a class name and press the key to complete its name
  2. Check the symbol location missing in the hint
    image

Expected behavior
The hint must show from where the symbol is from
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 [-]Symbols don't always show from where they are from[/-] [+]Bug report: Symbols don't always show from where they are from[/+] on Aug 27, 2024
  2. DanTup commented on Aug 28, 2024

    @DanTup
    Member

    This is working as intended - the packages shown here in completion are actually auto-imports, they are indicating that if you choose this item it will add a new import for that library to your file. If there is no package listed, it means the one that is already in-scope in your file (there should only ever be one of these).

    It's true that this probably isn't very obvious, but I think having this distinction is quite useful. Perhaps we should include the source library at least in the documentation part like we do in hovers?

    image

  3. added
    is enhancement
    and removed on Aug 28, 2024
  4. changed the title [-]Bug report: Symbols don't always show from where they are from[/-] [+]Show which library completion items come from even if they are in-scope[/+] on Aug 28, 2024
  5. added this to the On Deck milestone on Aug 28, 2024
  6. added
    in editor
    in lsp/analysis server
    on Aug 28, 2024
  7. Wdestroier commented on Aug 28, 2024

    @Wdestroier
    Author

    Thanks Dan!

    It's a little difficult to distinguish imported symbols from macro completions, keywords and other classes I didn't really want to import, but were exported from the library I imported other classes. I just noticed the icons are different:
    image

    Could the hint say "Already imported" or "Already imported from package:abc/abc.dart"?

  8. DanTup commented on Aug 28, 2024

    @DanTup
    Member

    I do slightly worry about making the completion list look really busy. Currently a lot of the items in completion tend to be already imported, so there's often a lot of space on the right:

    image

    If all items had text on the right, I think it would be a lot noisier and I wonder if that's worth it just to make this clearer (versus something like just having it in the extra popup, as noted in the comment above).

    Maybe we could collect some more opinions on this issue and see what others think?

  9. added
    your feedback wanted!
    on Aug 28, 2024
  10. Wdestroier commented on Aug 28, 2024

    @Wdestroier
    Author

    Another alternative could be if VSCode could textually tell me what the symbols mean, for example: class, variable or unknown symbol. I will search for this feature. Collecting feedback is a cool idea too.

  11. abitofevrything commented on Aug 28, 2024

    @abitofevrything

    I would personally prefer to omit the library name from already imported symbols (and also to not have an "Already imported" text). The information is implicit anyway and it avoids noise.

    If you really want to know what library a symbol is from, you can use jump to definition to find out.

  12. DanTup commented on Aug 28, 2024

    @DanTup
    Member

    @Wdestroier

    Another alternative could be if VSCode could textually tell me what the symbols mean, for example: class, variable or unknown symbol.

    If by "symbol" here you mean the icon, there isn't currently one for unimported items, because unimported items can by class, variable, etc. - so using the icon (CompletionItemKind) to indicate it's not imported would lose some information.

    We can attach CompletionItemTags to completions - currently VS Code only defines one - Deprecated. If it had an additional tag for "Unimported" (or similar), we could provide that, and then it could adjust the UI to indicate this somehow (for example an overlay over the icon or something?). Whether they'd be open to that, I don't know.

  13. FMorschel commented on Aug 29, 2024

    @FMorschel
    Contributor

    If it had an additional tag for "Unimported" (or similar), we could provide that, and then it could adjust the UI to indicate this somehow

    I like this one a little better.

    I see the point of showing the library because of name shadowing:

    image

    Maybe this is a valid case for it to show the library in the right anyway (created #5242 for the missing i.MyClassName option in the list. No matter if I have the import aliased or not have the import at all, I could not make the import show the MyClassName from my_class_name.dart without adding the i. in front - not even to suggest adding a new import).

  14. Wdestroier commented on Aug 29, 2024

    @Wdestroier
    Author

    I checked how it works in IntelliJ:

    Before a class is imported in IntelliJ for the first time:
    image

    When an already imported class is being completed again:
    image

    I feel more confident I'm using the correct class. Could this be a toggleable option (disabled by default)? The icons look more meaningful too.

  15. Wdestroier commented on Aug 29, 2024

    @Wdestroier
    Author

    The icons look easier to understand too. I didn't know they could be changed by the extension.

    In VSCode we have
    a wrench icon (what is a wrench in Dart?) and a rectangular prism icon
    image
    an icon with 2 lists and a box icon
    image
    a rectangular prism icon
    image
    a branches icon, or a version control icon according to ChatGPT
    image
    the same icon for a class (https://github.com/dart-lang/sdk/blob/230c7ed90c1d7469b9f6a96ea9d566f36a054e34/sdk/lib/core/map.dart#L472)
    image

    Can these icons be customized to something simpler? Such as (C) for any class, (E) for any enum, (F) for any function, (M) for any method and so on?

  16. DanTup commented on Sep 2, 2024

    @DanTup
    Member

    The icons look easier to understand too. I didn't know they could be changed by the extension.

    Those icons above are IntelliJ, we can't change them in VS Code - they're controlled by VS Code (and/or the theme), we can only provide the kind of completion.

    Could this be a toggleable option (disabled by default)?

    If there's sufficient demand, we could do this - but there are already a lot of settings and each setting multiplies the number of different cases to maintain and test (and there are already multiple combinations of things here due to LSP capabilities for the labels) so it would be good to verify there's demand for this first. The easiest way to gauge this is for people to add 👍 s to this issue at the top (and feel free to add your own, I do! 😄).

    I'll update the title a little to make what's being proposed a bit clearer. I think probably if the setting was enabled, we should still add some indicator that a completion is an auto-import completion (for example putting a * next to the package name or something).

  17. changed the title [-]Show which library completion items come from even if they are in-scope[/-] [+]Add an option to always show libraries against completions even if they're already in-scope and won't add an import[/+] on Sep 2, 2024
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 editorin lsp/analysis serveris enhancementyour feedback wanted!

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions