Skip to content

Commit 4fe0d6c

Browse files
KarthikNayakstamblerre
authored andcommitted
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 <[email protected]> Change-Id: Ib03e87258622f4294bf9385bf5f0a8effe0050ee GitHub-Last-Rev: 0c9549a GitHub-Pull-Request: golang#332 Reviewed-on: https://go-review.googlesource.com/c/tools/+/337170 Reviewed-by: Rebecca Stambler <[email protected]> Trust: Rebecca Stambler <[email protected]> Trust: Robert Findley <[email protected]> Trust: Peter Weinberger <[email protected]> Run-TryBot: Rebecca Stambler <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 0c506a2 commit 4fe0d6c

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

internal/lsp/source/signature_help.go

+5
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ FindCall:
5151
// which may be the parameter to the *ast.CallExpr.
5252
// Don't show signature help in this case.
5353
return nil, 0, errors.Errorf("no signature help within a function declaration")
54+
case *ast.BasicLit:
55+
if node.Kind == token.STRING {
56+
return nil, 0, errors.Errorf("no signature help within a string literal")
57+
}
5458
}
59+
5560
}
5661
if callExpr == nil || callExpr.Fun == nil {
5762
return nil, 0, errors.Errorf("cannot find an enclosing function")

internal/lsp/testdata/signature/signature.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ func Qux() {
4747
return func(int) rune { return 0 }
4848
}
4949

50-
fn("hi", "there") //@signature("hi", "fn(hi string, there string) func(i int) rune", 0)
50+
fn("hi", "there") //@signature("hi", "", 0)
51+
fn("hi", "there") //@signature(",", "fn(hi string, there string) func(i int) rune", 0)
5152
fn("hi", "there")(1) //@signature("1", "func(i int) rune", 0)
5253

5354
fnPtr := &fn
54-
(*fnPtr)("hi", "there") //@signature("hi", "func(hi string, there string) func(i int) rune", 0)
55+
(*fnPtr)("hi", "there") //@signature(",", "func(hi string, there string) func(i int) rune", 0)
5556

5657
var fnIntf interface{} = Foo
5758
fnIntf.(func(string, int) bool)("hi", 123) //@signature("123", "func(string, int) bool", 1)
@@ -69,8 +70,8 @@ func Qux() {
6970
Foo(myFunc(123), 456) //@signature("myFunc", "Foo(a string, b int) (c bool)", 0)
7071
Foo(myFunc(123), 456) //@signature("123", "myFunc(foo int) string", 0)
7172

72-
panic("oops!") //@signature("oops", "panic(v interface{})", 0)
73-
println("hello", "world") //@signature("world", "println(args ...Type)", 0)
73+
panic("oops!") //@signature(")", "panic(v interface{})", 0)
74+
println("hello", "world") //@signature(",", "println(args ...Type)", 0)
7475

7576
Hello(func() {
7677
//@signature("//", "", 0)

internal/lsp/testdata/summary.txt.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ RenamesCount = 37
2424
PrepareRenamesCount = 7
2525
SymbolsCount = 5
2626
WorkspaceSymbolsCount = 20
27-
SignaturesCount = 32
27+
SignaturesCount = 33
2828
LinksCount = 7
2929
ImplementationsCount = 14
3030

0 commit comments

Comments
 (0)