From a0016a2adeac320313ad5952f94282afebee9a9f Mon Sep 17 00:00:00 2001 From: pjw Date: Fri, 17 Sep 2021 15:39:32 -0400 Subject: [PATCH] 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 gopls-CI: kokoro TryBot-Result: Go Bot Trust: Peter Weinberger Reviewed-by: Robert Findley --- internal/lsp/diagnostics.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/lsp/diagnostics.go b/internal/lsp/diagnostics.go index acf3820284..f9e1a47bd6 100644 --- a/internal/lsp/diagnostics.go +++ b/internal/lsp/diagnostics.go @@ -439,6 +439,10 @@ func (s *Server) checkForOrphanedFile(ctx context.Context, snapshot source.Snaps 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.