gopls: add codelens to reset upgrade diagnostics

This clears the diagnostics that were added by the `Check for
upgrades` codelens for the given go.mod file. The diagnostic
source for the diagnostics from `Check for upgrades` is now
modCheckUpgradesSource instead of modSource in order to allow
us to easily clear these diagnostics.

Fixes golang/go#54065

Change-Id: I7c0824ce1fdfcf2a73ec83342501ceed82fc519f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/426016
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
diff --git a/gopls/internal/lsp/source/api_json.go b/gopls/internal/lsp/source/api_json.go
index 56f7c0f..6231507 100755
--- a/gopls/internal/lsp/source/api_json.go
+++ b/gopls/internal/lsp/source/api_json.go
@@ -741,6 +741,12 @@
 			ArgDoc:  "{\n\t// The go.mod file URI.\n\t\"URI\": string,\n\t// The module path to remove.\n\t\"ModulePath\": string,\n\t\"OnlyDiagnostic\": bool,\n}",
 		},
 		{
+			Command: "gopls.reset_go_mod_diagnostics",
+			Title:   "Reset go.mod diagnostics",
+			Doc:     "Reset diagnostics in the go.mod file of a module.",
+			ArgDoc:  "{\n\t// The file URI.\n\t\"URI\": string,\n}",
+		},
+		{
 			Command: "gopls.run_tests",
 			Title:   "Run test(s)",
 			Doc:     "Runs `go test` for a specific set of test or benchmark functions.",
diff --git a/gopls/internal/lsp/source/view.go b/gopls/internal/lsp/source/view.go
index 8bf0344..47f463e 100644
--- a/gopls/internal/lsp/source/view.go
+++ b/gopls/internal/lsp/source/view.go
@@ -21,10 +21,10 @@
 	"golang.org/x/mod/module"
 	"golang.org/x/tools/go/analysis"
 	"golang.org/x/tools/go/packages"
-	"golang.org/x/tools/internal/gocommand"
-	"golang.org/x/tools/internal/imports"
 	"golang.org/x/tools/gopls/internal/lsp/progress"
 	"golang.org/x/tools/gopls/internal/lsp/protocol"
+	"golang.org/x/tools/internal/gocommand"
+	"golang.org/x/tools/internal/imports"
 	"golang.org/x/tools/internal/span"
 )
 
@@ -267,6 +267,9 @@
 	// required by modfile.
 	RegisterModuleUpgrades(modfile span.URI, upgrades map[string]string)
 
+	// ClearModuleUpgrades clears all upgrades for the modules in modfile.
+	ClearModuleUpgrades(modfile span.URI)
+
 	// FileKind returns the type of a file
 	FileKind(FileHandle) FileKind
 }