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 2 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()
}

receiver := ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var receiver string

if sig, ok := typ.(*types.Signature); ok {
if receiverVar := sig.Recv(); receiverVar != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simpler:

if sig.Recv() != nil {
    receiver = types.TypeString(sig.Recv().Type(), func(*types.Package) string {
        return ""
    })
}

receiver = types.TypeString(receiverVar.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