internal/lsp: remove constant value from label and add tests

Fixes golang/go#29816
Fixes golang/go#31923

Change-Id: I4f0ff7941a5d26994ef6bbd10346eafe31160a21
Reviewed-on: https://go-review.googlesource.com/c/tools/+/177357
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
diff --git a/internal/lsp/source/completion_format.go b/internal/lsp/source/completion_format.go
index 3657c23..24b24ce 100644
--- a/internal/lsp/source/completion_format.go
+++ b/internal/lsp/source/completion_format.go
@@ -32,33 +32,25 @@
 		placeholderSnippet *snippet.Builder
 	)
 
-	switch o := obj.(type) {
+	switch obj := obj.(type) {
 	case *types.TypeName:
-		detail, kind = formatType(o.Type(), c.qf)
+		detail, kind = formatType(obj.Type(), c.qf)
 	case *types.Const:
-		if obj.Parent() == types.Universe {
-			detail = ""
-		} else {
-			val := o.Val().ExactString()
-			if !strings.ContainsRune(val, '\n') { // skip any multiline constants
-				label += " = " + val
-			}
-		}
 		kind = ConstantCompletionItem
 	case *types.Var:
-		if _, ok := o.Type().(*types.Struct); ok {
+		if _, ok := obj.Type().(*types.Struct); ok {
 			detail = "struct{...}" // for anonymous structs
 		}
-		if o.IsField() {
+		if obj.IsField() {
 			kind = FieldCompletionItem
 			plainSnippet, placeholderSnippet = c.structFieldSnippets(label, detail)
-		} else if c.isParameter(o) {
+		} else if c.isParameter(obj) {
 			kind = ParameterCompletionItem
 		} else {
 			kind = VariableCompletionItem
 		}
 	case *types.Func:
-		sig, ok := o.Type().(*types.Signature)
+		sig, ok := obj.Type().(*types.Signature)
 		if !ok {
 			break
 		}
@@ -75,7 +67,7 @@
 		}
 	case *types.PkgName:
 		kind = PackageCompletionItem
-		detail = fmt.Sprintf("\"%s\"", o.Imported().Path())
+		detail = fmt.Sprintf("\"%s\"", obj.Imported().Path())
 	}
 	detail = strings.TrimPrefix(detail, "untyped ")
 
diff --git a/internal/lsp/testdata/constant/constant.go b/internal/lsp/testdata/constant/constant.go
new file mode 100644
index 0000000..c1c88e1
--- /dev/null
+++ b/internal/lsp/testdata/constant/constant.go
@@ -0,0 +1,14 @@
+package constant
+
+const x = 1 //@item(constX, "x", "int", "const")
+
+const (
+	a int = iota << 2 //@item(constA, "a", "int", "const")
+	b                 //@item(constB, "b", "int", "const")
+	c                 //@item(constC, "c", "int", "const")
+)
+
+func _() {
+	const y = "hi" //@item(constY, "y", "string", "const")
+	//@complete("", constY, constA, constB, constC, constX)
+}
diff --git a/internal/lsp/tests/tests.go b/internal/lsp/tests/tests.go
index 88cc983..7b06478 100644
--- a/internal/lsp/tests/tests.go
+++ b/internal/lsp/tests/tests.go
@@ -28,7 +28,8 @@
 // We hardcode the expected number of test cases to ensure that all tests
 // are being executed. If a test is added, this number must be changed.
 const (
-	ExpectedCompletionsCount       = 106
+	ExpectedCompletionsCount       = 107
+	ExpectedCompletionSnippetCount = 13
 	ExpectedDiagnosticsCount       = 17
 	ExpectedFormatCount            = 5
 	ExpectedDefinitionsCount       = 33
@@ -36,7 +37,6 @@
 	ExpectedHighlightsCount        = 2
 	ExpectedSymbolsCount           = 1
 	ExpectedSignaturesCount        = 20
-	ExpectedCompletionSnippetCount = 13
 	ExpectedLinksCount             = 2
 )