Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Function complete doesn't support inline functions #1287

Closed
FiloSottile opened this issue Oct 16, 2017 · 8 comments · Fixed by #1673
Closed

Function complete doesn't support inline functions #1287

FiloSottile opened this issue Oct 16, 2017 · 8 comments · Fixed by #1673

Comments

@FiloSottile
Copy link
Contributor

If a local variable like this is defined

ensureKeyword := func (k string) {}

then ensureKeyword autocompletes to ensureKeyword without arguments even if useCodeSnippetsOnFunctionSuggestWithoutType is true.

@alexkohler
Copy link
Contributor

alexkohler commented Oct 17, 2017

It looks like we are checking if the suggest.class is 'func', whereas we should
be checking if the suggest.type contains 'func' (because a locally defined function will have a class of 'var', not func). https://github.com/Microsoft/vscode-go/blob/0.6.66/src/goSuggest.ts#L168

I.e. before:
...&& suggest.class === 'func'

My proposed solution:
...&& suggest.type.includes('func')

@ramya-rao-a thoughts?

@ramya-rao-a
Copy link
Contributor

In this case what does suggest.type have?

@alexkohler
Copy link
Contributor

alexkohler commented Oct 19, 2017

@ramya-rao-a The suggest.type would be func (k string) I think - I’ll double check this when I have access to my PC.

@alexkohler
Copy link
Contributor

@ramya-rao-a Yes, to confirm the suggest.type is func(k string). The suggest.type of the same function declared non-locally is also func(k string). Looking at all the potential edge cases, using includes does seem a little heavy handed.

@ramya-rao-a
Copy link
Contributor

by non-locally, you mean in another file in the same package?

@alexkohler
Copy link
Contributor

Not necessarily in another file, just declared in package scope rather than local scope.

I.e.:

package main

// package scoped function p
func p (k string) {}

func main() {
// locally scoped function l
l := func (k string) {}
}

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Jan 8, 2018

The suggest.type of the same function declared non-locally is also func(k string)

Wouldn't the non-locally declared function have the class as func?

So && suggest.class === 'func' could be replaced with && (suggest.class === 'func' || (suggest.class === 'var' && suggest.type.startswith('func')))

@ramya-rao-a
Copy link
Contributor

This feature is now out in the latest update to the Go extension (0.6.80)

@vscodebot vscodebot bot locked and limited conversation to collaborators Jun 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants