code: func CollectPackages(infos map[string]*FileInfo, protos []string, importDirs []string) (map[string]*PackageInfo, error) {
  	pkgMap := map[string]*PackageInfo{}
  
  	// Collect into packages.
  	for _, info := range infos {
  		packageInfo, ok := pkgMap[info.ComputedPackage]
  		if !ok {
  			packageInfo = &PackageInfo{ComputedPackage: info.ComputedPackage}
  			pkgMap[info.ComputedPackage] = packageInfo
  		}
  		packageInfo.Files = append(packageInfo.Files, info)
  	}
  
  	// Collect deps for each package.
  	for _, pkg := range pkgMap {
  		deps := map[string]*FileInfo{}
  		for _, info := range pkg.Files {
  			for _, dep := range info.Deps {
  				deps[dep] = infos[dep]
  			}
  		}
  		for _, dep := range deps {
  			pkg.Deps = append(pkg.Deps, dep)
  		}
  	}
  
  	return pkgMap, nil
  }
docs: // CollectPackages returns a map of PackageInfos.