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
internal/imports: require valid options, move LocalPrefix up
CL 239754 eagerly initialized the environment. This turns out to be a
problem for gopls, which calls ApplyFixes with no ProcessEnv.
Reinitializing it every time seriously harmed the performance of
unimported completions. Move back to lazy initialization.
Working with invalid options has caused a lot of confusion; this is only
the most recent. We have to maintain backwards compatibility in the
externally visible API, but everywhere else we can require fully
populated options. That includes the source byte slice and the options.
LocalPrefix is really more of an Option than an attribute of the
ProcessEnv, and it is needed in ApplyFixes where we really don't want to
have to pass a ProcessEnv. Move it up to Options.
Change-Id: Ib9466c375a640a521721da4587091bf93bbdaa3c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241159
Run-TryBot: Heschi Kreinick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Rebecca Stambler <[email protected]>
Copy file name to clipboardExpand all lines: cmd/goimports/goimports.go
+5-2Lines changed: 5 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,7 @@ import (
21
21
"runtime/pprof"
22
22
"strings"
23
23
24
+
"golang.org/x/tools/internal/gocommand"
24
25
"golang.org/x/tools/internal/imports"
25
26
)
26
27
@@ -42,14 +43,16 @@ var (
42
43
TabIndent: true,
43
44
Comments: true,
44
45
Fragment: true,
45
-
Env: &imports.ProcessEnv{},
46
+
Env: &imports.ProcessEnv{
47
+
GocmdRunner: &gocommand.Runner{},
48
+
},
46
49
}
47
50
exitCode=0
48
51
)
49
52
50
53
funcinit() {
51
54
flag.BoolVar(&options.AllErrors, "e", false, "report all errors (not just the first 10 on different lines)")
52
-
flag.StringVar(&options.Env.LocalPrefix, "local", "", "put imports beginning with this string after 3rd-party packages; comma-separated list")
55
+
flag.StringVar(&options.LocalPrefix, "local", "", "put imports beginning with this string after 3rd-party packages; comma-separated list")
53
56
flag.BoolVar(&options.FormatOnly, "format-only", false, "if true, don't fix imports and only format. In this mode, goimports is effectively gofmt, with the addition that imports are grouped into sections.")
0 commit comments