Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
Fix missing returns to prevent multiple replies
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-hov committed Apr 1, 2024
1 parent 6a95413 commit 720caae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions internal/lsp/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func definitionSelectorExpr(ctx context.Context, s *server, reply jsonrpc2.Repli

func definitionMethodDecl(ctx context.Context, reply jsonrpc2.Replier, params protocol.DefinitionParams, pkg *Package, i *ast.Ident, decl *ast.FuncDecl) error {
if decl.Recv.NumFields() != 1 || decl.Recv.List[0].Type == nil {
reply(ctx, nil, nil)
return reply(ctx, nil, nil)
}

var key string
Expand All @@ -278,12 +278,12 @@ func definitionMethodDecl(ctx context.Context, reply jsonrpc2.Replier, params pr
case *ast.Ident:
key = fmt.Sprintf("%s", rt.Name)
default:
reply(ctx, nil, nil)
return reply(ctx, nil, nil)
}

methods, ok := pkg.Methods.Get(key)
if !ok {
reply(ctx, nil, nil)
return reply(ctx, nil, nil)
}

var fileUri uri.URI
Expand Down
14 changes: 9 additions & 5 deletions internal/lsp/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ func hoverSelectorExpr(ctx context.Context, s *server, reply jsonrpc2.Replier, p
}, nil)
}
} else {
header := fmt.Sprintf("%s %s %s", mode(*tv), i.Name, tvStr)
t := tvStr
if strings.Contains(tvStr, pkg.ImportPath) {
t = strings.Replace(tvStr, pkg.ImportPath+".", "", 1)
}
header := fmt.Sprintf("%s %s %s", mode(*tv), i.Name, t)
return reply(ctx, protocol.Hover{
Contents: protocol.MarkupContent{
Kind: protocol.Markdown,
Expand All @@ -306,7 +310,7 @@ func hoverSelectorExpr(ctx context.Context, s *server, reply jsonrpc2.Replier, p

func hoverMethodDecl(ctx context.Context, reply jsonrpc2.Replier, params protocol.HoverParams, pkg *Package, i *ast.Ident, decl *ast.FuncDecl) error {
if decl.Recv.NumFields() != 1 || decl.Recv.List[0].Type == nil {
reply(ctx, nil, nil)
return reply(ctx, nil, nil)
}

var key string
Expand All @@ -316,12 +320,12 @@ func hoverMethodDecl(ctx context.Context, reply jsonrpc2.Replier, params protoco
case *ast.Ident:
key = fmt.Sprintf("%s", rt.Name)
default:
reply(ctx, nil, nil)
return reply(ctx, nil, nil)
}

methods, ok := pkg.Methods.Get(key)
if !ok {
reply(ctx, nil, nil)
return reply(ctx, nil, nil)
}

var header, body string
Expand Down Expand Up @@ -457,7 +461,7 @@ func hoverPackageLevelTypes(ctx context.Context, reply jsonrpc2.Replier, params
}

if header == "" {
reply(ctx, nil, nil)
return reply(ctx, nil, nil)
}

return reply(ctx, protocol.Hover{
Expand Down

0 comments on commit 720caae

Please sign in to comment.