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.
12 "golang.org/x/tools/internal/span"
13 errors "golang.org/x/xerrors"
16 // check implements the check verb for gopls.
21 func (c *check) Name() string { return "check" }
22 func (c *check) Usage() string { return "<filename>" }
23 func (c *check) ShortHelp() string { return "show diagnostic results for the specified file" }
24 func (c *check) DetailedHelp(f *flag.FlagSet) {
25 fmt.Fprint(f.Output(), `
26 Example: show the diagnostic results of this file:
28 $ gopls check internal/lsp/cmd/check.go
30 gopls check flags are:
35 // Run performs the check on the files specified by args and prints the
37 func (c *check) Run(ctx context.Context, args ...string) error {
39 // no files, so no results
42 checking := map[span.URI]*cmdFile{}
44 // now we ready to kick things off
45 conn, err := c.app.connect(ctx)
49 defer conn.terminate(ctx)
50 for _, arg := range args {
51 uri := span.URIFromPath(arg)
52 uris = append(uris, uri)
53 file := conn.AddFile(ctx, uri)
59 if err := conn.diagnoseFiles(ctx, uris); err != nil {
62 conn.Client.filesMu.Lock()
63 defer conn.Client.filesMu.Unlock()
65 for _, file := range checking {
66 for _, d := range file.diagnostics {
67 spn, err := file.mapper.RangeSpan(d.Range)
69 return errors.Errorf("Could not convert position %v for %q", d.Range, d.Message)
71 fmt.Printf("%v: %v\n", spn, d.Message)