gopls/internal/lsp/cache: move SuggestedFixFromCommand into cache

Change-Id: Id468b7b2749bae70430bcde70a1d3c5ceaaa92f8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/543919
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
diff --git a/gopls/internal/lsp/cache/diagnostics.go b/gopls/internal/lsp/cache/diagnostics.go
new file mode 100644
index 0000000..e7c2ca7
--- /dev/null
+++ b/gopls/internal/lsp/cache/diagnostics.go
@@ -0,0 +1,16 @@
+// Copyright 2023 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package cache
+
+import "golang.org/x/tools/gopls/internal/lsp/protocol"
+
+// SuggestedFixFromCommand returns a suggested fix to run the given command.
+func SuggestedFixFromCommand(cmd protocol.Command, kind protocol.CodeActionKind) SuggestedFix {
+	return SuggestedFix{
+		Title:      cmd.Title,
+		Command:    &cmd,
+		ActionKind: kind,
+	}
+}
diff --git a/gopls/internal/lsp/cache/errors.go b/gopls/internal/lsp/cache/errors.go
index 5620b05..e99f670 100644
--- a/gopls/internal/lsp/cache/errors.go
+++ b/gopls/internal/lsp/cache/errors.go
@@ -198,7 +198,7 @@
 	if err != nil {
 		return nil, err
 	}
-	return []source.SuggestedFix{source.SuggestedFixFromCommand(cmd, protocol.QuickFix)}, nil
+	return []source.SuggestedFix{SuggestedFixFromCommand(cmd, protocol.QuickFix)}, nil
 }
 
 func editGoDirectiveQuickFix(moduleMode bool, uri protocol.DocumentURI, version string) ([]source.SuggestedFix, error) {
@@ -214,7 +214,7 @@
 	if err != nil {
 		return nil, err
 	}
-	return []source.SuggestedFix{source.SuggestedFixFromCommand(cmd, protocol.QuickFix)}, nil
+	return []source.SuggestedFix{SuggestedFixFromCommand(cmd, protocol.QuickFix)}, nil
 }
 
 // encodeDiagnostics gob-encodes the given diagnostics.
@@ -366,7 +366,7 @@
 				log.Fatalf("internal error in NewApplyFixCommand: %v", err)
 			}
 			for _, kind := range kinds {
-				fixes = append(fixes, source.SuggestedFixFromCommand(cmd, kind))
+				fixes = append(fixes, SuggestedFixFromCommand(cmd, kind))
 			}
 		}
 		diag.SuggestedFixes = fixes
diff --git a/gopls/internal/lsp/cache/pkg.go b/gopls/internal/lsp/cache/pkg.go
index b06ddf2..2ab4694 100644
--- a/gopls/internal/lsp/cache/pkg.go
+++ b/gopls/internal/lsp/cache/pkg.go
@@ -75,7 +75,6 @@
 	RemoveIntermediateTestVariants = source.RemoveIntermediateTestVariants
 	IsCommandLineArguments         = source.IsCommandLineArguments
 	BundleQuickFixes               = source.BundleQuickFixes
-	SuggestedFixFromCommand        = source.SuggestedFixFromCommand
 	ToProtocolEdits                = source.ToProtocolEdits
 	NewFilterer                    = source.NewFilterer
 )
diff --git a/gopls/internal/lsp/mod/diagnostics.go b/gopls/internal/lsp/mod/diagnostics.go
index fafe684..d524134 100644
--- a/gopls/internal/lsp/mod/diagnostics.go
+++ b/gopls/internal/lsp/mod/diagnostics.go
@@ -173,7 +173,7 @@
 			Severity:       protocol.SeverityInformation,
 			Source:         source.UpgradeNotification,
 			Message:        fmt.Sprintf("%v can be upgraded", req.Mod.Path),
-			SuggestedFixes: []source.SuggestedFix{source.SuggestedFixFromCommand(cmd, protocol.QuickFix)},
+			SuggestedFixes: []source.SuggestedFix{cache.SuggestedFixFromCommand(cmd, protocol.QuickFix)},
 		})
 	}
 
@@ -274,7 +274,7 @@
 				if err != nil {
 					return nil, err // TODO: bug report
 				}
-				sf := source.SuggestedFixFromCommand(cmd, protocol.QuickFix)
+				sf := cache.SuggestedFixFromCommand(cmd, protocol.QuickFix)
 				switch _, typ := foundVuln(finding); typ {
 				case vulnImported:
 					infoFixes = append(infoFixes, sf)
@@ -301,7 +301,7 @@
 		if err != nil {
 			return nil, err // TODO: bug report
 		}
-		sf := source.SuggestedFixFromCommand(latest, protocol.QuickFix)
+		sf := cache.SuggestedFixFromCommand(latest, protocol.QuickFix)
 		if len(warningFixes) > 0 {
 			warningFixes = append(warningFixes, sf)
 		}
@@ -454,7 +454,7 @@
 		if err != nil {
 			return source.SuggestedFix{}, err
 		}
-		return source.SuggestedFixFromCommand(resetVulncheck, protocol.QuickFix), nil
+		return cache.SuggestedFixFromCommand(resetVulncheck, protocol.QuickFix), nil
 	}
 	vulncheck, err := command.NewRunGovulncheckCommand("Run govulncheck to verify", command.VulncheckArgs{
 		URI:     uri,
@@ -463,7 +463,7 @@
 	if err != nil {
 		return source.SuggestedFix{}, err
 	}
-	return source.SuggestedFixFromCommand(vulncheck, protocol.QuickFix), nil
+	return cache.SuggestedFixFromCommand(vulncheck, protocol.QuickFix), nil
 }
 
 func getVulnMessage(mod string, vulns []string, used, fromGovulncheck bool) string {
diff --git a/gopls/internal/lsp/source/fix.go b/gopls/internal/lsp/source/fix.go
index 2725754..b44a25d 100644
--- a/gopls/internal/lsp/source/fix.go
+++ b/gopls/internal/lsp/source/fix.go
@@ -94,14 +94,6 @@
 	}
 }
 
-func SuggestedFixFromCommand(cmd protocol.Command, kind protocol.CodeActionKind) SuggestedFix {
-	return SuggestedFix{
-		Title:      cmd.Title,
-		Command:    &cmd,
-		ActionKind: kind,
-	}
-}
-
 // CanFix returns true if Analyzer.Fix can fix the Diagnostic.
 //
 // It returns true by default: only if the analyzer is configured explicitly to