Skip to content

load std package list to check if a package is a really "std" lib #208

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,22 @@ import (
"strings"

"golang.org/x/tools/go/callgraph"
"golang.org/x/tools/go/packages"
"golang.org/x/tools/go/ssa"
)

var stdPackages = map[string]struct{}{}

func init() {
pkgs, err := packages.Load(nil, "std")
if err != nil {
panic(err)
}
for _, p := range pkgs {
stdPackages[p.PkgPath] = struct{}{}
}
}

func isSynthetic(edge *callgraph.Edge) bool {
// TODO: consider handling callee.Func.Pkg == nil
// this could still generate a node for the call, might be useful
Expand All @@ -25,10 +38,8 @@ func inStd(node *callgraph.Node) bool {
}

func isStdPkgPath(path string) bool {
if strings.Contains(path, ".") {
return false
}
return true
_, ok := stdPackages[path]
return ok
}

func printOutput(
Expand Down
Loading