Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completion doesn't work in go 1.9 for type aliases #479

Open
esemplastic opened this issue Oct 12, 2017 · 4 comments
Open

Completion doesn't work in go 1.9 for type aliases #479

esemplastic opened this issue Oct 12, 2017 · 4 comments

Comments

@esemplastic
Copy link

esemplastic commented Oct 12, 2017

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!

@nsf
Copy link
Owner

nsf commented Oct 13, 2017

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.

@esemplastic
Copy link
Author

esemplastic commented Oct 14, 2017

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!

@nsf
Copy link
Owner

nsf commented Oct 15, 2017

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.

@vividvilla
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants