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
Add an option to always show libraries against completions even if they're already in-scope and won't add an import #5239
in editorRelates to code editing or language featuresin lsp/analysis serverSomething to be fixed in the Dart analysis serveris enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.your feedback wanted!An issue with ideas that could do with feedback from more users to help decide on a solution
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
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?
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
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:
Could the hint say "Already imported" or "Already imported from package:abc/abc.dart"?
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:
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?
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.
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.
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.
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:
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).
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).
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
in editorRelates to code editing or language featuresin lsp/analysis serverSomething to be fixed in the Dart analysis serveris enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.your feedback wanted!An issue with ideas that could do with feedback from more users to help decide on a solution
Activity
[-]Symbols don't always show from where they are from[/-][+]Bug report: Symbols don't always show from where they are from[/+]DanTup commentedon Aug 28, 2024
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?
[-]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[/+]Wdestroier commentedon Aug 28, 2024
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:

Could the hint say "Already imported" or "Already imported from package:abc/abc.dart"?
DanTup commentedon Aug 28, 2024
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:
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?
Wdestroier commentedon Aug 28, 2024
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.
abitofevrything commentedon Aug 28, 2024
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.
DanTup commentedon Aug 28, 2024
@Wdestroier
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.FMorschel commentedon Aug 29, 2024
I like this one a little better.
I see the point of showing the library because of name shadowing:
Maybe this is a valid case for it to show the library in the right anyway (created #5242 for the missing
i.MyClassNameoption 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 theMyClassNamefrommy_class_name.dartwithout adding thei.in front - not even to suggest adding a new import).Wdestroier commentedon Aug 29, 2024
I checked how it works in IntelliJ:
Before a class is imported in IntelliJ for the first time:

When an already imported class is being completed again:

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.
Wdestroier commentedon Aug 29, 2024
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
an icon with 2 lists and a box icon
a rectangular prism icon
a branches icon, or a version control icon according to ChatGPT
the same icon for a class (https://github.com/dart-lang/sdk/blob/230c7ed90c1d7469b9f6a96ea9d566f36a054e34/sdk/lib/core/map.dart#L472)
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?
DanTup commentedon Sep 2, 2024
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.
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).[-]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[/+]