Skip to content

Commit

Permalink
address TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
tbruyelle committed Aug 6, 2024
1 parent d116a95 commit 588aa9d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions internal/handler/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@ func (h *handler) handleTextDocumentCompletion(ctx context.Context, reply jsonrp
pos := gotoken.Pos(doc.PositionToOffset(params.Position))
nodes, _ := astutil.PathEnclosingInterval(doc.Pgf.File, pos, pos)
spew.Dump("ENCLOSING NODES", nodes)
// TODO use this func in other places (check for ast.Ident usage)
nodeName := func(n ast.Node) string {
if id, ok := n.(*ast.Ident); ok {
return id.Name
}
return ""
}

for _, n := range nodes {
var syms []gno.Symbol
switch n := n.(type) {
Expand All @@ -71,9 +65,8 @@ func (h *handler) handleTextDocumentCompletion(ctx context.Context, reply jsonrp
}

case *ast.SelectorExpr:
if id, ok := n.X.(*ast.Ident); ok {
// look up in subpackages (TODO also add imported packages)
pkg := id.Name
// look up in subpackages (TODO also add imported packages)
if pkg := nodeName(n.X); pkg != "" {
// look up pkg in subpkgs
for _, sub := range h.subPkgs {
if sub.Name == pkg {
Expand Down Expand Up @@ -293,3 +286,10 @@ func (s symbolFinder) findIn(symbols []gno.Symbol, selectors []string) []gno.Sym
}
return syms
}

func nodeName(n ast.Node) string {
if id, ok := n.(*ast.Ident); ok {
return id.Name
}
return ""
}

0 comments on commit 588aa9d

Please sign in to comment.