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>
This commit is contained in:
Rebecca Stambler 2019-05-15 14:16:16 -04:00
parent 473d3dc1d7
commit 7c3f65130f
3 changed files with 23 additions and 17 deletions

View File

@ -32,33 +32,25 @@ func (c *completer) item(obj types.Object, score float64) CompletionItem {
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 @@ func (c *completer) item(obj types.Object, score float64) CompletionItem {
}
case *types.PkgName:
kind = PackageCompletionItem
detail = fmt.Sprintf("\"%s\"", o.Imported().Path())
detail = fmt.Sprintf("\"%s\"", obj.Imported().Path())
}
detail = strings.TrimPrefix(detail, "untyped ")

View File

@ -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)
}

View File

@ -28,7 +28,8 @@ import (
// 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 @@ const (
ExpectedHighlightsCount = 2
ExpectedSymbolsCount = 1
ExpectedSignaturesCount = 20
ExpectedCompletionSnippetCount = 13
ExpectedLinksCount = 2
)