mirror of
https://github.com/golang/go
synced 2024-11-19 04:54:41 -07:00
ad01d5993d
This change runs diagnostics on all packages in the workspace, instead of just open files. We also want to avoid invalidating the type information for a newly-opened file (since we should have it be default now), so handle that case. This causes a large increase in memory usage in the internal/lsp/cmd tests, so to handle that, share an app between all of the tests, rather than creating one per-test type. Change-Id: Ifba18d77a700cda79ec79f66174de0e7f13fe319 Reviewed-on: https://go-review.googlesource.com/c/tools/+/207353 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
37 lines
977 B
Go
37 lines
977 B
Go
// Copyright 2019 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package cmdtest
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"golang.org/x/tools/internal/lsp/cmd"
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
"golang.org/x/tools/internal/lsp/tests"
|
|
"golang.org/x/tools/internal/span"
|
|
"golang.org/x/tools/internal/tool"
|
|
)
|
|
|
|
func (r *runner) Link(t *testing.T, uri span.URI, wantLinks []tests.Link) {
|
|
m, err := r.data.Mapper(uri)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
args := []string{"-remote=internal", "links", "-json", uri.Filename()}
|
|
app := cmd.New("gopls-test", r.data.Config.Dir, r.data.Exported.Config.Env, r.options)
|
|
out := CaptureStdOut(t, func() {
|
|
_ = tool.Run(r.ctx, app, args)
|
|
})
|
|
var got []protocol.DocumentLink
|
|
err = json.Unmarshal([]byte(out), &got)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if diff := tests.DiffLinks(m, wantLinks, got); diff != "" {
|
|
t.Error(diff)
|
|
}
|
|
}
|