From 2feb2bb1ff51a5b7ed02382629fab3abab970e2d Mon Sep 17 00:00:00 2001 From: Peter Weinbergr Date: Thu, 29 Oct 2020 16:13:41 -0400 Subject: [PATCH] internal/lsp: elide details for non-package files When gc_details is invoked on a file, it can add diagnostics for files not in that file's package. Some of these will not go away when gc_details is toggled off. The fix is not emitting compiler details diagnostics about files not in the package. Fixes: https://github.com/golang/go/issues/42198 Fixes golang/go#42198 Change-Id: Ib69cdd8b7be96d73ee417711f7241f56fb529836 Reviewed-on: https://go-review.googlesource.com/c/tools/+/266342 Trust: Peter Weinberger Reviewed-by: Rebecca Stambler --- internal/lsp/source/gc_annotations.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/lsp/source/gc_annotations.go b/internal/lsp/source/gc_annotations.go index 8bf8ad73ca..4aac541d74 100644 --- a/internal/lsp/source/gc_annotations.go +++ b/internal/lsp/source/gc_annotations.go @@ -67,6 +67,12 @@ func GCOptimizationDetails(ctx context.Context, snapshot Snapshot, pkgDir span.U if fh == nil { continue } + if pkgDir.Filename() != filepath.Dir(fh.URI().Filename()) { + // https://github.com/golang/go/issues/42198 + // sometimes the detail diagnostics generated for files + // outside the package can never be taken back. + continue + } reports[fh.VersionedFileIdentity()] = diagnostics } return reports, parseError