Skip to content

Commit

Permalink
internal/lsp: include padding in inlay hint marker tests
Browse files Browse the repository at this point in the history
The marker tests are updated to include padding values
when mapping inlay hints to text edits.

Change-Id: Ieb421088238c65b07abdad12763816d3d1e757c8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/411654
Run-TryBot: Jamal Carvalho <jamal@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
  • Loading branch information
jamalc committed Jun 10, 2022
1 parent 5e48d26 commit c41ddce
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 31 deletions.
9 changes: 8 additions & 1 deletion internal/lsp/lsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -949,9 +949,16 @@ func (r *runner) InlayHints(t *testing.T, spn span.Span) {
// Map inlay hints to text edits.
edits := make([]protocol.TextEdit, len(hints))
for i, hint := range hints {
var paddingLeft, paddingRight string
if hint.PaddingLeft {
paddingLeft = " "
}
if hint.PaddingRight {
paddingRight = " "
}
edits[i] = protocol.TextEdit{
Range: protocol.Range{Start: *hint.Position, End: *hint.Position},
NewText: fmt.Sprintf("<%s>", hint.Label[0].Value),
NewText: fmt.Sprintf("<%s%s%s>", paddingLeft, hint.Label[0].Value, paddingRight),
}
}

Expand Down
10 changes: 5 additions & 5 deletions internal/lsp/testdata/inlay_hint/composite_literals.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ package inlayHint //@inlayHint("package")
import "fmt"

func fieldNames() {
for _<int>, c<struct{in string; want strin...> := range []struct {
for _< int>, c< struct{in string; want strin...> := range []struct {
in, want string
}{
{<in:>"Hello, world", <want:>"dlrow ,olleH"},
{<in:>"Hello, 世界", <want:>"界世 ,olleH"},
{<in:>"", <want:>""},
{<in: >"Hello, world", <want: >"dlrow ,olleH"},
{<in: >"Hello, 世界", <want: >"界世 ,olleH"},
{<in: >"", <want: >""},
} {
fmt.Println(<a...:>c.in == c.want)
fmt.Println(<a...: >c.in == c.want)
}
}

22 changes: 11 additions & 11 deletions internal/lsp/testdata/inlay_hint/constant_values.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ const True = true
type Kind int

const (
KindNone Kind = iota<= 0>
KindPrint<= 1>
KindPrintf<= 2>
KindErrorf<= 3>
KindNone Kind = iota< = 0>
KindPrint< = 1>
KindPrintf< = 2>
KindErrorf< = 3>
)

const (
u = iota * 4<= 0>
v float64 = iota * 42<= 42>
w = iota * 42<= 84>
u = iota * 4< = 0>
v float64 = iota * 42< = 42>
w = iota * 42< = 84>
)

const (
a, b = 1, 2
c, d<= 1, 2>
e, f = 5 * 5, "hello" + "world"<= 25, "helloworld">
g, h<= 25, "helloworld">
i, j = true, f<= true, "helloworld">
c, d< = 1, 2>
e, f = 5 * 5, "hello" + "world"< = 25, "helloworld">
g, h< = 25, "helloworld">
i, j = true, f< = true, "helloworld">
)

// No hint
Expand Down
20 changes: 10 additions & 10 deletions internal/lsp/testdata/inlay_hint/parameter_names.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func hello(name string) string {
}

func helloWorld() string {
return hello(<name:>"World")
return hello(<name: >"World")
}

type foo struct{}
Expand All @@ -21,27 +21,27 @@ func (*foo) bar(baz string, qux int) int {
}

func kase(foo int, bar bool, baz ...string) {
fmt.Println(<a...:>foo, bar, baz)
fmt.Println(<a...: >foo, bar, baz)
}

func kipp(foo string, bar, baz string) {
fmt.Println(<a...:>foo, bar, baz)
fmt.Println(<a...: >foo, bar, baz)
}

func plex(foo, bar string, baz string) {
fmt.Println(<a...:>foo, bar, baz)
fmt.Println(<a...: >foo, bar, baz)
}

func tars(foo string, bar, baz string) {
fmt.Println(<a...:>foo, bar, baz)
fmt.Println(<a...: >foo, bar, baz)
}

func foobar() {
var x foo
x.bar(<baz:>"", <qux:>1)
kase(<foo:>0, <bar:>true, <baz...:>"c", "d", "e")
kipp(<foo:>"a", <bar:>"b", <baz:>"c")
plex(<foo:>"a", <bar:>"b", <baz:>"c")
tars(<foo:>"a", <bar:>"b", <baz:>"c")
x.bar(<baz: >"", <qux: >1)
kase(<foo: >0, <bar: >true, <baz...: >"c", "d", "e")
kipp(<foo: >"a", <bar: >"b", <baz: >"c")
plex(<foo: >"a", <bar: >"b", <baz: >"c")
tars(<foo: >"a", <bar: >"b", <baz: >"c")
}

8 changes: 4 additions & 4 deletions internal/lsp/testdata/inlay_hint/variable_types.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
package inlayHint //@inlayHint("package")

func assignTypes() {
i<int>, j<int> := 0, len([]string{})-1
i< int>, j< int> := 0, len([]string{})-1
println(i, j)
}

func rangeTypes() {
for k<int>, v<string> := range []string{} {
for k< int>, v< string> := range []string{} {
println(k, v)
}
}

func funcLitType() {
myFunc<func(a string) string> := func(a string) string { return "" }
myFunc< func(a string) string> := func(a string) string { return "" }
}

func compositeLitType() {
foo<map[string]interface{}> := map[string]interface{}{"": ""}
foo< map[string]interface{}> := map[string]interface{}{"": ""}
}

0 comments on commit c41ddce

Please sign in to comment.