1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Package mod provides core features related to go.mod file
6 // handling for use by Go editors and tools.
12 "golang.org/x/tools/internal/event"
13 "golang.org/x/tools/internal/lsp/debug/tag"
14 "golang.org/x/tools/internal/lsp/protocol"
15 "golang.org/x/tools/internal/lsp/source"
18 func Diagnostics(ctx context.Context, snapshot source.Snapshot) (map[source.VersionedFileIdentity][]*source.Diagnostic, error) {
19 ctx, done := event.Start(ctx, "mod.Diagnostics", tag.Snapshot.Of(snapshot.ID()))
22 reports := map[source.VersionedFileIdentity][]*source.Diagnostic{}
23 for _, uri := range snapshot.ModFiles() {
24 fh, err := snapshot.GetVersionedFile(ctx, uri)
28 reports[fh.VersionedFileIdentity()] = []*source.Diagnostic{}
29 tidied, err := snapshot.ModTidy(ctx, fh)
30 if err == source.ErrTmpModfileUnsupported {
36 for _, e := range tidied.Errors {
37 diag := &source.Diagnostic{
42 if e.Category == "syntax" {
43 diag.Severity = protocol.SeverityError
45 diag.Severity = protocol.SeverityWarning
47 fh, err := snapshot.GetVersionedFile(ctx, e.URI)
51 reports[fh.VersionedFileIdentity()] = append(reports[fh.VersionedFileIdentity()], diag)