Skip to content

Commit

Permalink
Merge pull request #15 from d4l3k/fix15
Browse files Browse the repository at this point in the history
pry: go-pry now properly works on go1.5
  • Loading branch information
d4l3k authored Dec 25, 2016
2 parents 000bbde + 4022dc7 commit 300c4dc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
30 changes: 30 additions & 0 deletions pry/importer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// +build !go1.5

package pry

import (
"go/types"

gcimporter "golang.org/x/tools/go/gcimporter15"
)

var gcImporter = importer{
impFn: gcimporter.Import,
packages: make(map[string]*types.Package),
}

// importer implements go/types.Importer.
// It also implements go/types.ImporterFrom, which was new in Go 1.6,
// so vendoring will work.
type importer struct {
impFn func(packages map[string]*types.Package, path, srcDir string) (*types.Package, error)
packages map[string]*types.Package
}

func (i importer) Import(path string) (*types.Package, error) {
return i.impFn(i.packages, path, "")
}

func (i importer) ImportFrom(path, srcDir string, mode types.ImportMode) (*types.Package, error) {
return i.impFn(i.packages, path, srcDir)
}
7 changes: 7 additions & 0 deletions pry/importer15.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build go1.5

package pry

import gcimporter "go/importer"

var gcImporter = gcimporter.Default()
22 changes: 1 addition & 21 deletions pry/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"go/types"
// Used by types for import determination
"golang.org/x/tools/go/gcimporter15"
)

// Scope is a string-interface key-value pair that represents variables/functions in scope.
Expand Down Expand Up @@ -593,10 +592,7 @@ func (scope *Scope) ConfigureTypes(path string, line int) error {
scope.fset = token.NewFileSet() // positions are relative to fset
scope.config = &types.Config{
FakeImportC: true,
Importer: importer{
impFn: gcImporter,
packages: make(map[string]*types.Package),
},
Importer: gcImporter,
}

// Parse the file containing this very example
Expand Down Expand Up @@ -746,19 +742,3 @@ func ValuesToInterfaces(vals []reflect.Value) []interface{} {
}
return inters
}

// These lines were taken from github.com/golang/lint, see that project for
// more information.
var gcImporter = gcimporter.Import

// importer implements go/types.Importer.
// It also implements go/types.ImporterFrom, which was new in Go 1.6,
// so vendoring will work.
type importer struct {
impFn func(packages map[string]*types.Package, path, srcDir string) (*types.Package, error)
packages map[string]*types.Package
}

func (i importer) Import(path string) (*types.Package, error) {
return i.impFn(i.packages, path, "")
}
17 changes: 0 additions & 17 deletions pry/pry16.go

This file was deleted.

0 comments on commit 300c4dc

Please sign in to comment.