mirror of
https://github.com/golang/go
synced 2024-11-18 11:04:42 -07: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:
parent
7c47624df9
commit
6c6fd98e38
@ -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))
|
||||
}
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user