internal/lsp: fix bad `go mod tidy` quick fix title

Also, catch a potential nil pointer in the go.mod parsing code and a
typo.

Fixes golang/go#40659

Change-Id: Ic0adc8025a0d657cf713a101c333f28c15275f2b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/248037
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/internal/lsp/cache/mod.go b/internal/lsp/cache/mod.go
index 89b7f96..dfa1f4f 100644
--- a/internal/lsp/cache/mod.go
+++ b/internal/lsp/cache/mod.go
@@ -71,11 +71,16 @@
 		}
 		data.parsed.File, data.err = modfile.Parse(modFH.URI().Filename(), contents, nil)
 		if data.err != nil {
-			// Attempt to convert the error to a non-fatal parse error.
+			// Attempt to convert the error to a standardized parse error.
 			if parseErr, extractErr := extractModParseErrors(modFH.URI(), m, data.err, contents); extractErr == nil {
-				data.err = nil
 				data.parsed.ParseErrors = []source.Error{*parseErr}
 			}
+			// If the file was still parsed, we don't want to treat this as a
+			// fatal error. Note: This currently cannot happen as modfile.Parse
+			// always returns an error when the file is nil.
+			if data.parsed.File != nil {
+				data.err = nil
+			}
 		}
 		return data
 	})
diff --git a/internal/lsp/cache/mod_tidy.go b/internal/lsp/cache/mod_tidy.go
index a5c7578..e2f010d 100644
--- a/internal/lsp/cache/mod_tidy.go
+++ b/internal/lsp/cache/mod_tidy.go
@@ -87,15 +87,20 @@
 
 		snapshot := arg.(*snapshot)
 		pm, err := snapshot.ParseMod(ctx, fh)
-		if err != nil {
-			return &modTidyData{err: err}
-		}
-		if len(pm.ParseErrors) > 0 {
+		if err != nil || len(pm.ParseErrors) > 0 {
+			if err == nil {
+				err = fmt.Errorf("could not parse module to tidy: %v", pm.ParseErrors)
+			}
+			var errors []source.Error
+			if pm != nil {
+				errors = pm.ParseErrors
+			}
 			return &modTidyData{
 				tidied: &source.TidiedModule{
 					Parsed: pm,
+					Errors: errors,
 				},
-				err: fmt.Errorf("could not parse module to tidy: %v", pm.ParseErrors),
+				err: err,
 			}
 		}
 		tmpURI, runner, inv, cleanup, err := snapshot.goCommandInvocation(ctx, true, "mod", []string{"tidy"})
@@ -359,7 +364,7 @@
 		return source.Error{}, err
 	}
 	fix := &source.SuggestedFix{
-		Title: "Add %s to your go.mod file",
+		Title: fmt.Sprintf("Add %s to your go.mod file", req.Mod.Path),
 		Edits: map[span.URI][]protocol.TextEdit{
 			pm.Mapper.URI: edits,
 		},
diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go
index 4dea9cf..2f65ad2 100644
--- a/internal/lsp/cache/snapshot.go
+++ b/internal/lsp/cache/snapshot.go
@@ -1153,7 +1153,7 @@
 		return m
 	}
 	for _, r := range mod.File.Replace {
-		// We may be replacing a module with a different version. not a path
+		// We may be replacing a module with a different version, not a path
 		// on disk.
 		if r.New.Version != "" {
 			continue