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

Support for type aliases #77

Merged
merged 1 commit into from
Sep 11, 2018
Merged

Support for type aliases #77

merged 1 commit into from
Sep 11, 2018

Conversation

ijc
Copy link
Contributor

@ijc ijc commented Mar 16, 2018

Fixes #71 and supercedes #69. Handles the case described in #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

return false
}
ts, ok := obj.Decl.(*ast.TypeSpec)
return ok && ts.Assign != 0
Copy link

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()

Copy link
Contributor Author

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.

@@ -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}
Copy link

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}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, done.

@@ -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}
Copy link

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()
+	}

Copy link
Contributor Author

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.

Copy link

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`
@ijc
Copy link
Contributor Author

ijc commented Apr 3, 2018

@rogpeppe any thoughts on this one?

@chessman
Copy link

chessman commented May 2, 2018

I've been testing this PR for a month and it works perfectly.

@Asarew
Copy link

Asarew commented May 24, 2018

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

@marwan-at-work
Copy link

marwan-at-work commented Jun 26, 2018

@Asarew Should this repo be officially forked? Seems like @rogpeppe is unresponsive and this tool is much faster to work with on vscode than other ones :)

@Asarew
Copy link

Asarew commented Jun 27, 2018

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.

@Asarew
Copy link

Asarew commented Jun 28, 2018

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.

@uudashr
Copy link
Contributor

uudashr commented Jul 27, 2018

@rogpeppe should me move forward on this PR? I think PR should works. Some of the functionality on vscode-go depends on this

@Asarew Asarew mentioned this pull request Aug 6, 2018
@uudashr
Copy link
Contributor

uudashr commented Aug 10, 2018

@rogpeppe kindly need your help on this

@Asarew
Copy link

Asarew commented Aug 10, 2018

I have teamed up with the Gofrs to help out @rogpeppe maintain and update this community wide used project. See issue #86 to follow the discussion.

@uudashr
Copy link
Contributor

uudashr commented Sep 10, 2018

Hi @rogpeppe, we are still waiting for this PR.
On vscode-go, for some project that has dependencies use alias, the definition are broken causing hovering info doesn't shown. I've seen that this PR solve the issues.

Copy link
Owner

@rogpeppe rogpeppe left a 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.

@rogpeppe rogpeppe merged commit 8312188 into rogpeppe:master Sep 11, 2018
@ijc ijc deleted the type-aliases branch September 12, 2018 10:01
@ijc
Copy link
Contributor Author

ijc commented Sep 12, 2018

Thanks @rogpeppe and welcome back!

@GerryG
Copy link

GerryG commented Sep 30, 2018

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

@GerryG
Copy link

GerryG commented Sep 30, 2018

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

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

Successfully merging this pull request may close these issues.

8 participants