зеркало из https://github.com/golang/tools.git
internal/lsp: suppress parameter hint when argument matches parameter
Suppress the parameter hint when it would present redundant information. Fixes golang/go#2361 Change-Id: I4340a903046f212f8a035eab847da665e2692f1a Reviewed-on: https://go-review.googlesource.com/c/tools/+/419497 gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Suzy Mueller <suzmue@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Родитель
c83f42da70
Коммит
6c8a6c4093
|
@ -154,17 +154,24 @@ func parameterNames(node ast.Node, tmap *lsppos.TokenMapper, info *types.Info, _
|
|||
if i > params.Len()-1 {
|
||||
break
|
||||
}
|
||||
value := params.At(i).Name()
|
||||
param := params.At(i)
|
||||
// param.Name is empty for built-ins like append
|
||||
if value == "" {
|
||||
if param.Name() == "" {
|
||||
continue
|
||||
}
|
||||
// Skip the parameter name hint if the arg matches the
|
||||
// the parameter name.
|
||||
if i, ok := v.(*ast.Ident); ok && i.Name == param.Name() {
|
||||
continue
|
||||
}
|
||||
|
||||
label := param.Name()
|
||||
if signature.Variadic() && i == params.Len()-1 {
|
||||
value = value + "..."
|
||||
label = label + "..."
|
||||
}
|
||||
hints = append(hints, protocol.InlayHint{
|
||||
Position: &start,
|
||||
Label: buildLabel(value + ":"),
|
||||
Label: buildLabel(label + ":"),
|
||||
Kind: protocol.Parameter,
|
||||
PaddingRight: true,
|
||||
})
|
||||
|
|
|
@ -42,4 +42,9 @@ func foobar() {
|
|||
kipp("a", "b", "c")
|
||||
plex("a", "b", "c")
|
||||
tars("a", "b", "c")
|
||||
foo, bar, baz := "a", "b", "c"
|
||||
kipp(foo, bar, baz)
|
||||
plex("a", bar, baz)
|
||||
tars(foo+foo, (bar), "c")
|
||||
|
||||
}
|
||||
|
|
|
@ -43,5 +43,10 @@ func foobar() {
|
|||
kipp(<foo: >"a", <bar: >"b", <baz: >"c")
|
||||
plex(<foo: >"a", <bar: >"b", <baz: >"c")
|
||||
tars(<foo: >"a", <bar: >"b", <baz: >"c")
|
||||
foo< string>, bar< string>, baz< string> := "a", "b", "c"
|
||||
kipp(foo, bar, baz)
|
||||
plex(<foo: >"a", bar, baz)
|
||||
tars(<foo: >foo+foo, <bar: >(bar), <baz: >"c")
|
||||
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче