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

Conversation

segevfiner
Copy link

Fixes #9

P.S. I think the type for method expressions already includes the first receiver argument without any further changes to our code. At least it did when I tried it.

This can be used to fix microsoft/vscode-go#2107

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

receiver := ""
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 ""
    })
}

@@ -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 {
receiver = types.TypeString(receiverVar.Type(), func(*types.Package) string { return "" })
if sig.Recv() != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

sorry, one last comment - you can avoid the nested if with:

if sig, ok := typ.(*types.Signature); ok && sig.Recv() != nil {

@stamblerre
Copy link
Collaborator

thanks!

@stamblerre stamblerre merged commit be056ad into mdempsky:master Dec 26, 2018
@segevfiner segevfiner deleted the receivers branch December 26, 2018 18:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants