Skip to content

Commit

Permalink
update:anonymous function definition range
Browse files Browse the repository at this point in the history
  • Loading branch information
luoliwoshang committed May 17, 2024
1 parent f4ccbf1 commit fd65ba8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions gopls/internal/lsp/source/definition_gox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion gopls/internal/regtest/misc/definition_gox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
Expand Down

0 comments on commit fd65ba8

Please sign in to comment.