internal/lsp: add LocalPrefix configuration

Updates golang/go#32049

Change-Id: I64e5201170b5be8b470c436264e18e12ec8d12f2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/204820
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
diff --git a/internal/lsp/cache/view.go b/internal/lsp/cache/view.go
index 118a21d..ae3c9a5 100644
--- a/internal/lsp/cache/view.go
+++ b/internal/lsp/cache/view.go
@@ -185,7 +185,8 @@
 		Logf: func(format string, args ...interface{}) {
 			log.Print(ctx, fmt.Sprintf(format, args...))
 		},
-		Debug: true,
+		LocalPrefix: v.options.LocalPrefix,
+		Debug:       true,
 	}
 	for _, kv := range cfg.Env {
 		split := strings.Split(kv, "=")
diff --git a/internal/lsp/source/options.go b/internal/lsp/source/options.go
index 8a00930..b69d9fa 100644
--- a/internal/lsp/source/options.go
+++ b/internal/lsp/source/options.go
@@ -105,6 +105,9 @@
 	ComputeEdits diff.ComputeEdits
 
 	Analyzers []*analysis.Analyzer
+
+	// LocalPrefix is used to specify goimports's -local behavior.
+	LocalPrefix string
 }
 
 type CompletionOptions struct {
@@ -243,7 +246,7 @@
 	case "hoverKind":
 		hoverKind, ok := value.(string)
 		if !ok {
-			result.errorf("Invalid type %T for string option %q", value, name)
+			result.errorf("invalid type %T for string option %q", value, name)
 			break
 		}
 		switch hoverKind {
@@ -278,6 +281,14 @@
 	case "go-diff":
 		result.setBool(&o.GoDiff)
 
+	case "local":
+		localPrefix, ok := value.(string)
+		if !ok {
+			result.errorf("invalid type %T for string option %q", value, name)
+			break
+		}
+		o.LocalPrefix = localPrefix
+
 	// Deprecated settings.
 	case "wantSuggestedFixes":
 		result.State = OptionDeprecated