diff --git a/gopls/internal/lsp/source/definition_gox.go b/gopls/internal/lsp/source/definition_gox.go index ad92a2a4674..a9e0b796b73 100644 --- a/gopls/internal/lsp/source/definition_gox.go +++ b/gopls/internal/lsp/source/definition_gox.go @@ -84,12 +84,12 @@ func GopDefinition(ctx context.Context, snapshot Snapshot, fh FileHandle, positi return nil, nil } - anonyOvId := false + var anonyOvFunc *ast.FuncLit if fun, ok := obj.(*types.Func); ok { for ov := range pkg.GopTypesInfo().Implicits { if v, ok := ov.(*ast.FuncLit); ok { if v.Pos() == fun.Pos() { - anonyOvId = true + anonyOvFunc = v break } } @@ -149,9 +149,8 @@ func GopDefinition(ctx context.Context, snapshot Snapshot, fh FileHandle, positi } typeEnd := adjustedObjEnd(obj) - if anonyOvId { - // goxls: anonymous overload function identifier range - typeEnd = obj.Pos() + token.Pos(len("func")) + if anonyOvFunc != nil { // goxls: anonymous overload function + typeEnd = anonyOvFunc.Type.End() } // Finally, map the object position. loc, err := mapPosition(ctx, pkg.FileSet(), snapshot, obj.Pos(), typeEnd) diff --git a/gopls/internal/regtest/misc/definition_gox_test.go b/gopls/internal/regtest/misc/definition_gox_test.go index 04b06126d1c..63a45fc7c0a 100644 --- a/gopls/internal/regtest/misc/definition_gox_test.go +++ b/gopls/internal/regtest/misc/definition_gox_test.go @@ -33,7 +33,7 @@ func TestOverloadDefinition1(t *testing.T) { t.Errorf("GoToDefinition: got file %q, want %q", name, want) } // goxls : match the 'func' position of the corresponding overloaded function - if want := env.RegexpSearch("def.gop", `(func)\(a, b int\) int`); loc != want { + if want := env.RegexpSearch("def.gop", `func\(a, b int\) int`); loc != want { t.Errorf("GoToDefinition: got location %v, want %v", loc, want) } })