internal/lsp/diagnostics: avoid erroneous error message for orphaned files

If the user changes the extension of a go file while editing,
the existing code complains 'No packages found for open file'.
This error messsag is not helpful and this CL avoids it.

Change-Id: Idf426f1ce8b83b23757f81aa1f322fea86df9d82
Reviewed-on: https://go-review.googlesource.com/c/tools/+/350789
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/internal/lsp/diagnostics.go b/internal/lsp/diagnostics.go
index acf3820..f9e1a47 100644
--- a/internal/lsp/diagnostics.go
+++ b/internal/lsp/diagnostics.go
@@ -439,6 +439,10 @@
 	if err != nil {
 		return nil
 	}
+	// If the file no longer has a name ending in .go, this diagnostic is wrong
+	if filepath.Ext(fh.URI().Filename()) != ".go" {
+		return nil
+	}
 	// TODO(rstambler): We should be able to parse the build tags in the
 	// file and show a more specific error message. For now, put the diagnostic
 	// on the package declaration.