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
In certain circumstances where a Go package can be imported from different fully qualified name like assert or require, I notice different behavior between auto-import and Ctrl+Space suggestion.
The specific case I face the most often is that I write a unit test, I add require or assert statement like assert.Equal(...) then when I save, the "wrong" import is added (I say wrong just because it's not the one I wanted).
If I instead write assert.Equal(...) then place my cursor right after assert (between t and .) then I do Ctrl+Space to see suggestions, then the first listed is the one I would like to actually use. It could be a coincidence and they are simply alphabetically sorted.
So I was wondering what is the way auto-import decides which import to pick to resolve a particular package? Is there anyway currently to "tweak" this behavior a bit maybe provide a list of my preferred resolution?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In certain circumstances where a Go package can be imported from different fully qualified name like
assert
orrequire
, I notice different behavior between auto-import andCtrl+Space
suggestion.The specific case I face the most often is that I write a unit test, I add
require
orassert
statement likeassert.Equal(...)
then when I save, the "wrong" import is added (I say wrong just because it's not the one I wanted).If I instead write
assert.Equal(...)
then place my cursor right afterassert
(betweent
and.
) then I doCtrl+Space
to see suggestions, then the first listed is the one I would like to actually use. It could be a coincidence and they are simply alphabetically sorted.So I was wondering what is the way
auto-import
decides which import to pick to resolve a particular package? Is there anyway currently to "tweak" this behavior a bit maybe provide a list of my preferred resolution?Beta Was this translation helpful? Give feedback.
All reactions