From 720caaef4e8b0495f5530039b721f5e6229a2dc9 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Mon, 1 Apr 2024 16:11:30 +0530 Subject: [PATCH] Fix missing returns to prevent multiple replies --- internal/lsp/definition.go | 6 +++--- internal/lsp/hover.go | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/internal/lsp/definition.go b/internal/lsp/definition.go index 67a24b9..c8c7e20 100644 --- a/internal/lsp/definition.go +++ b/internal/lsp/definition.go @@ -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 @@ -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 diff --git a/internal/lsp/hover.go b/internal/lsp/hover.go index 5b34d8c..bc49f2b 100644 --- a/internal/lsp/hover.go +++ b/internal/lsp/hover.go @@ -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, @@ -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 @@ -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 @@ -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{