Git Product home page Git Product logo

Comments (11)

zippoxer avatar zippoxer commented on July 28, 2024

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

tbg avatar tbg commented on July 28, 2024

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.

colonelpanic8 avatar colonelpanic8 commented on July 28, 2024

I think that the problem is with ImportPathToName

func ImportPathToName(p string) string {

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.

colonelpanic8 avatar colonelpanic8 commented on July 28, 2024

@tschottdorf I fixed this. Give the version from my pull request a try and see if it works for you.

from godef.

colonelpanic8 avatar colonelpanic8 commented on July 28, 2024

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.

colonelpanic8 avatar colonelpanic8 commented on July 28, 2024

Also @rogpeppe why does godef seem to have its own version of the go parser/ast code?

from godef.

colonelpanic8 avatar colonelpanic8 commented on July 28, 2024

It looks like #3 was another (much simpler) attempt to solve this issue. What happened to that PR.

from godef.

rogpeppe avatar rogpeppe commented on July 28, 2024

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.

colonelpanic8 avatar colonelpanic8 commented on July 28, 2024

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

colonelpanic8 avatar colonelpanic8 commented on July 28, 2024

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

rogpeppe avatar rogpeppe commented on July 28, 2024

Fixed by #34

from godef.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.