internal/lsp/source: always use default goimports options

No point in constructing the defaults in three places.

Change-Id: I2b0776910a933a7250245bd82dc27e63c34df18a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212632
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/internal/lsp/cache/view.go b/internal/lsp/cache/view.go
index cd0893b..8b9e024 100644
--- a/internal/lsp/cache/view.go
+++ b/internal/lsp/cache/view.go
@@ -171,7 +171,7 @@
 	}
 }
 
-func (v *view) RunProcessEnvFunc(ctx context.Context, fn func(*imports.Options) error, opts *imports.Options) error {
+func (v *view) RunProcessEnvFunc(ctx context.Context, fn func(*imports.Options) error) error {
 	v.mu.Lock()
 	defer v.mu.Unlock()
 	if v.processEnv == nil {
@@ -187,7 +187,17 @@
 	}
 
 	// Run the user function.
-	opts.Env = v.processEnv
+	opts := &imports.Options{
+		// Defaults.
+		AllErrors:  true,
+		Comments:   true,
+		Fragment:   true,
+		FormatOnly: false,
+		TabIndent:  true,
+		TabWidth:   8,
+		Env:        v.processEnv,
+	}
+
 	if err := fn(opts); err != nil {
 		return err
 	}
diff --git a/internal/lsp/source/format.go b/internal/lsp/source/format.go
index c2afd16..e11e2cd 100644
--- a/internal/lsp/source/format.go
+++ b/internal/lsp/source/format.go
@@ -98,19 +98,10 @@
 	if hasListErrors(pkg) {
 		return nil, nil, errors.Errorf("%s has list errors, not running goimports", fh.Identity().URI)
 	}
-	options := &imports.Options{
-		// Defaults.
-		AllErrors:  true,
-		Comments:   true,
-		Fragment:   true,
-		FormatOnly: false,
-		TabIndent:  true,
-		TabWidth:   8,
-	}
 	err = snapshot.View().RunProcessEnvFunc(ctx, func(opts *imports.Options) error {
 		allFixEdits, editsPerFix, err = computeImportEdits(ctx, snapshot.View(), pgh, opts)
 		return err
-	}, options)
+	})
 	if err != nil {
 		return nil, nil, errors.Errorf("computing fix edits: %v", err)
 	}
@@ -317,23 +308,13 @@
 	ctx, done := trace.StartSpan(ctx, "source.CandidateImports")
 	defer done()
 
-	options := &imports.Options{
-		// Defaults.
-		AllErrors:  true,
-		Comments:   true,
-		Fragment:   true,
-		FormatOnly: false,
-		TabIndent:  true,
-		TabWidth:   8,
-	}
-
 	var imps []imports.ImportFix
 	importFn := func(opts *imports.Options) error {
 		var err error
 		imps, err = imports.GetAllCandidates(ctx, prefix, filename, opts)
 		return err
 	}
-	err := view.RunProcessEnvFunc(ctx, importFn, options)
+	err := view.RunProcessEnvFunc(ctx, importFn)
 	return imps, err
 }
 
@@ -343,23 +324,13 @@
 	ctx, done := trace.StartSpan(ctx, "source.PackageExports")
 	defer done()
 
-	options := &imports.Options{
-		// Defaults.
-		AllErrors:  true,
-		Comments:   true,
-		Fragment:   true,
-		FormatOnly: false,
-		TabIndent:  true,
-		TabWidth:   8,
-	}
-
 	var pkgs []imports.PackageExport
 	importFn := func(opts *imports.Options) error {
 		var err error
 		pkgs, err = imports.GetPackageExports(ctx, pkg, filename, opts)
 		return err
 	}
-	err := view.RunProcessEnvFunc(ctx, importFn, options)
+	err := view.RunProcessEnvFunc(ctx, importFn)
 	return pkgs, err
 }
 
diff --git a/internal/lsp/source/view.go b/internal/lsp/source/view.go
index 0847f6c..af05e1c 100644
--- a/internal/lsp/source/view.go
+++ b/internal/lsp/source/view.go
@@ -110,9 +110,9 @@
 	// Config returns the configuration for the view.
 	Config(ctx context.Context) *packages.Config
 
-	// RunProcessEnvFunc runs fn with the process env for this view inserted into opts.
+	// RunProcessEnvFunc runs fn with the process env for this view.
 	// Note: the process env contains cached module and filesystem state.
-	RunProcessEnvFunc(ctx context.Context, fn func(*imports.Options) error, opts *imports.Options) error
+	RunProcessEnvFunc(ctx context.Context, fn func(*imports.Options) error) error
 
 	// Options returns a copy of the Options for this view.
 	Options() Options