Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201028153306-37f0764111ff / internal / lsp / mod / diagnostics.go
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.
4
5 // Package mod provides core features related to go.mod file
6 // handling for use by Go editors and tools.
7 package mod
8
9 import (
10         "context"
11
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"
16 )
17
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()))
20         defer done()
21
22         reports := map[source.VersionedFileIdentity][]*source.Diagnostic{}
23         for _, uri := range snapshot.ModFiles() {
24                 fh, err := snapshot.GetVersionedFile(ctx, uri)
25                 if err != nil {
26                         return nil, err
27                 }
28                 reports[fh.VersionedFileIdentity()] = []*source.Diagnostic{}
29                 tidied, err := snapshot.ModTidy(ctx, fh)
30                 if err == source.ErrTmpModfileUnsupported {
31                         return nil, nil
32                 }
33                 if err != nil {
34                         return nil, err
35                 }
36                 for _, e := range tidied.Errors {
37                         diag := &source.Diagnostic{
38                                 Message: e.Message,
39                                 Range:   e.Range,
40                                 Source:  e.Category,
41                         }
42                         if e.Category == "syntax" {
43                                 diag.Severity = protocol.SeverityError
44                         } else {
45                                 diag.Severity = protocol.SeverityWarning
46                         }
47                         fh, err := snapshot.GetVersionedFile(ctx, e.URI)
48                         if err != nil {
49                                 return nil, err
50                         }
51                         reports[fh.VersionedFileIdentity()] = append(reports[fh.VersionedFileIdentity()], diag)
52                 }
53         }
54         return reports, nil
55 }