1
0
mirror of https://github.com/golang/go synced 2024-09-30 14:28:33 -06:00

internal/lsp: fix panic in computing diagnostics for module

We were returning empty diagnostics for an empty file.

Fixes golang/go#39696.

Change-Id: Idfd50980f4bf771f76ad7b7fb6180a5f712a92bf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/239040
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Rebecca Stambler 2020-06-19 16:31:22 -04:00
parent 7c47624df9
commit 6c6fd98e38
2 changed files with 8 additions and 0 deletions

View File

@ -74,6 +74,10 @@ func (s *Server) diagnose(ctx context.Context, snapshot source.Snapshot, alwaysA
}
modURI := snapshot.View().ModFile()
for id, diags := range reports {
if id.URI == "" {
event.Error(ctx, "missing URI for module diagnostics", fmt.Errorf("empty URI"), tag.Directory.Of(snapshot.View().Folder().Filename()))
continue
}
if id.URI != modURI {
panic(fmt.Sprintf("expected module diagnostics report for %q, got %q", modURI, id.URI))
}

View File

@ -18,6 +18,10 @@ import (
func Diagnostics(ctx context.Context, snapshot source.Snapshot) (map[source.FileIdentity][]*source.Diagnostic, map[string]*modfile.Require, error) {
uri := snapshot.View().ModFile()
if uri == "" {
return nil, nil, nil
}
ctx, done := event.Start(ctx, "mod.Diagnostics", tag.URI.Of(uri))
defer done()