From 4ca4b55e2050cfa75f1a1f72ae10825e80b052a0 Mon Sep 17 00:00:00 2001 From: Ian Cottrell Date: Tue, 16 Apr 2019 15:47:48 -0400 Subject: [PATCH] internal/lsp: make the symbols tests use the enum names rather than hard coding the values this makes them less fragile, more portable and also more understandable. Change-Id: Ife8a7ed76b7517eaae37bd3896fee87740ffb22a Reviewed-on: https://go-review.googlesource.com/c/tools/+/172405 Run-TryBot: Ian Cottrell TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- internal/lsp/lsp_test.go | 4 +-- internal/lsp/testdata/symbols/main.go | 36 +++++++++++++-------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/internal/lsp/lsp_test.go b/internal/lsp/lsp_test.go index 6dc678c68b..d6c419a63c 100644 --- a/internal/lsp/lsp_test.go +++ b/internal/lsp/lsp_test.go @@ -547,7 +547,7 @@ func (h highlights) test(t *testing.T, s *Server) { } } -func (s symbols) collect(e *packagestest.Exported, fset *token.FileSet, name string, rng span.Range, kind int64, parentName string) { +func (s symbols) collect(e *packagestest.Exported, fset *token.FileSet, name string, rng span.Range, kind string, parentName string) { f := fset.File(rng.Start) if f == nil { return @@ -571,7 +571,7 @@ func (s symbols) collect(e *packagestest.Exported, fset *token.FileSet, name str sym := protocol.DocumentSymbol{ Name: name, - Kind: protocol.SymbolKind(kind), + Kind: protocol.ParseSymbolKind(kind), SelectionRange: prng, } if parentName == "" { diff --git a/internal/lsp/testdata/symbols/main.go b/internal/lsp/testdata/symbols/main.go index 93ace00cdf..032f74e1f1 100644 --- a/internal/lsp/testdata/symbols/main.go +++ b/internal/lsp/testdata/symbols/main.go @@ -2,42 +2,42 @@ package main import "io" -var x = 42 //@symbol("x", "x", 13, "") +var x = 42 //@symbol("x", "x", "Variable", "") -const y = 43 //@symbol("y", "y", 14, "") +const y = 43 //@symbol("y", "y", "Constant", "") -type Number int //@symbol("Number", "Number", 16, "") +type Number int //@symbol("Number", "Number", "Number", "") -type Alias = string //@symbol("Alias", "Alias", 15, "") +type Alias = string //@symbol("Alias", "Alias", "String", "") -type NumberAlias = Number //@symbol("NumberAlias", "NumberAlias", 16, "") +type NumberAlias = Number //@symbol("NumberAlias", "NumberAlias", "Number", "") type ( - Boolean bool //@symbol("Boolean", "Boolean", 17, "") - BoolAlias = bool //@symbol("BoolAlias", "BoolAlias", 17, "") + Boolean bool //@symbol("Boolean", "Boolean", "Boolean", "") + BoolAlias = bool //@symbol("BoolAlias", "BoolAlias", "Boolean", "") ) -type Foo struct { //@symbol("Foo", "Foo", 23, "") - Quux //@symbol("Quux", "Quux", 8, "Foo") - W io.Writer //@symbol("W" , "W", 8, "Foo") - Bar int //@symbol("Bar", "Bar", 8, "Foo") - baz string //@symbol("baz", "baz", 8, "Foo") +type Foo struct { //@symbol("Foo", "Foo", "Struct", "") + Quux //@symbol("Quux", "Quux", "Field", "Foo") + W io.Writer //@symbol("W" , "W", "Field", "Foo") + Bar int //@symbol("Bar", "Bar", "Field", "Foo") + baz string //@symbol("baz", "baz", "Field", "Foo") } -type Quux struct { //@symbol("Quux", "Quux", 23, "") - X, Y float64 //@symbol("X", "X", 8, "Quux"), symbol("Y", "Y", 8, "Quux") +type Quux struct { //@symbol("Quux", "Quux", "Struct", "") + X, Y float64 //@symbol("X", "X", "Field", "Quux"), symbol("Y", "Y", "Field", "Quux") } -func (f Foo) Baz() string { //@symbol("Baz", "Baz", 6, "Foo") +func (f Foo) Baz() string { //@symbol("Baz", "Baz", "Method", "Foo") return f.baz } -func (q *Quux) Do() {} //@symbol("Do", "Do", 6, "Quux") +func (q *Quux) Do() {} //@symbol("Do", "Do", "Method", "Quux") -func main() { //@symbol("main", "main", 12, "") +func main() { //@symbol("main", "main", "Function", "") } -type Stringer interface { //@symbol("Stringer", "Stringer", 11, "") +type Stringer interface { //@symbol("Stringer", "Stringer", "Interface", "") String() string }