mirror of https://github.com/golang/go.git
internal/lsp: skip signature help within a string literal
Currently the `SignatureHelp` function provides signature help even when the requested range lies within a string literal. Let's suppress this behavior and return an error when someone requests signature help from within a string literal. Fixes golang/go#43397 Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Change-Id: Ib03e87258622f4294bf9385bf5f0a8effe0050ee GitHub-Last-Rev: 0c9549ae68b0263a3cac274da133e9ab4b4c7bf5 GitHub-Pull-Request: golang/tools#332 Reviewed-on: https://go-review.googlesource.com/c/tools/+/337170 Reviewed-by: Rebecca Stambler <rstambler@golang.org> Trust: Rebecca Stambler <rstambler@golang.org> Trust: Robert Findley <rfindley@google.com> Trust: Peter Weinberger <pjw@google.com> Run-TryBot: Rebecca Stambler <rstambler@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
0c506a2740
commit
4fe0d6c80e
|
|
@ -51,7 +51,12 @@ FindCall:
|
|||
// which may be the parameter to the *ast.CallExpr.
|
||||
// Don't show signature help in this case.
|
||||
return nil, 0, errors.Errorf("no signature help within a function declaration")
|
||||
case *ast.BasicLit:
|
||||
if node.Kind == token.STRING {
|
||||
return nil, 0, errors.Errorf("no signature help within a string literal")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if callExpr == nil || callExpr.Fun == nil {
|
||||
return nil, 0, errors.Errorf("cannot find an enclosing function")
|
||||
|
|
|
|||
|
|
@ -47,11 +47,12 @@ func Qux() {
|
|||
return func(int) rune { return 0 }
|
||||
}
|
||||
|
||||
fn("hi", "there") //@signature("hi", "fn(hi string, there string) func(i int) rune", 0)
|
||||
fn("hi", "there") //@signature("hi", "", 0)
|
||||
fn("hi", "there") //@signature(",", "fn(hi string, there string) func(i int) rune", 0)
|
||||
fn("hi", "there")(1) //@signature("1", "func(i int) rune", 0)
|
||||
|
||||
fnPtr := &fn
|
||||
(*fnPtr)("hi", "there") //@signature("hi", "func(hi string, there string) func(i int) rune", 0)
|
||||
(*fnPtr)("hi", "there") //@signature(",", "func(hi string, there string) func(i int) rune", 0)
|
||||
|
||||
var fnIntf interface{} = Foo
|
||||
fnIntf.(func(string, int) bool)("hi", 123) //@signature("123", "func(string, int) bool", 1)
|
||||
|
|
@ -69,8 +70,8 @@ func Qux() {
|
|||
Foo(myFunc(123), 456) //@signature("myFunc", "Foo(a string, b int) (c bool)", 0)
|
||||
Foo(myFunc(123), 456) //@signature("123", "myFunc(foo int) string", 0)
|
||||
|
||||
panic("oops!") //@signature("oops", "panic(v interface{})", 0)
|
||||
println("hello", "world") //@signature("world", "println(args ...Type)", 0)
|
||||
panic("oops!") //@signature(")", "panic(v interface{})", 0)
|
||||
println("hello", "world") //@signature(",", "println(args ...Type)", 0)
|
||||
|
||||
Hello(func() {
|
||||
//@signature("//", "", 0)
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ RenamesCount = 37
|
|||
PrepareRenamesCount = 7
|
||||
SymbolsCount = 5
|
||||
WorkspaceSymbolsCount = 20
|
||||
SignaturesCount = 32
|
||||
SignaturesCount = 33
|
||||
LinksCount = 7
|
||||
ImplementationsCount = 14
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue