code: func (p *pkg) scopeOf(id *ast.Ident) *types.Scope {
  	var scope *types.Scope
  	if obj := p.typesInfo.ObjectOf(id); obj != nil {
  		scope = obj.Parent()
  	}
  	if scope == p.typesPkg.Scope() {
  		// We were given a top-level identifier.
  		// Use the file-level scope instead of the package-level scope.
  		pos := id.Pos()
  		for _, f := range p.files {
  			if f.f.Pos() <= pos && pos < f.f.End() {
  				scope = p.typesInfo.Scopes[f.f]
  				break
  			}
  		}
  	}
  	return scope
  }
docs: // scopeOf returns the tightest scope encompassing id.