diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2020-08-05 00:28:48 +0300 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2020-08-05 00:28:48 +0300 |
| commit | cd8ef321bd713d967fa0f436bd6720566a71c66a (patch) | |
| tree | 7684de6993ae237d49e3ddf148148a3cc47c9b62 /Software/Visual_Studio/Scripting/Tango.Scripting.Editors | |
| parent | 054b6ca55142fae5bb30a9b8f3301f7e71a92296 (diff) | |
| parent | b9700510ad42a7b869596924edb03ad38c47675c (diff) | |
| download | Tango-cd8ef321bd713d967fa0f436bd6720566a71c66a.tar.gz Tango-cd8ef321bd713d967fa0f436bd6720566a71c66a.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Editors')
| -rw-r--r-- | Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ExtensionMethods.cs | 2 | ||||
| -rw-r--r-- | Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs | 151 |
2 files changed, 99 insertions, 54 deletions
diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ExtensionMethods.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ExtensionMethods.cs index 1605ff281..d112c6141 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ExtensionMethods.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ExtensionMethods.cs @@ -22,7 +22,7 @@ namespace Tango.Scripting.Editors { List<String> args = new List<string>(); - foreach (var lGenericArgument in type.GetGenericTypeDefinition().GetGenericArguments()) + foreach (var lGenericArgument in type.GetGenericArguments()) { args.Add(lGenericArgument.Name); } diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs index 8cf615a7c..0802cf456 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs @@ -65,6 +65,7 @@ namespace Tango.Scripting.Editors private static List<CachedUsing> _cachedUsings; private static bool _isLoadingCachedAssemblies; private static bool _isCacheAssembliesLoaded; + private static bool _isUsingsLoadingStarted; private static object _loadUsingsLock = new object(); private static List<SnippetCompletionItem> snippets; @@ -72,9 +73,27 @@ namespace Tango.Scripting.Editors public static event EventHandler LoadingSymbolsStarted; public static event EventHandler LoadingSymbolsCompleted; private static event EventHandler KnownTypesAvailable; + public static event EventHandler UsingsLoadingStarted; + public static event EventHandler UsingsLoadingCompleted; #region Mini Classes + private class KnownTypeResult + { + public KnownType KnownType { get; set; } + public bool IsStatic { get; set; } + + public KnownTypeResult() + { + + } + + public KnownTypeResult(KnownType knownType) + { + KnownType = knownType; + } + } + private class ScriptClass { public String Name { get; set; } @@ -257,6 +276,12 @@ namespace Tango.Scripting.Editors }" }); + + snippets.Add(new SnippetCompletionItem() + { + Name = "cw", + Code = "context.WriteLine(\"\");" + }); } /// <summary> @@ -302,6 +327,13 @@ namespace Tango.Scripting.Editors errorMarkerService = new TextMarkerService(Document); TextArea.TextView.BackgroundRenderers.Add(errorMarkerService); TextArea.TextView.LineTransformers.Add(errorMarkerService); + + Unloaded += ScriptEditor_Unloaded; + } + + private void ScriptEditor_Unloaded(object sender, RoutedEventArgs e) + { + _update_timer.Stop(); } private void ScriptEditor_KnownTypesAvailable(object sender, EventArgs e) @@ -477,19 +509,19 @@ namespace Tango.Scripting.Editors if (e.Text == " " && previousWords.Count > 2 && previousWords[previousWords.Count - 2] == "=") { var expression = previousWords.First(); - var knownType = GetKnownTypeFromExpression(expression + "."); + var knownTypeResult = GetKnownTypeFromExpression(expression + "."); - if (knownType != null && knownType.Type.IsEnum) + if (knownTypeResult != null && knownTypeResult.KnownType.Type.IsEnum) { completionWindow.HideCompletion(); IList<ICompletionData> data = new List<ICompletionData>(); - foreach (var field in knownType.Fields) + foreach (var field in knownTypeResult.KnownType.Fields) { data.Add(new FieldCompletionItem() { - Class = knownType.FriendlyName, - Name = knownType.FriendlyName + "." + field.Name, + Class = knownTypeResult.KnownType.FriendlyName, + Name = knownTypeResult.KnownType.FriendlyName + "." + field.Name, Type = field.ReturnTypeFriendlyName, Description = field.Summary, }); @@ -524,25 +556,25 @@ namespace Tango.Scripting.Editors } else if (e.Text == ".") { - var knownType = GetCurrentKnownType(); + var knownTypeResult = GetCurrentKnownType(); IList<ICompletionData> data = new List<ICompletionData>(); - if (knownType != null) + if (knownTypeResult != null) { completionWindow.HideCompletion(); - if (!knownType.Type.IsEnum) + if (!knownTypeResult.KnownType.Type.IsEnum) { - var typeMembers = knownType.Members.ToList(); + var typeMembers = knownTypeResult.KnownType.Members.ToList(); - foreach (var methodGroup in typeMembers.OfType<KnownTypeMethod>().Where(x => !x.IsStatic).GroupBy(x => x.NameWithTypeArguments)) + foreach (var methodGroup in typeMembers.OfType<KnownTypeMethod>().Where(x => (!knownTypeResult.IsStatic && !x.IsStatic) || (knownTypeResult.IsStatic && x.IsStatic)).GroupBy(x => x.NameWithTypeArguments)) { var method = methodGroup.First(); data.Add(new MethodCompletionItem() { - Class = knownType.FriendlyName, + Class = knownTypeResult.KnownType.FriendlyName, Name = method.NameWithTypeArguments, ReturnType = method.ReturnTypeFriendlyName, Description = method.Summary, @@ -555,7 +587,7 @@ namespace Tango.Scripting.Editors { data.Add(new EventCompletionItem() { - Class = knownType.FriendlyName, + Class = knownTypeResult.KnownType.FriendlyName, Name = ev.Name, Description = ev.Summary, }); @@ -567,7 +599,7 @@ namespace Tango.Scripting.Editors data.Add(new PropertyCompletionItem() { - Class = knownType.FriendlyName, + Class = knownTypeResult.KnownType.FriendlyName, Name = member.Name, Type = member.ReturnTypeFriendlyName, Description = member.Summary, @@ -576,11 +608,11 @@ namespace Tango.Scripting.Editors } else { - foreach (var field in knownType.Fields) + foreach (var field in knownTypeResult.KnownType.Fields) { data.Add(new FieldCompletionItem() { - Class = knownType.FriendlyName, + Class = knownTypeResult.KnownType.FriendlyName, Name = field.Name, Type = field.ReturnTypeFriendlyName, Description = field.Summary, @@ -656,34 +688,6 @@ namespace Tango.Scripting.Editors ShowCompletionWindow(data, GetCurrentWord()); } - else - { - //Maybe static ... - var typeText = GetPreviousWord(); - knownType = _knownTypes.FirstOrDefault(x => x.FriendlyName == typeText || x.Alias == typeText); - - if (knownType != null) - { - var typeMembers = knownType.Members.ToList(); - - foreach (var methodGroup in typeMembers.OfType<KnownTypeMethod>().Where(x => x.IsStatic).GroupBy(x => x.NameWithTypeArguments)) - { - var method = methodGroup.First(); - - data.Add(new MethodCompletionItem() - { - Class = knownType.FriendlyName, - Name = method.NameWithTypeArguments, - ReturnType = method.ReturnTypeFriendlyName, - Description = method.Summary, - Parameters = method.Parameters, - Overloads = methodGroup.Count() - 1, - }); - } - - ShowCompletionWindow(data.OrderBy(x => x.Text).ToList(), GetCurrentWord()); - } - } } } else if (e.Text == "(" || e.Text == ",") @@ -1081,13 +1085,13 @@ namespace Tango.Scripting.Editors return list; } - private KnownType GetCurrentKnownType() + private KnownTypeResult GetCurrentKnownType() { var expression = GetPreviousWords().LastOrDefault(); return GetKnownTypeFromExpression(expression); } - private KnownType GetKnownTypeFromExpression(String expression) + private KnownTypeResult GetKnownTypeFromExpression(String expression) { if (expression != null) { @@ -1108,7 +1112,7 @@ namespace Tango.Scripting.Editors if (enumType != null) { - return enumType; + return new KnownTypeResult(enumType); } tree.RemoveAt(0); @@ -1136,13 +1140,36 @@ namespace Tango.Scripting.Editors knownType = _knownTypes.FirstOrDefault(x => x.Type.Namespace + "." + x.Type.Name == member.ReturnType.Namespace + "." + member.ReturnType.Name); } - return knownType; + return new KnownTypeResult(knownType); + } + else //Maybe a variable of a declared type... + { + if (tree.Count > 0) + { + var memberName = tree[0]; + var declaredType = _declaredTypes.SingleOrDefault(x => x.Name == name); + + if (declaredType != null) + { + var member = declaredType.Symbols.FirstOrDefault(x => x.Name == memberName); + if (member != null) + { + knownType = _knownTypes.SingleOrDefault(x => x.Name.ToLower() == member.Type.ToLower()); + + if (knownType != null) + { + return new KnownTypeResult(knownType); + } + } + } + } } } else { //Maybe static... - return _knownTypes.FirstOrDefault(x => x.Name == variableName); + var type = _knownTypes.FirstOrDefault(x => x.Name == variableName); + return type != null ? new KnownTypeResult(type) { IsStatic = true } : null; } } } @@ -1289,7 +1316,7 @@ namespace Tango.Scripting.Editors foreach (var m in session.Type.Methods.Where(x => x.Name == session.MethodName)) { MethodDescription method = new MethodDescription(); - method.ReturnType = session.Type.Name; + method.ReturnType = m.ReturnTypeFriendlyName; method.Description = m.Summary; method.Name = m.NameWithTypeArguments; method.Class = session.Type.FriendlyName; @@ -1394,6 +1421,12 @@ namespace Tango.Scripting.Editors { if (!_cachedUsings.Exists(x => x.Namespace == use)) { + if (!_isUsingsLoadingStarted) + { + _isUsingsLoadingStarted = true; + UsingsLoadingStarted?.Invoke(this, new EventArgs()); + } + var useFileName = System.IO.Path.Combine(KNOWN_TYPES_CACHE_FOLDER, use + ".json"); if (File.Exists(useFileName)) @@ -1477,7 +1510,7 @@ namespace Tango.Scripting.Editors knownType.LoadDocumentation(); } - if (!BlockedUsingsCache.Exists(x => x == use)) + if (!BlockedUsingsCache.Exists(x => use.StartsWith(x))) { Task.Factory.StartNew(() => { @@ -1488,6 +1521,11 @@ namespace Tango.Scripting.Editors } } + if (_isUsingsLoadingStarted) + { + UsingsLoadingCompleted?.Invoke(this, new EventArgs()); + } + LoadingSymbolsCompleted?.Invoke(null, new EventArgs()); } } @@ -2431,9 +2469,16 @@ namespace Tango.Scripting.Editors public void HighlighError(int position, int length) { - ITextMarker marker = errorMarkerService.Create(position, length); - marker.MarkerTypes = TextMarkerTypes.SquigglyUnderline; - marker.MarkerColor = Colors.Red; + try + { + ITextMarker marker = errorMarkerService.Create(position, length); + marker.MarkerTypes = TextMarkerTypes.SquigglyUnderline; + marker.MarkerColor = Colors.Red; + } + catch (Exception ex) + { + Debug.WriteLine($"Error highlighting script error.\n{ex.ToString()}"); + } } public void ClearErrors() |
