-
Notifications
You must be signed in to change notification settings - Fork 141
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
Support for type aliases #77
Conversation
go/types/types.go
Outdated
return false | ||
} | ||
ts, ok := obj.Decl.(*ast.TypeSpec) | ||
return ok && ts.Assign != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe should use IsValid() method:
return ok && ts.Assign.IsValid()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I agree, will push an updated commit.
go/parser/parser.go
Outdated
@@ -2027,8 +2027,12 @@ func parseTypeSpec(p *parser, doc *ast.CommentGroup, decl *ast.GenDecl, _ int) a | |||
// at the identifier in the TypeSpec and ends at the end of the innermost | |||
// containing block. | |||
// (Global identifiers are resolved in a separate phase after parsing.) | |||
spec := &ast.TypeSpec{doc, ident, nil, p.lineComment} | |||
spec := &ast.TypeSpec{doc, ident, 0, nil, p.lineComment} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use token.NoPos ?
spec := &ast.TypeSpec{doc, ident, token.NoPos, nil, p.lineComment}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, done.
go/parser/parser.go
Outdated
@@ -2027,8 +2027,12 @@ func parseTypeSpec(p *parser, doc *ast.CommentGroup, decl *ast.GenDecl, _ int) a | |||
// at the identifier in the TypeSpec and ends at the end of the innermost | |||
// containing block. | |||
// (Global identifiers are resolved in a separate phase after parsing.) | |||
spec := &ast.TypeSpec{doc, ident, nil, p.lineComment} | |||
spec := &ast.TypeSpec{doc, ident, 0, nil, p.lineComment} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not enough, should add some line to parse rightly
+ spec := &ast.TypeSpec{doc, ident, token.NoPos, nil, p.lineComment}
p.declare(spec, p.topScope, ast.Typ, ident)
+ if p.tok == token.ASSIGN {
+ spec.Assign = p.pos
+ p.next()
+ }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must be missing something, apart from the token.NoPos
change (which I've just made), your proposal looks identical to what is already there to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my fault, confused with the pull-request page ;)
Fixes rogpeppe#71 and supercedes rogpeppe#69. Handles the case described in rogpeppe#69 (comment), i.e. ``` $ cat <<EOF | ./godef -i -o 106 package main import "encoding/json" func xxxx() { type foo = json.Encoder x := new(foo) _ = x.Encode } EOF /usr/lib/go-1.10/src/encoding/json/stream.go:195:21 ``` i.e. it correctly finds the definition of `x.Encode` (offset 106 is on the `E`) Also: ``` $ cat <<EOF | ./godef -i -o 91 package main import "encoding/json" func xxxx() { type foo = json.Encoder x := new(foo) _ = x.Encode } EOF 4:10 ``` Where offset 91 is the `f` in `new(foo)` and `4:10` is the `json.Encoder`
@rogpeppe any thoughts on this one? |
I've been testing this PR for a month and it works perfectly. |
@rogpeppe I've been running this fix for a while now and everything seems to be good! Do you have any input on this PR? |
Based on the amount of activity in this repo from @rogpeppe; I would agree. But I think that "just" making a fork wouldn't help the community in the long run. Perhaps something like a public notice first, where we would impose a discussion about the future of this project. This is not only for the go community, but also for @rogpeppe. There are a couple of issues open which are not that difficult to solve and are critical to the usability of this tool (eq: #77, #83). I hope that enough gophers in the vscode user-base agree with your statement, and are willing to invest some time in the survival of this project. @marwan-at-work what do you think? If you agree I will draft a notice, create a new issue, and make an attempt to get some public attention. |
If there are no objections from the participants in this issue by Monday 12:00(GMT+2), I will move ahead with creating the public notice. And also propose a timeline which will include merging this pull request. |
@rogpeppe should me move forward on this PR? I think PR should works. Some of the functionality on vscode-go depends on this |
@rogpeppe kindly need your help on this |
Hi @rogpeppe, we are still waiting for this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks. And abject apologies for leaving this so long. It could use a test in go/types/types_test.go but I can add that.
Thanks @rogpeppe and welcome back! |
I tend to doubt it. I seem to have this same problem, and I checked that the Merge above in in my workspace for godef |
I take that back. I installed the version built from that code and it seems to have fixed it. In case the use case matters to anyone. I was using godef from GoClipse |
Fixes #71 and supercedes #69. Handles the case described in #69 (comment), i.e.
i.e. it correctly finds the definition of
x.Encode
(offset 106 is on theE
)Also:
Where offset 91 is the
f
innew(foo)
and4:10
is thejson.Encoder