-
Notifications
You must be signed in to change notification settings - Fork 648
"Format Code" imports wrong package #109
Comments
This doesn't really have anything to do with vscode-go but rather goimports. I also don't see how goimports can make a decision about which is the correct import. |
Yeah, I wasn't sure if it's a vscode-go thing or goimports. But still, imo it would be more logical to first try to import the package from the same app. |
What do you mean "same app"? |
I'll try to explain a bit more clearly: I have 2 db packages, one in app1 and one in app2. Simplified code - in reality they're not exactly the same, just similar, but both have the
package db
var X *whatever
func (x *whatever) Test() {
...
}
package db
var X *whatever
func (x *whatever) Test() {
...
} Now if I write a code in
like this: package main
func main() {
db.X.Test()
} And then using "Format Code" will import the |
Thanks @ivoviz. This does appear to be arguably a bug in I see a few bugs over there that are still active that are likely related, including golang/go#9197. I'm going to close the issue out here since we are relying on the existing Go tools for this so we have to accept their behaviour. |
Let's say I have a structure like this (in the
src
folder, obviously):Let's also assume that both
app1
andapp2
has a package calleddb
. Now I haven't really tested out when does the import work properly and when not (just came here to report the issue asap), but in my case I have used thedb
package inapp2
, then used "Format Code". After half an hour I realized it imported the package fromapp1
.In my case both
db
packages were similar - not exactly the same -, but they both had that exact function.The text was updated successfully, but these errors were encountered: