diff --git a/internal/lsp/source/completion_format.go b/internal/lsp/source/completion_format.go index 3657c230..24b24ce6 100644 --- a/internal/lsp/source/completion_format.go +++ b/internal/lsp/source/completion_format.go @@ -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 ") diff --git a/internal/lsp/testdata/constant/constant.go b/internal/lsp/testdata/constant/constant.go new file mode 100644 index 00000000..c1c88e16 --- /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 88cc983c..7b064788 100644 --- a/internal/lsp/tests/tests.go +++ b/internal/lsp/tests/tests.go @@ -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 )