Comments (11)
+1
Is it idiomatic to walk through the import paths and visit some go file in each package to get it's name?
from godef.
I looked into this and it requires a lot of familiarity with how AST parsing/resolution works. With a little guidance, maybe this can be picked up. What I tried naively was to walk through pkg.Imports
and seek out any Decl[i].(_GenDecl).Specs[j].(_ImportSpec).Name == nil (in which case we want to load the package given under <same>.Path
). I have no idea whether that's the right thing to do. It seems too manual, like there should be a resolver tool that does this already.
from godef.
I think that the problem is with ImportPathToName
Line 26 in f90a996
This thing should really be going into the path specified in the import and figuring out what the name of the package contained in that path is.
from godef.
@tschottdorf I fixed this. Give the version from my pull request a try and see if it works for you.
from godef.
Is it idiomatic to walk through the import paths and visit some go file in each package to get it's name?
I feel like there should be.
@rogpeppe this solution feels pretty hacky/gross, which is why I didn't really bother to clean it up much in my PR. Let me know if you would be willing to accept something like this -- If so I'll clean it up and write a test or two.
from godef.
Also @rogpeppe why does godef seem to have its own version of the go parser/ast code?
from godef.
It looks like #3 was another (much simpler) attempt to solve this issue. What happened to that PR.
from godef.
godef has its own version of the go parser code because when it was written,
I hoped that the changes (that resolve almost all symbols at parse time)
might make it upstream. They didn't, but the fork lives on.
The reason for this bug is essentially that I wanted godef to be fast, so it takes
a shortcut which makes it wrong some of the time. That was probably not
the best decision, but it's quite a hassle to change, and probably not
worth the effort now that guru is almost there.
For the record, the speed is gained because godef resolves
all symbols without actually pulling in the import packages, so
when searching for a local symbol, it only needs to read the
local package's files. This is wrong in two cases: when an imported
package uses a different symbol from its directory name, and
when using "import .".
from godef.
@rogpeppe godef is still plenty fast with this change though. I set the only parse package mode so it should really just open ONE file in the package and read what the package is. I refuse to believe that that has enough of a performance impact to make this change unviable. At the very least, I'd like to see profiling that indicates that it has too large an effect.
Premature optimization is the root of all evil.
from godef.
@rogpeppe I hand't heard of go guru before. I just got it set up and it seems to work really well. What is merely 'almost there' about it?
from godef.
Fixed by #34
from godef.
Related Issues (20)
- Cannot find modules in $GOPATH/pkg/mod/cache/download
- godef might be extremly slow in Go packages using cgo when using go/packages
- godef by expression not working with go/packages HOT 3
- Allow a way to print the version of the godef tool
- Struct tips not pretty with go modules HOT 7
- go get github.com/rogpeppe/godef not working
- godef can't work for go while using import . ""
- godef takes ~2 seconds when used with go modules HOT 8
- godef can't work HOT 1
- When export GO111MODULE=on, the godef can not work. HOT 2
- internal error: nil Pkg importing "errors" from "mypkg" HOT 3
- godef: could not parse GOARCH and Go compiler HOT 2
- "no declaration found" when a package uses a binary literal
- include methods in members list HOT 1
- Godef fails in dependency module directories where no go.mod is present HOT 1
- Does godef support build tags?
- godef not work in go mod HOT 4
- Printing the receiver for methods when printing types
- go mod project search github.com/coreos/etcd very slow and fail HOT 1
- Support showing variable initialization values when printing types
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from godef.