1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:14:46 -07:00

internal/lsp/cmd: fix definition test to run independently

definition.Run requires a nil check of opts before applying to avoid
panic, and test must be run with markdown enabled.
When running 'go test' without -run flag, connection.initialize() was
not called and there was no problem because the default value of
Options.PreferredContentFormat was Markdown.
In addition, currently using the same connection despite different
options, therefore make to use a different connection for different
options.

Change-Id: I6ef773c14cbdcae621da9295d4c618c3aff0beee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222497
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Daisuke Suzuki 2020-03-07 21:03:24 +09:00 committed by Rebecca Stambler
parent c97a9db72c
commit 521f4a0cd4
3 changed files with 11 additions and 4 deletions

View File

@ -202,7 +202,12 @@ func (app *Application) connect(ctx context.Context) (*connection, error) {
case strings.HasPrefix(app.Remote, "internal@"):
internalMu.Lock()
defer internalMu.Unlock()
if c := internalConnections[app.wd]; c != nil {
opts := source.DefaultOptions()
if app.options != nil {
app.options(&opts)
}
key := fmt.Sprintf("%s %v", app.wd, opts)
if c := internalConnections[key]; c != nil {
return c, nil
}
remote := app.Remote[len("internal@"):]
@ -211,7 +216,7 @@ func (app *Application) connect(ctx context.Context) (*connection, error) {
if err != nil {
return nil, err
}
internalConnections[app.wd] = connection
internalConnections[key] = connection
return connection, nil
default:
return app.connectRemote(ctx, app.Remote)

View File

@ -64,7 +64,9 @@ func (d *definition) Run(ctx context.Context, args ...string) error {
// Plaintext makes more sense for the command line.
opts := d.query.app.options
d.query.app.options = func(o *source.Options) {
opts(o)
if opts != nil {
opts(o)
}
o.PreferredContentFormat = protocol.PlainText
if d.query.MarkdownSupported {
o.PreferredContentFormat = protocol.Markdown

View File

@ -33,7 +33,7 @@ func (r *runner) Definition(t *testing.T, spn span.Span, d tests.Definition) {
}
d.Src = span.New(d.Src.URI(), span.NewPoint(0, 0, d.Src.Start().Offset()), span.Point{})
for _, mode := range godefModes {
args := []string{"query"}
args := []string{"query", "-markdown"}
tag := d.Name + "-definition"
if mode&jsonGoDef != 0 {
tag += "-json"