-
Notifications
You must be signed in to change notification settings - Fork 645
Intentional choice to not collapse imports? #374
Comments
@benclarkwood import "fmt" Then I added import (
"fmt"
"math"
) The auto imports do get collapsed. |
@ramya-rao-a While it does work like that sometimes, I can easily get vscode-go into a state where subsequent imports are added one-by-one, i.e. import "fmt"
import "math"
import "os" IMO there's no reason not to use the import grouping form all the time. That is, even when I just have a single import, I want it to look like import (
"fmt"
) Perhaps we can change it to simply have this behavior? |
@ramya-rao-a sorry I didn't include proper repro steps before. Here is a repro that always causes the failure to collapse for me:
As @peterbourgon suggested, the "simplest" (and arguably best/most consistent) solution is to just always use the
block style for imports. I'll take a look at what has to change in goImport.ts for that and submit a PR against this ticket. |
@benclarkwood @peterbourgon Sorry, I saw the word "goImport" and my brain mapped it to "goimports" the formatting tool and thought the problem was with the imports that get added when formatting is triggered. At the moment, any new import added via the I think this was intentional so that if someone has separate imports to begin with, the status quo is maintained. @lukehoban Can you confirm? You could add a setting which when true will always collapse the imports even if the current file has multiple import statements. |
If you have more than 1 import then you always want them grouped. // Always this.
import (
"fmt"
"os"
)
// Never this.
import "fmt"
import "os" If you have only 1 import then it can be without parens, but there's no reason it needs to be. // This is fine.
import "fmt"
// But this is no less correct.
import (
"fmt"
) |
@ramya-rao-a as you said, I think the right approach is for my change to be wrapped in a setting (default == false) that when true gives @peterbourgon and I what we want (always block imports) and when false maintains the current status quo. Which is what I shall endeavor to do :). |
So, I took a quick (and a little bit slapdash) stab at this. AFAICT, the only way to end up with many single line imports is:
With the flag enabled, both #1 and #2 should no longer occur. The new behavior (with go.blockImportsOnly == true) is: File with no imports:
File with one or more single line imports
File that already has an import block
|
The linked PR has been merged and this change will be out in the next update |
This is now out in the latest update to the Go extension (0.6.72) |
I love the auto import features of vscode-go, but it always bugs me that I can wind up in scenarios where the imports aren't collapsed into a
statement instead. I'd like to change goImport.ts to handle this collapsing. I can wrap it in a setting if that is more amenable.
The text was updated successfully, but these errors were encountered: