diff options
Diffstat (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs')
| -rw-r--r-- | Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs | 729 |
1 files changed, 368 insertions, 361 deletions
diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs index efa1b087a..d06862cef 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs @@ -279,18 +279,18 @@ namespace Tango.Scripting.Editors } else if (e.Key == Key.Oem2) { - int offset = CaretOffset; - var line = Document.GetLineByOffset(offset); + //int offset = CaretOffset; + //var line = Document.GetLineByOffset(offset); - String text = GetCurrentLineText(); - if (text.TrimStart('\t', ' ').StartsWith("//")) - { - Document.BeginUpdate(); - Document.Replace(line, "/// <summary>\n/// \n/// </summary>"); - Document.EndUpdate(); - e.Handled = true; - CaretOffset = Document.GetLineByNumber(line.LineNumber + 1).EndOffset; - } + //String text = GetCurrentLineText(); + //if (text.TrimStart('\t', ' ').StartsWith("//")) + //{ + // Document.BeginUpdate(); + // Document.Replace(line, "/// <summary>\n/// \n/// </summary>"); + // Document.EndUpdate(); + // e.Handled = true; + // CaretOffset = Document.GetLineByNumber(line.LineNumber + 1).EndOffset; + //} } else if (e.Key == Key.End || e.Key == Key.Home) { @@ -304,474 +304,481 @@ namespace Tango.Scripting.Editors private void TextArea_TextEntered(object sender, TextCompositionEventArgs e) { - List<Object> items = new List<object>(); - - HidePopup(); - - var lineText = GetCurrentLineText(); - var previousWords = GetPreviousWords(); - var previousWordsLast = previousWords.LastOrDefault(); - String currentWord = previousWordsLast != null ? previousWordsLast.Replace("\t", "") : String.Empty; - String currentWordIncludingParenthesis = currentWord.Split('(').LastOrDefault(); - - if (previousWords.Count > 0 && previousWords.First().Trim().StartsWith("//")) return; - - if (e.Text == " " && previousWords.Count > 2 && previousWords[previousWords.Count - 2] == "=") + try { - var expression = previousWords.First(); - var knownType = GetKnownTypeFromExpression(expression + "."); + List<Object> items = new List<object>(); - if (knownType != null && knownType.Type.IsEnum) - { - completionWindow.HideCompletion(); - IList<ICompletionData> data = new List<ICompletionData>(); + HidePopup(); - foreach (var field in knownType.Fields) - { - data.Add(new FieldCompletionItem() - { - Class = knownType.FriendlyName, - Name = knownType.FriendlyName + "." + field.Name, - Type = field.ReturnTypeFriendlyName, - Description = field.Summary, - }); - } + var lineText = GetCurrentLineText(); + var previousWords = GetPreviousWords(); + var previousWordsLast = previousWords.LastOrDefault(); + String currentWord = previousWordsLast != null ? previousWordsLast.Replace("\t", "") : String.Empty; + String currentWordIncludingParenthesis = currentWord.Split('(').LastOrDefault(); - ShowCompletionWindow(data.OrderBy(x => x.Text).ToList(), GetCurrentWord()); - } - - } - else if (e.Text == " " && GetPreviousWord() == "new") - { - var s = _parser.GetExpressionFirst<FieldDeclarationSyntax>(GetCurrentLineText()); - - if (s != null) - { - String type = s.Declaration.Type.ToString(); - - IList<ICompletionData> data = new List<ICompletionData>(); - - data.Add(new ClassCompletionItem() - { - Name = type, - Description = "Auto generate assignment...", - }); + if (previousWords.Count > 0 && previousWords.First().Trim().StartsWith("//")) return; - ShowCompletionWindow(data, type); - } - } - else if (e.Text == ";" || e.Text == " ") - { - HideCompletionWindow(); - } - else if (e.Text == ".") - { - var knownType = GetCurrentKnownType(); - - if (knownType != null) + if (e.Text == " " && previousWords.Count > 2 && previousWords[previousWords.Count - 2] == "=") { - completionWindow.HideCompletion(); - IList<ICompletionData> data = new List<ICompletionData>(); + var expression = previousWords.First(); + var knownType = GetKnownTypeFromExpression(expression + "."); - if (!knownType.Type.IsEnum) + if (knownType != null && knownType.Type.IsEnum) { - var typeMembers = knownType.Members.ToList(); + completionWindow.HideCompletion(); + IList<ICompletionData> data = new List<ICompletionData>(); - foreach (var methodGroup in typeMembers.OfType<KnownTypeMethod>().GroupBy(x => x.NameWithTypeArguments)) + foreach (var field in knownType.Fields) { - var method = methodGroup.First(); - - data.Add(new MethodCompletionItem() + data.Add(new FieldCompletionItem() { Class = knownType.FriendlyName, - Name = method.NameWithTypeArguments, - ReturnType = method.ReturnTypeFriendlyName, - Description = method.Summary, - Parameters = method.Parameters, - Overloads = methodGroup.Count() - 1, + Name = knownType.FriendlyName + "." + field.Name, + Type = field.ReturnTypeFriendlyName, + Description = field.Summary, }); } - foreach (var methodGroup in typeMembers.Where(x => x.GetType() != typeof(KnownTypeMethod)).GroupBy(x => x.Name)) - { - var member = methodGroup.First(); + ShowCompletionWindow(data.OrderBy(x => x.Text).ToList(), GetCurrentWord()); + } - data.Add(new PropertyCompletionItem() - { - Class = knownType.FriendlyName, - Name = member.Name, - Type = member.ReturnTypeFriendlyName, - Description = member.Summary, - }); + } + else if (e.Text == " " && GetPreviousWord() == "new") + { + var s = _parser.GetExpressionFirst<FieldDeclarationSyntax>(GetCurrentLineText()); - } - } - else + if (s != null) { - foreach (var field in knownType.Fields) + String type = s.Declaration.Type.ToString(); + + IList<ICompletionData> data = new List<ICompletionData>(); + + data.Add(new ClassCompletionItem() { - data.Add(new FieldCompletionItem() - { - Class = knownType.FriendlyName, - Name = field.Name, - Type = field.ReturnTypeFriendlyName, - Description = field.Summary, - }); + Name = type, + Description = "Auto generate assignment...", + }); - } + ShowCompletionWindow(data, type); } - - ShowCompletionWindow(data.OrderBy(x => x.Text).ToList(), GetCurrentWord()); } - else + else if (e.Text == ";" || e.Text == " ") + { + HideCompletionWindow(); + } + else if (e.Text == ".") { - var declaredType = GetCurrentDeclaredType(); + var knownType = GetCurrentKnownType(); - if (declaredType != null) + if (knownType != null) { completionWindow.HideCompletion(); IList<ICompletionData> data = new List<ICompletionData>(); - var typeMembers = declaredType.Symbols.ToList(); - - foreach (var methodGroup in typeMembers.GroupBy(x => x.Name)) + if (!knownType.Type.IsEnum) { - var member = methodGroup.First(); + var typeMembers = knownType.Members.ToList(); - if (member.Kind == SymbolKind.Method) + foreach (var methodGroup in typeMembers.OfType<KnownTypeMethod>().GroupBy(x => x.NameWithTypeArguments)) { - var methodCompletion = new MethodCompletionItem() - { - Class = declaredType.Name, - Name = member.Name, - ReturnType = member.Type, - Description = member.Summary, - Overloads = methodGroup.Count() - 1, - }; + var method = methodGroup.First(); - - for (int i = 0; i < member.Parameters.Count; i++) + data.Add(new MethodCompletionItem() { - 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); - + Class = knownType.FriendlyName, + Name = method.NameWithTypeArguments, + ReturnType = method.ReturnTypeFriendlyName, + Description = method.Summary, + Parameters = method.Parameters, + Overloads = methodGroup.Count() - 1, + }); } - else if (member.Kind == SymbolKind.Property) + + foreach (var methodGroup in typeMembers.Where(x => x.GetType() != typeof(KnownTypeMethod)).GroupBy(x => x.Name)) { + var member = methodGroup.First(); + data.Add(new PropertyCompletionItem() { - Class = declaredType.Name, + Class = knownType.FriendlyName, Name = member.Name, - Type = member.Type, + Type = member.ReturnTypeFriendlyName, Description = member.Summary, }); + } - else if (member.Kind == SymbolKind.Field) + } + else + { + foreach (var field in knownType.Fields) { data.Add(new FieldCompletionItem() { - Class = declaredType.Name, - Name = member.Name, - Type = member.Type, - Description = member.Summary, + Class = knownType.FriendlyName, + Name = field.Name, + Type = field.ReturnTypeFriendlyName, + Description = field.Summary, }); + } } - ShowCompletionWindow(data, GetCurrentWord()); + ShowCompletionWindow(data.OrderBy(x => x.Text).ToList(), GetCurrentWord()); } - } - } - else if (e.Text == "(" || e.Text == ",") - { - completionWindow.HideCompletion(); + else + { + var declaredType = GetCurrentDeclaredType(); - try + if (declaredType != null) + { + completionWindow.HideCompletion(); + IList<ICompletionData> data = new List<ICompletionData>(); + + var typeMembers = declaredType.Symbols.ToList(); + + foreach (var methodGroup in typeMembers.GroupBy(x => x.Name)) + { + var member = methodGroup.First(); + + if (member.Kind == SymbolKind.Method) + { + var methodCompletion = new MethodCompletionItem() + { + Class = declaredType.Name, + Name = member.Name, + ReturnType = member.Type, + Description = member.Summary, + 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) + { + data.Add(new PropertyCompletionItem() + { + Class = declaredType.Name, + Name = member.Name, + Type = member.Type, + Description = member.Summary, + }); + } + else if (member.Kind == SymbolKind.Field) + { + data.Add(new FieldCompletionItem() + { + Class = declaredType.Name, + Name = member.Name, + Type = member.Type, + Description = member.Summary, + }); + } + } + + ShowCompletionWindow(data, GetCurrentWord()); + } + } + } + else if (e.Text == "(" || e.Text == ",") { - var session = GetConstructionSession(); + completionWindow.HideCompletion(); - if (session != null) + try { - var content = CreateConstructionSessionPopupContent(session); - if (content.Methods.Count > 0) + var session = GetConstructionSession(); + + if (session != null) { - ShowPopup(content); - return; + var content = CreateConstructionSessionPopupContent(session); + if (content.Methods.Count > 0) + { + ShowPopup(content); + return; + } } - } - var methodSession = GetMethodSession(); + var methodSession = GetMethodSession(); - if (methodSession != null) - { - var content = CreateMethodSessionPopupContent(methodSession); - if (content.Methods.Count > 0) + if (methodSession != null) { - ShowPopup(content); - return; + var content = CreateMethodSessionPopupContent(methodSession); + if (content.Methods.Count > 0) + { + ShowPopup(content); + return; + } } - } - var declaredMethodSession = GetDeclaredMethodSession(); + var declaredMethodSession = GetDeclaredMethodSession(); - if (declaredMethodSession != null) - { - var content = CreateDeclaredMethodSessionPopupContent(declaredMethodSession); - if (content.Methods.Count > 0) + if (declaredMethodSession != null) { - ShowPopup(content); - return; + var content = CreateDeclaredMethodSessionPopupContent(declaredMethodSession); + if (content.Methods.Count > 0) + { + ShowPopup(content); + return; + } } } + catch (Exception ex) + { + Debug.WriteLine(ex); + } } - catch (Exception ex) - { - Debug.WriteLine(ex); - } - } - else if (lineText.StartsWith("using")) - { - if (completionWindow.IsVisible) + else if (lineText.StartsWith("using") && e.Text != "\n") { - completionWindow.UpdatePositionFix(); - return; - } + if (completionWindow.IsVisible) + { + completionWindow.UpdatePositionFix(); + return; + } - IList<ICompletionData> data = new List<ICompletionData>(); + IList<ICompletionData> data = new List<ICompletionData>(); - foreach (var asm in ReferenceAssemblies) - { - foreach (var ns in asm.Assembly.GetTypes().Select(x => x.Namespace).Distinct().Where(x => x != null)) + foreach (var asm in ReferenceAssemblies) { - data.Add(new NamespaceCompletionItem() + foreach (var ns in asm.Assembly.GetTypes().Select(x => x.Namespace).Distinct().Where(x => x != null)) { - Name = ns, - Assembly = asm.Assembly.GetName().Name, - }); + data.Add(new NamespaceCompletionItem() + { + Name = ns, + Assembly = asm.Assembly.GetName().Name, + }); + } } - } - data = data.DistinctBy(x => x.Text).ToList(); + data = data.DistinctBy(x => x.Text).ToList(); - ShowCompletionWindow(data, GetCurrentWord()); - } - else if (e.Text == "{") - { - int parentesisCount = lineText.TakeWhile(x => x != '{').Count(x => x == '\"'); - - if (parentesisCount % 2 == 0) - { - Document.Insert(CaretOffset, "}"); - CaretOffset--; + ShowCompletionWindow(data, GetCurrentWord()); } - } - else if (e.Text == "}") - { - if (Document.GetText(CaretOffset - 2, 1) == "{" && Document.GetText(CaretOffset, 1) == "}") - { - Document.Replace(CaretOffset, 1, ""); - } - } - else if (e.Text == "\n") - { - if (Document.GetText(CaretOffset - 3, 1) == "{" && Document.GetText(CaretOffset, 1) == "}") + else if (e.Text == "{") { - CaretOffset--; - Document.Insert(CaretOffset, "\n\t"); + int parentesisCount = lineText.TakeWhile(x => x != '{').Count(x => x == '\"'); + + if (parentesisCount % 2 == 0) + { + Document.Insert(CaretOffset, "}"); + CaretOffset--; + } } - } - else if (!currentWordIncludingParenthesis.Contains(".") || currentWord[currentWord.Length - 2] == '<') - { - if (completionWindow.IsVisible) + else if (e.Text == "}") { - completionWindow.UpdatePositionFix(); - return; + if (Document.GetText(CaretOffset - 2, 1) == "{" && Document.GetText(CaretOffset, 1) == "}") + { + Document.Replace(CaretOffset, 1, ""); + } } - - var previous_word = GetPreviousWord(); - var word = GetCurrentWord(); - - if (word.Contains("<")) + else if (e.Text == "\n") { - word = word.Last(x => x != '<').ToString(); + if (Document.GetText(CaretOffset - 3, 1) == "{" && Document.GetText(CaretOffset, 1) == "}") + { + CaretOffset--; + Document.Insert(CaretOffset, "\n\t"); + } } - - if (previous_word != word) + else if (!currentWordIncludingParenthesis.Contains(".") || currentWord[currentWord.Length - 2] == '<') { - if (_knownTypes.Exists(x => x.Name == previous_word)) + if (completionWindow.IsVisible) { + completionWindow.UpdatePositionFix(); return; } - if (_blocking_type_words.Contains(previous_word)) + var previous_word = GetPreviousWord(); + var word = GetCurrentWord(); + + if (word.Contains("<")) { - return; + word = word.Last(x => x != '<').ToString(); } - } - - if (!String.IsNullOrWhiteSpace(word)) - { - IList<ICompletionData> data = new List<ICompletionData>(); - foreach (var type in _declaredTypes.Where(x => x.Name.StartsWith(word))) + if (previous_word != word) { - if (type.Kind == TypeKind.Struct) + if (_knownTypes.Exists(x => x.Name == previous_word)) { - data.Add(new StructCompletionItem() - { - Name = type.Name, - Description = type.Summary, - Namespace = type.ContainingNamespace, - Priority = 1, - }); - } - else if (type.Kind == TypeKind.Enum) - { - data.Add(new EnumCompletionItem() - { - Name = type.Name, - Description = type.Summary, - Namespace = type.ContainingNamespace, - Priority = 1, - }); - } - else if (type.Kind == TypeKind.Interface) - { - data.Add(new InterfaceCompletionItem() - { - Name = type.Name, - Description = type.Summary, - Namespace = type.ContainingNamespace, - Priority = 1, - }); - } - else if (type.Kind == TypeKind.Class) - { - data.Add(new ClassCompletionItem() - { - Name = type.Name, - Description = type.Summary, - Namespace = type.ContainingNamespace, - Priority = 1, - }); + return; } - else + + if (_blocking_type_words.Contains(previous_word)) { - throw new NotImplementedException("Implement generic item here!"); + return; } } - foreach (var type in _knownTypes.ToList().Where(x => x.Name.StartsWith(word))) + if (!String.IsNullOrWhiteSpace(word)) { - if (type.Type.IsEnum) + IList<ICompletionData> data = new List<ICompletionData>(); + + foreach (var type in _declaredTypes.Where(x => x.Name.StartsWith(word))) { - data.Add(new EnumCompletionItem() + if (type.Kind == TypeKind.Struct) { - Namespace = type.Type.Namespace, - Description = type.Summary, - Name = type.FriendlyName, - Priority = 0, - }); - } - else if (type.Type.IsInterface) - { - data.Add(new InterfaceCompletionItem() + data.Add(new StructCompletionItem() + { + Name = type.Name, + Description = type.Summary, + Namespace = type.ContainingNamespace, + Priority = 1, + }); + } + else if (type.Kind == TypeKind.Enum) { - Name = type.FriendlyName, - Description = type.Summary, - Namespace = type.Type.Namespace, - Priority = 0, - }); - } - else if (type.Type.IsValueType) - { - data.Add(new StructCompletionItem() + data.Add(new EnumCompletionItem() + { + Name = type.Name, + Description = type.Summary, + Namespace = type.ContainingNamespace, + Priority = 1, + }); + } + else if (type.Kind == TypeKind.Interface) { - Name = type.FriendlyName, - Description = type.Summary, - Namespace = type.Type.Namespace, - Priority = 0, - }); - } - else if (type.Type.IsClass) - { - data.Add(new ClassCompletionItem() + data.Add(new InterfaceCompletionItem() + { + Name = type.Name, + Description = type.Summary, + Namespace = type.ContainingNamespace, + Priority = 1, + }); + } + else if (type.Kind == TypeKind.Class) { - Name = type.FriendlyName, - Description = type.Summary, - Namespace = type.Type.Namespace, - Priority = 0, - }); - } - else - { - throw new NotImplementedException("Implement generic item here."); + data.Add(new ClassCompletionItem() + { + Name = type.Name, + Description = type.Summary, + Namespace = type.ContainingNamespace, + Priority = 1, + }); + } + else + { + throw new NotImplementedException("Implement generic item here!"); + } } - } - foreach (var symbol in _parser.GetContextSymbols(Document.Text, CaretOffset).Where(x => x.Name.StartsWith(GetCurrentWord()))) - { - if (symbol.Kind == SymbolKind.Property) + foreach (var type in _knownTypes.ToList().Where(x => x.Name.StartsWith(word))) { - data.Add(new PropertyCompletionItem() + if (type.Type.IsEnum) { - Class = symbol.Class, - Description = symbol.Summary, - Name = symbol.Name, - Type = symbol.Type, - Priority = 2, - }); - } - else if (symbol.Kind == SymbolKind.Field || symbol.Kind == SymbolKind.Local || symbol.Kind == SymbolKind.Parameter) - { - data.Add(new FieldCompletionItem() + data.Add(new EnumCompletionItem() + { + Namespace = type.Type.Namespace, + Description = type.Summary, + Name = type.FriendlyName, + Priority = 0, + }); + } + else if (type.Type.IsInterface) { - Class = symbol.Class, - Description = symbol.Summary, - Name = symbol.Name, - Type = symbol.Type, - Priority = 2, - }); + data.Add(new InterfaceCompletionItem() + { + Name = type.FriendlyName, + Description = type.Summary, + Namespace = type.Type.Namespace, + Priority = 0, + }); + } + else if (type.Type.IsValueType) + { + data.Add(new StructCompletionItem() + { + Name = type.FriendlyName, + Description = type.Summary, + Namespace = type.Type.Namespace, + Priority = 0, + }); + } + else if (type.Type.IsClass) + { + data.Add(new ClassCompletionItem() + { + Name = type.FriendlyName, + Description = type.Summary, + Namespace = type.Type.Namespace, + Priority = 0, + }); + } + else + { + throw new NotImplementedException("Implement generic item here."); + } } - else if (symbol.Kind == SymbolKind.Method) + + foreach (var symbol in _parser.GetContextSymbols(Document.Text, CaretOffset).Where(x => x.Name.StartsWith(GetCurrentWord()))) { - var methodCompletion = new MethodCompletionItem() + if (symbol.Kind == SymbolKind.Property) { - Class = symbol.Class, - Description = symbol.Summary, - Name = symbol.Name, - ReturnType = symbol.Type, - Priority = 2, - }; - - for (int i = 0; i < symbol.Parameters.Count; i++) + data.Add(new PropertyCompletionItem() + { + Class = symbol.Class, + Description = symbol.Summary, + Name = symbol.Name, + Type = symbol.Type, + Priority = 2, + }); + } + else if (symbol.Kind == SymbolKind.Field || symbol.Kind == SymbolKind.Local || symbol.Kind == SymbolKind.Parameter) { - var pair = symbol.Parameters[i]; - - methodCompletion.Parameters.Add(new KnownTypeMethodParameter() + data.Add(new FieldCompletionItem() { - Type = pair.Key, - Name = pair.Value, - IsLast = (i == symbol.Parameters.Count - 1) + Class = symbol.Class, + Description = symbol.Summary, + Name = symbol.Name, + Type = symbol.Type, + Priority = 2, }); } + else if (symbol.Kind == SymbolKind.Method) + { + 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); + data.Add(methodCompletion); + } } - } - ShowCompletionWindow(data, word); + ShowCompletionWindow(data, word); + } } } + catch (Exception ex) + { + Debug.WriteLine(ex.ToString()); + } } #endregion |
