Support for getting a bound scope at a specific character position
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Upsilon.Binder;
|
||||
|
||||
@@ -7,17 +8,35 @@ namespace Upsilon.Utilities
|
||||
{
|
||||
public static BoundScope GetScopeAt(this BoundScript script, int characterPosition)
|
||||
{
|
||||
var scope = script.Scope;
|
||||
foreach (var node in script.GetNodeAtPosition(characterPosition))
|
||||
{
|
||||
|
||||
if (node is IBoundNodeScopeOwner scopeOwner && scopeOwner.Scope != null)
|
||||
{
|
||||
return scopeOwner.Scope;
|
||||
}
|
||||
}
|
||||
return scope;
|
||||
return script.Scope;
|
||||
}
|
||||
|
||||
public static BoundNode GetBottomNodeAtPosition(this BoundNode node, int characterPosition)
|
||||
{
|
||||
return node.GetNodeAtPosition(characterPosition).First();
|
||||
}
|
||||
|
||||
public static Dictionary<string, VariableSymbol> GetBoundScopeVisibleVariables(this BoundScope scope)
|
||||
{
|
||||
IEnumerable<KeyValuePair<string, VariableSymbol>> dictionary = scope.Variables;
|
||||
if (scope.ParentScope != null)
|
||||
{
|
||||
dictionary= dictionary.Union(scope.ParentScope.GetBoundScopeVisibleVariables());
|
||||
}
|
||||
|
||||
if (scope.ReadOnlyScope != null)
|
||||
{
|
||||
dictionary = dictionary.Union(scope.ReadOnlyScope.GetBoundScopeVisibleVariables());
|
||||
}
|
||||
|
||||
return dictionary.ToDictionary(k => k.Key, v => v.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user