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

Add the receiver to method completions #100

Merged
merged 4 commits into from
Dec 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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