godef icon indicating copy to clipboard operation
godef copied to clipboard

godef: no declaration found when using dot import syntax

Open athom opened this issue 9 years ago • 3 comments

It works when the code looks like this.

file: main.go

package main

import (
    "fmt"
    "time"
)

func main() {
    ti := time.Now()
    fmt.Println(ti)
}
➜  godef -f=./main.go -o=68
/usr/local/Cellar/go/1.5/libexec/src/time/time.go:781:6

but it failed when the code change to this:

file: main.go

package main

import (
    "fmt"
    . "time"
)

func main() {
    ti := Now()
    fmt.Println(ti)
}
➜  godef -f=./main.go -o=65
parseLocalPackage error: no more package files found
godef: no declaration found for Now

athom avatar Nov 02 '15 07:11 athom

This is a known issue with godef. In general, dot imports are a bad idea, but this should probably be fixed some time.

rogpeppe avatar May 27 '16 10:05 rogpeppe

For testing dot imports are pretty useful, for example ginkgo and goconvey use it to good effect.

It's also useful when putting tests in a separate package, e.g. package foo_test

Alexendoo avatar Sep 27 '16 20:09 Alexendoo

Any plans to fix this?

sdwarwick avatar Nov 10 '16 16:11 sdwarwick