gocode icon indicating copy to clipboard operation
gocode copied to clipboard

Completion doesn't work in go 1.9 for type aliases

Open esemplastic opened this issue 6 years ago • 4 comments

iris.C 's origin type is mvc.C: https://github.com/kataras/iris/blob/master/mvc/controller.go#L39 iris.C type alias definition: https://github.com/kataras/iris/blob/master/go19.go#L148

The mvc.C looks like the following:

type C struct {
	Name string
	Ctx context.Context
}

func (c *C) BeginRequest(ctx context.Context) { c.Ctx = ctx }

But when embedding the type in other type, auto completion doesn't work:

problem1

Same for non-embedding, i.e return a struct that derives from a type alias:

problem2

Is this a bug, is it a feature request? I don't know but please try to look on this and fix that as soon as possible!

esemplastic avatar Oct 12 '17 17:10 esemplastic

Struct autocompletion should work now, sorry about breaking it in a recent commit. Will have a look at type aliases, but they should work. I haven't tested them on cross-package boundaries though. Most likely will have a look at it this weekend.

nsf avatar Oct 13 '17 06:10 nsf

Thanks for answering but it doesn't work, I did the update with go get -u -f github.com/nsf/gocode , both the return types (the fields are not be shown on auto completion) neither the embedded's fields and functions are shown, it's very important please take some time to fix that if you can, here's a code that you can do your tests:

file: mypackage/original/embedded_struct.go

package original

type C struct {
	Field  string
	Field2 int
}

func (c *C) BeginRequest() {

}

file: mypackage/original/return_type.go

package original

type Result interface {
	DoSomething()
}

type Response struct {
	Text string
}

func (r Response) DoSomething() {

}

file: mypackage/mypackage.go

package mypackage

import (
	"esemplastic/mypackage/original"
)

type (
	C        = original.C
	Result   = original.Result
	Response = original.Response
)

file: main.go

package main

import (
	"esemplastic/mypackage"
)

type ExampleController struct {
	mypackage.C
}

func (ex *ExampleController) Get() {
	// `ex.` doesn't give completion for the mypackage.C's:
	//	     Field  string
	//       Field2 int
	// neither the function `BeginRequest()`,
	// it only shows the field `C` and its own function `Get`.
	// but `ex.Field` or `ex.BeginRequest` is compiled and ran without errors.
	// The `ex.C.` gives completion help.
}

func (ex *ExampleController) ReturnSomething() mypackage.Result {
	return mypackage.Response{
	// field: Text string is not shown to completion help,
	// nothing except the built go functions like `append`...
	}
}

func main() {

}

Thanks!

esemplastic avatar Oct 14 '17 18:10 esemplastic

Ok, take a look please. It was a local issue (it has nothing to do with cross package boundaries). But I tested it on "iris" lib just in case. If it works for you, feel free to close the issue. If you spot any other problems with type aliases let me know. At this point there is no clear solution for type aliases in gocode, it's all just hacks on a case by case basis. But it sort of works.

nsf avatar Oct 15 '17 10:10 nsf

@esemplastic If you have installed Go via brew then you need to update your VS Code config for go.goroot to Go version 1.9.2. In my case it was something like /usr/local/Cellar/go/1.9.2/libexec/. You also have to restart VS Code and reinstall all tools.

vividvilla avatar Dec 11 '17 11:12 vividvilla