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 <pjw@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Peter Weinbergr 2020-10-29 16:13:41 -04:00 коммит произвёл Peter Weinberger
Родитель 186a7436c9
Коммит 2feb2bb1ff
1 изменённых файлов: 6 добавлений и 0 удалений

Просмотреть файл

@ -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