aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-03-11 19:46:43 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-03-11 19:46:43 +0200
commit057b7d9d9916144fed099ac8573a864c45cd0146 (patch)
tree5e32e59ea55d3bf4066670b0cdb39901db537bf5 /Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors
parentac251de510cfb75c2967f85efc17ac8f8ad20ea0 (diff)
downloadTango-057b7d9d9916144fed099ac8573a864c45cd0146.tar.gz
Tango-057b7d9d9916144fed099ac8573a864c45cd0146.zip
Working on script engine.
Diffstat (limited to 'Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors')
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/MethodDescription.cs2
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/ScriptEditor.cs177
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Themes/Generic.xaml13
3 files changed, 186 insertions, 6 deletions
diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/MethodDescription.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/MethodDescription.cs
index 864072952..70e0d028d 100644
--- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/MethodDescription.cs
+++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Popups/MethodDescription.cs
@@ -11,6 +11,8 @@ namespace Tango.Scripting.Editors.Popups
public String Description { get; set; }
public String ReturnType { get; set; }
public List<ParameterDescription> Parameters { get; set; }
+ public String Class { get; set; }
+ public String Name { get; set; }
public MethodDescription()
{
diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/ScriptEditor.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/ScriptEditor.cs
index d2f5dd169..e43322711 100644
--- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/ScriptEditor.cs
+++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/ScriptEditor.cs
@@ -73,6 +73,12 @@ namespace Tango.Scripting.Editors
public String MethodName { get; set; }
}
+ private class DeclaredMethodSession
+ {
+ public ScriptType Type { get; set; }
+ public ScriptSymbol Method { get; set; }
+ }
+
#endregion
#region Properties
@@ -436,6 +442,74 @@ namespace Tango.Scripting.Editors
return null;
}
+ private DeclaredMethodSession GetDeclaredMethodSession()
+ {
+ var expression = GetPreviousWords().LastOrDefault();
+
+ if (expression != null)
+ {
+ var tree = expression.Split('.').Select(x => x.Replace("\n", "").Replace("\r", "").Replace(" ", "").Replace("\t", "").Replace("(", "").Replace(")", "").Replace("[", "").Replace("]", "")).ToList();
+ var variableName = tree.FirstOrDefault();
+
+ if (variableName != null && tree.Count > 0)
+ {
+ tree.RemoveAt(0);
+ var variables = _parser.GetContextSymbols(Document.Text, CaretOffset);
+ var variable = variables.FirstOrDefault(x => x.Name == variableName);
+
+ if (variable != null)
+ {
+ var declaredType = _declaredTypes.FirstOrDefault(x => x.Name == Regex.Replace(variable.Class, "<.+>", "<T>"));
+
+ if (declaredType != null)
+ {
+ while (tree.Count > 1)
+ {
+ var memberName = tree.First();
+ tree.RemoveAt(0);
+ var member = declaredType.Symbols.FirstOrDefault(x => x.Name == memberName);
+
+ if (member == null)
+ {
+ return null;
+ }
+
+ declaredType = _declaredTypes.FirstOrDefault(x => x.ContainingNamespace + "." + x.Name == member.ContainingNamespace + "." + member.Type);
+ }
+
+ var methodName = tree.Count > 0 ? tree.Last() : variableName;
+
+ var method = declaredType.Symbols.FirstOrDefault(x => x.Kind == SymbolKind.Method && x.Name == methodName);
+
+ if (method != null)
+ {
+ return new DeclaredMethodSession()
+ {
+ Type = declaredType,
+ Method = method,
+ };
+ }
+ }
+ else if (tree.Count == 0)
+ {
+ var method = variable;
+
+ if (method != null)
+ {
+ return new DeclaredMethodSession()
+ {
+ Type = declaredType,
+ Method = method,
+ };
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
public List<String> GetPreviousWords()
{
var currentLine = GetCurrentLine();
@@ -687,7 +761,7 @@ namespace Tango.Scripting.Editors
String currentWord = previousWordsLast != null ? previousWordsLast.Replace("\t", "") : String.Empty;
String currentWordIncludingParenthesis = currentWord.Split('(').LastOrDefault();
- if (previousWords.Count > 0 && previousWords.First().StartsWith("//")) return;
+ if (previousWords.Count > 0 && previousWords.First().Trim().StartsWith("//")) return;
if (e.Text == " " && GetPreviousWord() == "new")
{
@@ -773,15 +847,29 @@ namespace Tango.Scripting.Editors
if (member.Kind == SymbolKind.Method)
{
- data.Add(new MethodCompletionItem()
+ var methodCompletion = new MethodCompletionItem()
{
Class = declaredType.Name,
Name = member.Name,
ReturnType = member.Type,
Description = member.Summary,
- //Parameters = method.Parameters,
Overloads = methodGroup.Count() - 1,
- });
+ };
+
+
+ for (int i = 0; i < member.Parameters.Count; i++)
+ {
+ var pair = member.Parameters[i];
+
+ methodCompletion.Parameters.Add(new KnownTypeMethodParameter()
+ {
+ Type = pair.Key,
+ Name = pair.Value,
+ IsLast = (i == member.Parameters.Count - 1)
+ });
+ }
+
+ data.Add(methodCompletion);
}
else if (member.Kind == SymbolKind.Property)
@@ -824,6 +912,7 @@ namespace Tango.Scripting.Editors
if (content.Methods.Count > 0)
{
ShowPopup(content);
+ return;
}
}
@@ -835,6 +924,19 @@ namespace Tango.Scripting.Editors
if (content.Methods.Count > 0)
{
ShowPopup(content);
+ return;
+ }
+ }
+
+ var declaredMethodSession = GetDeclaredMethodSession();
+
+ if (declaredMethodSession != null)
+ {
+ var content = CreateDeclaredMethodSessionPopupContent(declaredMethodSession);
+ if (content.Methods.Count > 0)
+ {
+ ShowPopup(content);
+ return;
}
}
}
@@ -1019,14 +1121,28 @@ namespace Tango.Scripting.Editors
}
else if (symbol.Kind == SymbolKind.Method)
{
- data.Add(new MethodCompletionItem()
+ var methodCompletion = new MethodCompletionItem()
{
Class = symbol.Class,
Description = symbol.Summary,
Name = symbol.Name,
ReturnType = symbol.Type,
Priority = 2,
- });
+ };
+
+ for (int i = 0; i < symbol.Parameters.Count; i++)
+ {
+ var pair = symbol.Parameters[i];
+
+ methodCompletion.Parameters.Add(new KnownTypeMethodParameter()
+ {
+ Type = pair.Key,
+ Name = pair.Value,
+ IsLast = (i == symbol.Parameters.Count - 1)
+ });
+ }
+
+ data.Add(methodCompletion);
}
}
@@ -1294,6 +1410,8 @@ namespace Tango.Scripting.Editors
MethodDescription method = new MethodDescription();
method.ReturnType = session.Type.Name;
method.Description = m.Summary;
+ method.Name = m.Name;
+ method.Class = session.Type.FriendlyName;
//if (session.Type.Type.IsGenericType && session.TypeArguments != null)
//{
@@ -1336,6 +1454,53 @@ namespace Tango.Scripting.Editors
return popup;
}
+ private MethodPopup CreateDeclaredMethodSessionPopupContent(DeclaredMethodSession session)
+ {
+ MethodPopup popup = new MethodPopup();
+
+ MethodDescription method = new MethodDescription();
+ method.ReturnType = session.Method.Type;
+ method.Description = session.Method.Summary;
+ method.Name = session.Method.Name;
+ method.Class = session.Method.Class;
+
+ //if (session.Type.Type.IsGenericType && session.TypeArguments != null)
+ //{
+ // method.ReturnType = new String(session.Type.Name.TakeWhile(x => x != '`').ToArray()) + $"<{String.Join(",", session.TypeArguments)}>";
+ //}
+
+ foreach (var p in session.Method.Parameters)
+ {
+ ParameterDescription pDescription = new ParameterDescription(method);
+ pDescription.Type = p.Key;
+ pDescription.Name = p.Value;
+ method.Parameters.Add(pDescription);
+ }
+
+ popup.Methods.Add(method);
+
+ //if (false)
+ //{
+ // popup.CurrentMethod = popup.Methods.FirstOrDefault(x => x.Parameters.Count == session.ParameterIndex + 1);
+
+ // if (popup.CurrentMethod == null)
+ // {
+ // popup.CurrentMethod = popup.Methods.FirstOrDefault();
+ // }
+ //}
+ //else
+ //{
+ popup.CurrentMethod = popup.Methods.FirstOrDefault();
+ //}
+
+ if (popup.CurrentMethod != null)
+ {
+ popup.CurrentMethodIndex = popup.Methods.IndexOf(popup.CurrentMethod) + 1;
+ }
+
+ return popup;
+ }
+
#endregion
}
}
diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Themes/Generic.xaml b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Themes/Generic.xaml
index 1ab9dd2db..ce5cb39e1 100644
--- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Themes/Generic.xaml
+++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Themes/Generic.xaml
@@ -311,6 +311,9 @@
<StackPanel Margin="10 0 0 0">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=CurrentMethod.ReturnType}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock>
+ <TextBlock Margin="5 0 0 0" Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=CurrentMethod.Class}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock>
+ <TextBlock>.</TextBlock>
+ <TextBlock Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=CurrentMethod.Name}" Foreground="{StaticResource ScriptReferenceTypesBrush}"></TextBlock>
<TextBlock>(</TextBlock>
<ItemsControl ItemsSource="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=CurrentMethod.Parameters}">
<ItemsControl.ItemsPanel>
@@ -337,6 +340,16 @@
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type popups:ParameterDescription}">
<StackPanel Orientation="Horizontal">
+ <StackPanel.Style>
+ <Style TargetType="StackPanel">
+ <Setter Property="Visibility" Value="Visible"></Setter>
+ <Style.Triggers>
+ <DataTrigger Binding="{Binding Description}" Value="{x:Null}">
+ <Setter Property="Visibility" Value="Collapsed"></Setter>
+ </DataTrigger>
+ </Style.Triggers>
+ </Style>
+ </StackPanel.Style>
<TextBlock Text="{Binding Name}"></TextBlock>
<TextBlock>:</TextBlock>
<TextBlock Opacity="0.7" Margin="5 0 0 0" Text="{Binding Description}"></TextBlock>