Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions gopls/internal/golang/completion/unimported.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,15 @@ func (c *completer) pkgIDmatches(ctx context.Context, ids []metadata.PackageID,
}
kind = protocol.FunctionCompletion
detail = fmt.Sprintf("func (from %q)", pkg.PkgPath)
case protocol.Variable, protocol.Struct:
case protocol.Variable:
kind = protocol.VariableCompletion
detail = fmt.Sprintf("var (from %q)", pkg.PkgPath)
case protocol.Interface:
kind = protocol.InterfaceCompletion
detail = fmt.Sprintf("type (from %q)", pkg.PkgPath)
case protocol.Struct, protocol.Class:
kind = protocol.ClassCompletion
detail = fmt.Sprintf("type (from %q)", pkg.PkgPath)
case protocol.Constant:
kind = protocol.ConstantCompletion
detail = fmt.Sprintf("const (from %q)", pkg.PkgPath)
Expand Down Expand Up @@ -284,7 +290,7 @@ func (c *completer) stdlibMatches(pkgs []metadata.PackagePath, pkg metadata.Pack
kind = protocol.VariableCompletion
detail = fmt.Sprintf("var (from %q)", candpkg)
case stdlib.Type:
kind = protocol.VariableCompletion
kind = protocol.ClassCompletion
detail = fmt.Sprintf("type (from %q)", candpkg)
default:
continue
Expand Down Expand Up @@ -331,7 +337,7 @@ func (c *completer) modcacheMatches(pkg metadata.PackageName, prefix string) ([]
kind = protocol.ConstantCompletion
detail = fmt.Sprintf("const (from %s)", cand.ImportPath)
case modindex.Type: // might be a type alias
kind = protocol.VariableCompletion
kind = protocol.ClassCompletion
detail = fmt.Sprintf("type (from %s)", cand.ImportPath)
default:
continue
Expand Down
20 changes: 19 additions & 1 deletion gopls/internal/test/marker/testdata/completion/unimported.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func Foo() {}
package foo

type StructFoo struct{ F int }
type ArrayFoo [16]byte
type InterfaceFoo interface{}
type FuncFoo func(int)

const ConstFoo = 1

var VarFoo = 2

-- baz/baz.go --
package baz
Expand All @@ -41,6 +48,10 @@ func _() {
signature.Foo //@complete(re"()Foo", signaturefoo)

context.Bac //@complete(re"() \\/\\/", contextBackground)

// Every kind of exported declaration of a workspace package that is not
// imported yet.
foo. //@complete(re"foo.() \\/\\/", fooArray, fooConst, fooFunc, fooInterface, fooStruct, fooVar)
}

// Create markers for unimported std lib packages. Only for use by this test.
Expand All @@ -49,7 +60,14 @@ func _() {
/* httptrace */ //@item(httptrace, "httptrace", "\"net/http/httptrace\"", "package")
/* httputil */ //@item(httputil, "httputil", "\"net/http/httputil\"", "package")

/* ring.Ring */ //@item(ringring, "Ring", "type (from \"container/ring\")", "var")
/* ring.Ring */ //@item(ringring, "Ring", "type (from \"container/ring\")", "type")

/* foo.ArrayFoo */ //@item(fooArray, "ArrayFoo", "type (from \"unimported.test/foo\")", "type")
/* foo.ConstFoo */ //@item(fooConst, "ConstFoo", "const (from \"unimported.test/foo\")", "const")
/* foo.FuncFoo */ //@item(fooFunc, "FuncFoo", "func (from \"unimported.test/foo\")", "func")
/* foo.InterfaceFoo */ //@item(fooInterface, "InterfaceFoo", "type (from \"unimported.test/foo\")", "interface")
/* foo.StructFoo */ //@item(fooStruct, "StructFoo", "type (from \"unimported.test/foo\")", "type")
/* foo.VarFoo */ //@item(fooVar, "VarFoo", "var (from \"unimported.test/foo\")", "var")

/* signature.Foo */ //@item(signaturefoo, "Foo", "func (from \"unimported.test/signature\")", "func")

Expand Down