Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
Fix definition and hover for var of type imported
Browse files Browse the repository at this point in the history
Curretly if you hover on method of var of type imported package. It shows nothing. Fixed it.
  • Loading branch information
harry-hov committed Apr 1, 2024
1 parent 92d553b commit d56aa88
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
31 changes: 24 additions & 7 deletions internal/lsp/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,31 @@ func definitionSelectorExpr(ctx context.Context, s *server, reply jsonrpc2.Repli

for _, spec := range pgf.File.Imports {
path := spec.Path.Value[1 : len(spec.Path.Value)-1]
if strings.Contains(tvParentStr, path) { // of pkg name
symbol := s.completionStore.lookupSymbol(path, i.Name)
if symbol == nil {
// TODO: fix
// getting nil even when it is not supposed to be
if strings.Contains(tvParentStr, path) { // hover on parent var of kind import
parts := strings.Split(path, "/")
last := parts[len(parts)-1]
pkg := s.completionStore.lookupPkg(last)
if pkg == nil {
break
}
tvParentStrParts := strings.Split(tvParentStr, ".")
parentType := tvParentStrParts[len(tvParentStrParts)-1]
methods, ok := pkg.Methods.Get(parentType)
if !ok {
break
}
var fileUri uri.URI
var pos token.Position
for _, m := range methods {
if m.Name == i.Name {
fileUri = m.FileURI
pos = m.Position
}
}

if fileUri == "" {
break
}
fileUri := symbol.FileURI
pos := symbol.Position

return reply(ctx, protocol.Location{
URI: fileUri,
Expand All @@ -215,6 +231,7 @@ func definitionSelectorExpr(ctx context.Context, s *server, reply jsonrpc2.Repli
),
}, nil)
}

}

// can be non gno.land import
Expand Down
30 changes: 23 additions & 7 deletions internal/lsp/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func hoverSelectorExpr(ctx context.Context, s *server, reply jsonrpc2.Replier, p
path := spec.Path.Value[1 : len(spec.Path.Value)-1]
parts := strings.Split(path, "/")
last := parts[len(parts)-1]
if last == i.Name { // hover of pkg name
if last == i.Name { // hover on pkg name
header := fmt.Sprintf("package %s (%s)", last, spec.Path.Value)
body := func() string {
if strings.HasPrefix(path, "gno.land/") {
Expand Down Expand Up @@ -206,18 +206,34 @@ func hoverSelectorExpr(ctx context.Context, s *server, reply jsonrpc2.Replier, p

for _, spec := range pgf.File.Imports {
path := spec.Path.Value[1 : len(spec.Path.Value)-1]
if strings.Contains(tvParentStr, path) { // hover of pkg name
symbol := s.completionStore.lookupSymbol(path, i.Name)
if symbol == nil {
// TODO: fix
// getting nil even when it is not supposed to be
if strings.Contains(tvParentStr, path) { // hover on parent var of kind import
parts := strings.Split(path, "/")
last := parts[len(parts)-1]
pkg := s.completionStore.lookupPkg(last)
if pkg == nil {
break
}
tvParentStrParts := strings.Split(tvParentStr, ".")
parentType := tvParentStrParts[len(tvParentStrParts)-1]
methods, ok := pkg.Methods.Get(parentType)
if !ok {
break
}
var header, body string
for _, m := range methods {
if m.Name == i.Name {
header = m.Signature
body = m.Doc
}
}
if header == "" {
break
}

return reply(ctx, protocol.Hover{
Contents: protocol.MarkupContent{
Kind: protocol.Markdown,
Value: symbol.String(),
Value: FormatHoverContent(header, body),
},
Range: posToRange(
int(params.Position.Line),
Expand Down

0 comments on commit d56aa88

Please sign in to comment.