golang.org/x/tools/gopls@v0.15.3/internal/test/integration/misc/signature_help_test.go (about) 1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package misc 6 7 import ( 8 "testing" 9 10 "github.com/google/go-cmp/cmp" 11 "golang.org/x/tools/gopls/internal/protocol" 12 . "golang.org/x/tools/gopls/internal/test/integration" 13 ) 14 15 func TestSignatureHelpInNonWorkspacePackage(t *testing.T) { 16 const files = ` 17 -- a/go.mod -- 18 module a.com 19 20 go 1.18 21 -- a/a/a.go -- 22 package a 23 24 func DoSomething(int) {} 25 26 func _() { 27 DoSomething() 28 } 29 -- b/go.mod -- 30 module b.com 31 go 1.18 32 33 require a.com v1.0.0 34 35 replace a.com => ../a 36 -- b/b/b.go -- 37 package b 38 39 import "a.com/a" 40 41 func _() { 42 a.DoSomething() 43 } 44 ` 45 46 WithOptions( 47 WorkspaceFolders("a"), 48 ).Run(t, files, func(t *testing.T, env *Env) { 49 env.OpenFile("a/a/a.go") 50 env.OpenFile("b/b/b.go") 51 signatureHelp := func(filename string) *protocol.SignatureHelp { 52 loc := env.RegexpSearch(filename, `DoSomething\(()\)`) 53 var params protocol.SignatureHelpParams 54 params.TextDocument.URI = loc.URI 55 params.Position = loc.Range.Start 56 help, err := env.Editor.Server.SignatureHelp(env.Ctx, ¶ms) 57 if err != nil { 58 t.Fatal(err) 59 } 60 return help 61 } 62 ahelp := signatureHelp("a/a/a.go") 63 bhelp := signatureHelp("b/b/b.go") 64 65 if diff := cmp.Diff(ahelp, bhelp); diff != "" { 66 t.Fatal(diff) 67 } 68 }) 69 }