1
0
mirror of https://github.com/golang/go synced 2024-10-01 15:58:33 -06:00
go/internal/lsp/regtest/codelens_test.go
Rob Findley cb8d9cd245 internal/lsp: support configurable codeLens
Some code lenses may be undesirable for certain users or editors -- for
example a code lens that runs tests, when VSCode already supports this
functionality outside of the LSP. To handle such situations, support
configuring code lenses via a new 'codelens' gopls option.

Add support for code lens in regtests, and use this to test the new
configuration. To achieve this, thread through a new 'EditorConfig' type
that configures the fake editor's LSP session. It made sense to move the
test Env overlay onto this config object as well.

While looking at them, document some types in source.Options.

Change-Id: I961077422a273829c5cbd83c3b87fae29f77eeda
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232680
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-05-08 18:47:35 +00:00

58 lines
1.2 KiB
Go

// Copyright 2020 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 regtest
import (
"testing"
"golang.org/x/tools/internal/lsp/fake"
"golang.org/x/tools/internal/lsp/source"
)
func TestDisablingCodeLens(t *testing.T) {
const workspace = `
-- go.mod --
module codelens.test
-- lib.go --
package lib
type Number int
const (
Zero Number = iota
One
Two
)
//go:generate stringer -type=Number
`
tests := []struct {
label string
enabled map[string]bool
wantCodeLens bool
}{
{
label: "default",
wantCodeLens: true,
},
{
label: "generate disabled",
enabled: map[string]bool{source.CommandGenerate: false},
wantCodeLens: false,
},
}
for _, test := range tests {
t.Run(test.label, func(t *testing.T) {
runner.Run(t, workspace, func(t *testing.T, env *Env) {
env.OpenFile("lib.go")
lens := env.CodeLens("lib.go")
if gotCodeLens := len(lens) > 0; gotCodeLens != test.wantCodeLens {
t.Errorf("got codeLens: %t, want %t", gotCodeLens, test.wantCodeLens)
}
}, WithEditorConfig(fake.EditorConfig{CodeLens: test.enabled}))
})
}
}