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
Run-TryBot: Peter Weinberger <>
gopls-CI: kokoro <>
TryBot-Result: Go Bot <>
Trust: Peter Weinberger <>
Reviewed-by: Robert Findley <>
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.