diff --git a/internal/lsp/source/completion.go b/internal/lsp/source/completion.go index 82324a25bd..76fda99d27 100644 --- a/internal/lsp/source/completion.go +++ b/internal/lsp/source/completion.go @@ -721,7 +721,7 @@ func (c *completer) unimportedMembers(id *ast.Ident) error { if imports.ImportPathToAssumedName(path) != pkg.GetTypes().Name() { imp.name = pkg.GetTypes().Name() } - c.packageMembers(pkg.GetTypes(), .01*float64(relevances[path]), imp) + c.packageMembers(pkg.GetTypes(), stdScore+.01*float64(relevances[path]), imp) if len(c.items) >= unimportedTarget { return nil } @@ -740,7 +740,7 @@ func (c *completer) unimportedMembers(id *ast.Ident) error { // Continue with untyped proposals. pkg := types.NewPackage(pkgExport.Fix.StmtInfo.ImportPath, pkgExport.Fix.IdentName) for _, export := range pkgExport.Exports { - score := 0.01 * float64(pkgExport.Fix.Relevance) + score := stdScore + 0.01*float64(pkgExport.Fix.Relevance) c.found(candidate{ obj: types.NewVar(0, pkg, export, nil), score: score, diff --git a/internal/lsp/testdata/lsp/primarymod/unimported/unimported.go.in b/internal/lsp/testdata/lsp/primarymod/unimported/unimported.go.in index d4ce8b3d25..ef5dc4caec 100644 --- a/internal/lsp/testdata/lsp/primarymod/unimported/unimported.go.in +++ b/internal/lsp/testdata/lsp/primarymod/unimported/unimported.go.in @@ -4,8 +4,9 @@ func _() { //@unimported("", hashslashadler32, goslashast, encodingslashbase64, bytes) pkg //@unimported("g", externalpackage) // container/ring is extremely unlikely to be imported by anything, so shouldn't have type information. - ring.Ring //@unimported("Ring", ringring) + ring.Ring //@unimported("Ring", ringring) signature.Foo //@unimported("Foo", signaturefoo) + context.Bac //@unimported("Bac", contextBackground, contextBackgroundErr) } // Create markers for unimported std lib packages. Only for use by this test. @@ -17,4 +18,7 @@ func _() { /* ring.Ring */ //@item(ringring, "Ring", "(from \"container/ring\")", "var") -/* signature.Foo */ //@item(signaturefoo, "Foo", "func(a string, b int) (c bool) (from \"golang.org/x/tools/internal/lsp/signature\")", "func") \ No newline at end of file +/* signature.Foo */ //@item(signaturefoo, "Foo", "func(a string, b int) (c bool) (from \"golang.org/x/tools/internal/lsp/signature\")", "func") + +/* context.Background */ //@item(contextBackground, "Background", "func() context.Context (from \"context\")", "func") +/* context.Background().Err */ //@item(contextBackgroundErr, "Background().Err", "func() error (from \"context\")", "method") diff --git a/internal/lsp/testdata/lsp/primarymod/unimported/unimported_cand_type.go b/internal/lsp/testdata/lsp/primarymod/unimported/unimported_cand_type.go index 2690c1a4a2..531aa2d180 100644 --- a/internal/lsp/testdata/lsp/primarymod/unimported/unimported_cand_type.go +++ b/internal/lsp/testdata/lsp/primarymod/unimported/unimported_cand_type.go @@ -1,8 +1,10 @@ package unimported import ( + _ "context" + "golang.org/x/tools/internal/lsp/baz" - "golang.org/x/tools/internal/lsp/signature" // provide type information for unimported completions in the other file + _ "golang.org/x/tools/internal/lsp/signature" // provide type information for unimported completions in the other file ) func _() { diff --git a/internal/lsp/testdata/lsp/summary.txt.golden b/internal/lsp/testdata/lsp/summary.txt.golden index 519a643566..d6d706caca 100644 --- a/internal/lsp/testdata/lsp/summary.txt.golden +++ b/internal/lsp/testdata/lsp/summary.txt.golden @@ -1,7 +1,7 @@ -- summary -- CompletionsCount = 227 CompletionSnippetCount = 66 -UnimportedCompletionsCount = 9 +UnimportedCompletionsCount = 11 DeepCompletionsCount = 5 FuzzyCompletionsCount = 8 RankedCompletionsCount = 84