Skip to content

Commit

Permalink
Format hover for var of type imported pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-hov committed Apr 1, 2024
1 parent d56aa88 commit 6a95413
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions internal/lsp/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,25 @@ func (s *server) Hover(ctx context.Context, reply jsonrpc2.Replier, req jsonrpc2
return hoverPackageLevelValue(ctx, reply, params, pkg, n, tv, m, typeStr, isPackageLevelGlobal)
}

// TODO: remove? handles var from imported packages
header := fmt.Sprintf("%s %s %s", m, n.Name, typeStr)
// if var of type imported package
var header string
if strings.Contains(typeStr, "gno.land/") {
for _, spec := range pgf.File.Imports {
path := spec.Path.Value[1 : len(spec.Path.Value)-1]
if strings.Contains(typeStr, path) {
parts := strings.Split(path, "/")
last := parts[len(parts)-1]
t := strings.Replace(typeStr, path, last, 1)
header = fmt.Sprintf("%s %s %s", m, n.Name, t)
break
}
}
} else { // rest of the cases
header = fmt.Sprintf("%s %s %s", m, n.Name, typeStr)
}

// Handles rest of the cases
// TODO: improve?
return reply(ctx, protocol.Hover{
Contents: protocol.MarkupContent{
Kind: protocol.Markdown,
Expand Down

0 comments on commit 6a95413

Please sign in to comment.