Skip to content

Commit

Permalink
Add helper FormatHoverContent()
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-hov committed Jan 17, 2024
1 parent dedec21 commit f4f7cfc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/lsp/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (s *server) Hover(ctx context.Context, reply jsonrpc2.Replier, req jsonrpc2
parts := strings.Split(path, "/")
last := parts[len(parts)-1]
if last == i.Name {
header := fmt.Sprintf("```gno\npackage %s (%s)\n```\n\n", last, spec.Path.Value)
header := fmt.Sprintf("package %s (%s)", last, spec.Path.Value)
body := func() string {
if strings.HasPrefix(path, "gno.land/") {
return fmt.Sprintf("[```%s``` on gno.land](https://%s)", last, path)
Expand All @@ -164,7 +164,7 @@ func (s *server) Hover(ctx context.Context, reply jsonrpc2.Replier, req jsonrpc2
return reply(ctx, protocol.Hover{
Contents: protocol.MarkupContent{
Kind: protocol.Markdown,
Value: header + body,
Value: FormatHoverContent(header, body),
},
Range: posToRange(
int(params.Position.Line),
Expand Down Expand Up @@ -197,6 +197,10 @@ func (s *server) Hover(ctx context.Context, reply jsonrpc2.Replier, req jsonrpc2
return reply(ctx, nil, nil)
}

func FormatHoverContent(header, body string) string {
return fmt.Sprintf("```gno\n%s\n```\n\n%s", header, body)
}

// handleSelectorExpr returns jsonrpc2.Replier for Hover
// on SelectorExpr
// TODO: Move duplicate logic here
Expand Down

0 comments on commit f4f7cfc

Please sign in to comment.