Skip to content

Commit

Permalink
getIdentNodes() to get idents from Expr
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-hov committed Jan 24, 2024
1 parent 84a6613 commit 255d749
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions internal/lsp/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,23 @@ func (s *server) hoverPackageIdent(ctx context.Context, reply jsonrpc2.Replier,
return reply(ctx, nil, nil)
}

// getIdentNodes return idents from Expr
// Note: only handles *ast.SelectorExpr and *ast.CallExpr
func getIdentNodes(n ast.Node) []*ast.Ident {
res := []*ast.Ident{}
switch t := n.(type) {
case *ast.Ident:
res = append(res, t)
case *ast.SelectorExpr:
res = append(res, t.Sel)
res = append(res, getIdentNodes(t.X)...)
case *ast.CallExpr:
res = append(res, getIdentNodes(t.Fun)...)
}

return res
}

func (s *server) hoverVariableIdent(ctx context.Context, reply jsonrpc2.Replier, pgf *ParsedGnoFile, params protocol.HoverParams, i *ast.Ident) error {
if i.Obj != nil {
switch u := i.Obj.Decl.(type) {
Expand Down

0 comments on commit 255d749

Please sign in to comment.