Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Commit

Permalink
internal/suggest: add the receiver to method completions
Browse files Browse the repository at this point in the history
Merge pull request #100 from segevfiner/receivers
  • Loading branch information
stamblerre authored Dec 26, 2018
2 parents 9c77a29 + af672b8 commit be056ad
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions internal/suggest/candidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (
)

type Candidate struct {
Class string `json:"class"`
PkgPath string `json:"package"`
Name string `json:"name"`
Type string `json:"type"`
Class string `json:"class"`
PkgPath string `json:"package"`
Name string `json:"name"`
Type string `json:"type"`
Receiver string `json:"receiver,omitempty"`
}

func (c Candidate) Suggestion() string {
Expand Down Expand Up @@ -129,11 +130,19 @@ func (b *candidateCollector) asCandidate(obj types.Object) Candidate {
path = pkg.Path()
}

var receiver string
if sig, ok := typ.(*types.Signature); ok && sig.Recv() != nil {
receiver = types.TypeString(sig.Recv().Type(), func(*types.Package) string {
return ""
})
}

return Candidate{
Class: objClass,
PkgPath: path,
Name: obj.Name(),
Type: typStr,
Class: objClass,
PkgPath: path,
Name: obj.Name(),
Type: typStr,
Receiver: receiver,
}
}

Expand Down

0 comments on commit be056ad

Please sign in to comment.