public static IScope GetEnclosingScope(this IAstNode node) {
var gs = node as GlobalScope;
if (gs != null) {
return gs;
}
var root = node as AstRoot;
if (root != null) {
return root.Children.Count > 0 ? root.Children[0] as IScope : null;
}
var n = node.Parent;
while (!(n is IScope) && n != null) {
n = n.Parent;
}
return n as IScope;
}
}