private static IEnumerable<Symbol> LookupSymbols(Binder binder)
{
// NOTE: We want to only show the *available* symbols. That means, we need to
// hide symbols from the parent binder that have same name as the ones
// from a nested binder.
//
// We do this by simply recording which names we've already seen.
// Please note that we *do* want to see duplicate names within the
// *same* binder.
var allNames = new HashSet<string>();
while (binder != null)
{
var localNames = new HashSet<string>();
var localSymbols = binder.LocalSymbols
.SelectMany(x => x.Value)
.Where(s => !string.IsNullOrEmpty(s.Name));
foreach (var symbol in localSymbols)
{
if (!allNames.Contains(symbol.Name))
{
localNames.Add(symbol.Name);
yield return symbol;
}
}
allNames.UnionWith(localNames);
binder = binder.Parent;
}
}