internal/lsp/source: fix default param name generation

When generating a default param name based on a type name, we want to
ignore any package qualifier. For example, if the type is "ast.Node"
we want to generate the variable name "n", so we must ignore the
"ast." qualifier. To do this we use a types.Qualifier that always
returns empty, but qualifyExpr wasn't respecting an empty qualifier
because it is doing manual ast manipulation. However, it seems like
things "just work" if you set a SelectorExpr's "X" to empty
string (i.e. only "Sel" is output when formatting).

Fixes golang/go#42794.

Change-Id: Ied86b9511e4a9550590417c5a506fe35d561d4f9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/275519
Run-TryBot: Muir Manders <muir@mnd.rs>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
This commit is contained in:
Muir Manders 2020-12-04 20:50:10 -08:00 committed by Rebecca Stambler
parent 1dfd70e0ab
commit 7bb39e4ca9
3 changed files with 5 additions and 5 deletions

View File

@ -282,10 +282,7 @@ func qualifyExpr(expr ast.Expr, srcpkg, pkg Package, clonedInfo map[token.Pos]*t
if !ok {
return false
}
pkgName := qf(obj.Imported())
if pkgName != "" {
x.Name = pkgName
}
x.Name = qf(obj.Imported())
return false
case *ast.Ident:
if srcpkg == pkg {

View File

@ -2,6 +2,7 @@ package snippets
import (
"bytes"
"go/ast"
"net/http"
"sort"
@ -159,6 +160,8 @@ func _() {
const two = 2
var builtinTypes func([]int, [two]bool, map[string]string, struct{ i int }, interface{ foo() }, <-chan int)
builtinTypes = f //@snippet(" //", litFunc, "func(i1 []int, b [two]bool, m map[string]string, s struct{ i int \\}, i2 interface{ foo() \\}, c <-chan int) {$0\\}", "func(${1:i1} []int, ${2:b} [two]bool, ${3:m} map[string]string, ${4:s} struct{ i int \\}, ${5:i2} interface{ foo() \\}, ${6:c} <-chan int) {$0\\}")
var _ func(ast.Node) = f //@snippet(" //", litFunc, "func(n ast.Node) {$0\\}", "func(${1:n} ast.Node) {$0\\}")
}
func _() {

View File

@ -2,7 +2,7 @@
CallHierarchyCount = 1
CodeLensCount = 5
CompletionsCount = 255
CompletionSnippetCount = 87
CompletionSnippetCount = 88
UnimportedCompletionsCount = 5
DeepCompletionsCount = 5
FuzzyCompletionsCount = 8