diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-03-16 11:53:31 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-03-16 11:53:31 +0200 |
| commit | c1c1e12fd3f0d89752b42d890ac43678bf9e7d69 (patch) | |
| tree | 6a8ba06ea9c44cefe0871b356d65fc191a97eb06 /Software/Visual_Studio/TEMP/Tango.Scripting | |
| parent | ec4b039d1d72742943f67725dd3f2622d576c28b (diff) | |
| download | Tango-c1c1e12fd3f0d89752b42d890ac43678bf9e7d69.tar.gz Tango-c1c1e12fd3f0d89752b42d890ac43678bf9e7d69.zip | |
More work on script editor.
Diffstat (limited to 'Software/Visual_Studio/TEMP/Tango.Scripting')
3 files changed, 501 insertions, 485 deletions
diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/Utils.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/Utils.cs index e30d0e37e..f8cc7072d 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/Utils.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting.Editors/Intellisense/Utils.cs @@ -116,7 +116,7 @@ namespace Tango.Scripting.Editors.Intellisense XmlNode mDoc = null; mDoc = docNodes.FirstOrDefault(x => x.Attributes["name"].InnerText.Contains(knownType.Type.Name + "." + method.Name)); - method.Summary = mDoc != null ? mDoc.SelectSingleNode("summary").InnerXml : "No documentation"; + method.Summary = mDoc != null ? mDoc.SelectSingleNode("summary").InnerXml.Remove("(<see cref=\".:)|(\" \\/>)") : "No documentation"; var parameters = method.Parameters.ToList(); var parametersNodes = mDoc != null ? mDoc.SelectNodes("param").OfType<XmlNode>().ToList() : new List<XmlNode>(); @@ -134,7 +134,7 @@ namespace Tango.Scripting.Editors.Intellisense pNode = parametersNodes[j]; } - parameter.Description = pNode != null ? pNode.InnerText : null; + parameter.Description = pNode != null ? pNode.InnerText.Remove("(<see cref=\".:)|(\" \\/>)") : null; } } } 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 71b836f36..efa1b087a 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 @@ -72,6 +72,7 @@ namespace Tango.Scripting.Editors { public KnownType Type { get; set; } public String MethodName { get; set; } + public int ParameterIndex { get; set; } } private class DeclaredMethodSession @@ -210,467 +211,6 @@ namespace Tango.Scripting.Editors #endregion - #region Public Methods - - /// <summary> - /// Invalidates all using statements in the script. - /// </summary> - public void InvalidateUsings() - { - var oldUsings = _current_usings.ToList(); - _current_usings = _parser.GetUsings(Text); - - if (_current_usings.Exists(x => !oldUsings.Exists(y => y == x)) || oldUsings.Exists(x => !_current_usings.Exists(y => y == x))) - { - InvalidateHighlighting(); - } - } - - /// <summary> - /// Invalidates the script folding if enabled. - /// </summary> - public void InvalidateFolding() - { - if (EnableFolding) - { - if (foldingManager == null) - { - foldingManager = FoldingManager.Install(TextArea); - } - - foldingStrategy.UpdateFoldings(foldingManager, Document); - } - } - - /// <summary> - /// Indents the code. - /// </summary> - public void IndentCode() - { - Text = Indentation.CSharp.CSharpIndentationHelper.IndentCSharpCode(Text); - //Text = _parser.IndentCSharpCode(Text); - } - - /// <summary> - /// Gets the current line. - /// </summary> - /// <returns></returns> - public DocumentLine GetCurrentLine() - { - int offset = CaretOffset; - var line = Document.GetLineByOffset(offset); - return line; - } - - /// <summary> - /// Gets the current line text. - /// </summary> - /// <returns></returns> - public String GetCurrentLineText() - { - var text = Document.GetText(GetCurrentLine()); - return text; - } - - /// <summary> - /// Gets the current word. - /// </summary> - /// <returns></returns> - public String GetCurrentWord() - { - return GetWordByEndIndex(CaretOffset); - } - - public String GetWordByEndIndex(int index) - { - String word = String.Empty; - var line = GetCurrentLine(); - - int position = index; - - for (int i = position - 1; i >= line.Offset; i--) - { - char c = Document.GetText(i, 1).First(); - - if (word_separators.Contains(c)) - { - break; - } - - word += c; - } - - word = new string(word.Reverse().ToArray()); - - if (word.Length > 0) - { - word = word.Replace(".", ""); - } - - return word; - } - - public int GetCurrentWordStartIndex() - { - var line = GetCurrentLine(); - - int position = CaretOffset; - - for (int i = position - 1; i >= line.Offset; i--) - { - char c = Document.GetText(i, 1).First(); - - if (word_separators.Contains(c)) - { - return i + 1; - } - } - - return line.Offset; - } - - public String GetPreviousWord() - { - int index = GetCurrentWordStartIndex() - 1; - return GetWordByEndIndex(index); - } - - private ConstructionSession GetConstructionSession() - { - var expression = _parser.GetCurrentConstructionExpression(GetCurrentLineText()); - - if (expression != null) - { - ConstructionSession session = new ConstructionSession(); - - var line = GetCurrentLine(); - int parameterIndex = 0; - for (int i = CaretOffset; i > line.Offset; i--) - { - String c = Document.GetText(i, 1); - - if (c == "(") - { - var typeDeclaration = expression.Type as GenericNameSyntax; - - KnownType type = null; - - if (typeDeclaration != null) - { - var typeName = typeDeclaration.Identifier.ToString(); - var argumentsCount = typeDeclaration.TypeArgumentList.Arguments.Count; - session.TypeArguments = typeDeclaration.TypeArgumentList.Arguments.Select(x => x.ToString()).ToList(); - - if (argumentsCount == 0) - { - type = _knownTypes.FirstOrDefault(x => x.Type.Name == expression.Type.ToString()); - } - else - { - type = _knownTypes.FirstOrDefault(x => x.Type.Name == typeName + "`" + argumentsCount); - } - } - else - { - type = _knownTypes.FirstOrDefault(x => x.Name == expression.Type.ToString()); - } - - if (type != null) - { - session.Type = type; - session.ParameterIndex = parameterIndex; - return session; - } - else - { - return null; - } - } - else if (c == ",") - { - parameterIndex++; - } - - } - } - - return null; - } - - private MethodSession GetMethodSession() - { - var expression = GetPreviousWords().LastOrDefault(); - - if (expression != null) - { - var tree = expression.Split('.').Select(x => x.Remove(@"\n|\r|\s|\t|\(|\)|\[|\]|<.*>")).ToList(); - var variableName = tree.FirstOrDefault(); - - if (variableName != null && tree.Count > 1) - { - tree.RemoveAt(0); - var variables = _parser.GetContextSymbols(Document.Text, CaretOffset); - var variable = variables.FirstOrDefault(x => x.Name == variableName); - - if (variable != null) - { - var knownType = _knownTypes.FirstOrDefault(x => x.FriendlyName == Regex.Replace(variable.Type, "<.+>", "<T>")); - - if (knownType != null) - { - while (tree.Count > 1) - { - var memberName = tree.First(); - tree.RemoveAt(0); - var member = knownType.Members.FirstOrDefault(x => x.Name == memberName); - - if (member == null) - { - return null; - } - - knownType = _knownTypes.FirstOrDefault(x => x.Type.Namespace + "." + x.Type.Name == member.ReturnType.Namespace + "." + member.ReturnType.Name); - } - - return new MethodSession() - { - Type = knownType, - MethodName = tree.Last(), - }; - } - } - } - } - - 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(); - var currentText = Document.GetText(currentLine.Offset, CaretOffset - currentLine.Offset); - return currentText.Split(' ',',').ToList(); - } - - #endregion - - #region Highlighting - - private void InvalidateHighlighting() - { - if (!_isLoadingTypes) - { - _isLoadingTypes = true; - _knownTypes.Clear(); - - var assemblies = ReferenceAssemblies.ToList(); - var usings = _current_usings.ToList(); - - Thread t = new Thread(() => - { - foreach (var asm in assemblies.Select(x => x.Assembly)) - { - Parallel.ForEach(asm.GetTypes().Where(x => x.IsVisible && x.IsPublic && !x.IsPrimitive), (type) => - { - if (usings.Exists(x => type.Namespace == x)) - { - lock (_knownTypes) - { - if (!_knownTypes.Exists(x => x.Type.FullName == type.FullName)) - { - _knownTypes.Add(new KnownType(type)); - } - } - } - }); - } - - if (_knownTypes.Count > 0 || _declaredTypes.Count > 0) - { - String text = String.Empty; - - Stream xshd_stream = typeof(ScriptEditor).Assembly.GetManifestResourceStream("Tango.Scripting.Editors.Highlighting.Resources.CSharp-Mode.xshd"); - - using (StreamReader reader = new StreamReader(xshd_stream)) - { - text = reader.ReadToEnd(); - } - - List<String> referenceTypes = new List<string>(); - List<String> interfaceTypes = new List<string>(); - - lock (_knownTypes) - { - foreach (var type in _knownTypes.ToList().Where(x => x != null)) - { - String name = type.Name; - - if (type.Type.ContainsGenericParameters) - { - name = new String(name.TakeWhile(x => x != '`').ToArray()); - } - - if (type.Type.IsInterface || type.Type.IsEnum) - { - interfaceTypes.Add(String.Format("<Word>{0}</Word>", name)); - } - else if (type.Type.IsClass || (type.Type.IsValueType)) - { - referenceTypes.Add(String.Format("<Word>{0}</Word>", name)); - } - } - } - - foreach (var type in _declaredTypes) - { - if (type.Kind == TypeKind.Interface || type.Kind == TypeKind.Enum) - { - interfaceTypes.Add(String.Format("<Word>{0}</Word>", type.Name)); - } - else if (type.Kind == TypeKind.Class) - { - referenceTypes.Add(String.Format("<Word>{0}</Word>", type.Name)); - } - } - - if (referenceTypes.Count > 0) - { - text = text.Replace("<Word>@ReferenceTypes@</Word>", String.Join(Environment.NewLine, referenceTypes.Distinct())); - } - - if (interfaceTypes.Count > 0) - { - text = text.Replace("<Word>@InterfaceTypes@</Word>", String.Join(Environment.NewLine, interfaceTypes.Distinct())); - } - - MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(text)); - - XmlTextReader xshd_reader = new XmlTextReader(ms); - - Dispatcher.BeginInvoke(new Action(() => - { - SyntaxHighlighting = HighlightingLoader.Load(xshd_reader, HighlightingManager.Instance); - xshd_reader.Close(); - ms.Dispose(); - })); - - - foreach (var knownType in _knownTypes) - { - knownType.LoadDocumentation(); - } - } - - _isLoadingTypes = false; - }); - t.IsBackground = true; - t.Start(); - } - } - - private void InvalidateScriptTypesHighlightings() - { - var declaredTypes = _parser.GetDeclaredTypes(Text); - - if (declaredTypes.Exists(x => !_declaredTypes.Exists(y => y.Name == x.Name)) || _declaredTypes.Exists(x => !declaredTypes.Exists(y => y.Name == x.Name))) - { - _declaredTypes = declaredTypes; - InvalidateHighlighting(); - } - - _declaredTypes = declaredTypes; - - //for (int i = 0; i < TextArea.TextView.LineTransformers.Count; i++) - //{ - // if (TextArea.TextView.LineTransformers[i] is OffsetColorizer) - // { - // TextArea.TextView.LineTransformers.RemoveAt(i); - // } - //} - - //foreach (var cls in scriptClasses) - //{ - // Document.BeginUpdate(); - - // var line = Document.GetLineByOffset(cls.Index); - - // OffsetColorizer colorizer = new OffsetColorizer(line, cls.Index, cls.Index + cls.Name.Length, Brushes.Red); - // TextArea.TextView.LineTransformers.Add(colorizer); - - // Document.EndUpdate(); - //} - } - - #endregion - #region Override Methods /// <summary> @@ -760,13 +300,8 @@ namespace Tango.Scripting.Editors #endregion - #region Intellisense + #region Text Entered - /// <summary> - /// Handles the TextEntered event of the TextArea control. - /// </summary> - /// <param name="sender">The source of the event.</param> - /// <param name="e">The <see cref="TextCompositionEventArgs"/> instance containing the event data.</param> private void TextArea_TextEntered(object sender, TextCompositionEventArgs e) { List<Object> items = new List<object>(); @@ -1029,6 +564,31 @@ namespace Tango.Scripting.Editors ShowCompletionWindow(data, GetCurrentWord()); } + else if (e.Text == "{") + { + int parentesisCount = lineText.TakeWhile(x => x != '{').Count(x => x == '\"'); + + if (parentesisCount % 2 == 0) + { + Document.Insert(CaretOffset, "}"); + CaretOffset--; + } + } + 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) == "}") + { + CaretOffset--; + Document.Insert(CaretOffset, "\n\t"); + } + } else if (!currentWordIncludingParenthesis.Contains(".") || currentWord[currentWord.Length - 2] == '<') { if (completionWindow.IsVisible) @@ -1214,11 +774,19 @@ namespace Tango.Scripting.Editors } } + #endregion + + #region Completion Window Insertion + private void CompletionWindow_InsertionRequest(ICompletionData item) { item.Complete(this); } + #endregion + + #region Private/Internal Methods + private void ShowCompletionWindow(IList<ICompletionData> suggestions, String filter) { IList<ICompletionData> data = completionWindow.CompletionList.CompletionData; @@ -1396,10 +964,6 @@ namespace Tango.Scripting.Editors return null; } - #endregion - - #region Popup - private void ShowPopup(Object content) { var position = TextArea.Caret.Position; @@ -1507,19 +1071,19 @@ namespace Tango.Scripting.Editors popup.Methods.Add(method); } - //if (false) - //{ - // popup.CurrentMethod = popup.Methods.FirstOrDefault(x => x.Parameters.Count == session.ParameterIndex + 1); + if (session.ParameterIndex > 0) + { + 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.CurrentMethod = popup.Methods.FirstOrDefault(); + } + } + else + { + popup.CurrentMethod = popup.Methods.FirstOrDefault(); + } if (popup.CurrentMethod != null) { @@ -1576,6 +1140,456 @@ namespace Tango.Scripting.Editors return popup; } + private void InvalidateHighlighting() + { + if (!_isLoadingTypes) + { + _isLoadingTypes = true; + _knownTypes.Clear(); + + var assemblies = ReferenceAssemblies.ToList(); + var usings = _current_usings.ToList(); + + Thread t = new Thread(() => + { + foreach (var asm in assemblies.Select(x => x.Assembly)) + { + Parallel.ForEach(asm.GetTypes().Where(x => x.IsVisible && x.IsPublic && !x.IsPrimitive), (type) => + { + if (usings.Exists(x => type.Namespace == x)) + { + lock (_knownTypes) + { + if (!_knownTypes.Exists(x => x.Type.FullName == type.FullName)) + { + _knownTypes.Add(new KnownType(type)); + } + } + } + }); + } + + if (_knownTypes.Count > 0 || _declaredTypes.Count > 0) + { + String text = String.Empty; + + Stream xshd_stream = typeof(ScriptEditor).Assembly.GetManifestResourceStream("Tango.Scripting.Editors.Highlighting.Resources.CSharp-Mode.xshd"); + + using (StreamReader reader = new StreamReader(xshd_stream)) + { + text = reader.ReadToEnd(); + } + + List<String> referenceTypes = new List<string>(); + List<String> interfaceTypes = new List<string>(); + + lock (_knownTypes) + { + foreach (var type in _knownTypes.ToList().Where(x => x != null)) + { + String name = type.Name; + + if (type.Type.ContainsGenericParameters) + { + name = new String(name.TakeWhile(x => x != '`').ToArray()); + } + + if (type.Type.IsInterface || type.Type.IsEnum) + { + interfaceTypes.Add(String.Format("<Word>{0}</Word>", name)); + } + else if (type.Type.IsClass || (type.Type.IsValueType)) + { + referenceTypes.Add(String.Format("<Word>{0}</Word>", name)); + } + } + } + + foreach (var type in _declaredTypes) + { + if (type.Kind == TypeKind.Interface || type.Kind == TypeKind.Enum) + { + interfaceTypes.Add(String.Format("<Word>{0}</Word>", type.Name)); + } + else if (type.Kind == TypeKind.Class) + { + referenceTypes.Add(String.Format("<Word>{0}</Word>", type.Name)); + } + } + + if (referenceTypes.Count > 0) + { + text = text.Replace("<Word>@ReferenceTypes@</Word>", String.Join(Environment.NewLine, referenceTypes.Distinct())); + } + + if (interfaceTypes.Count > 0) + { + text = text.Replace("<Word>@InterfaceTypes@</Word>", String.Join(Environment.NewLine, interfaceTypes.Distinct())); + } + + MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(text)); + + XmlTextReader xshd_reader = new XmlTextReader(ms); + + Dispatcher.BeginInvoke(new Action(() => + { + SyntaxHighlighting = HighlightingLoader.Load(xshd_reader, HighlightingManager.Instance); + xshd_reader.Close(); + ms.Dispose(); + })); + + + foreach (var knownType in _knownTypes) + { + knownType.LoadDocumentation(); + } + } + + _isLoadingTypes = false; + }); + t.IsBackground = true; + t.Start(); + } + } + + private void InvalidateScriptTypesHighlightings() + { + var declaredTypes = _parser.GetDeclaredTypes(Text); + + if (declaredTypes.Exists(x => !_declaredTypes.Exists(y => y.Name == x.Name)) || _declaredTypes.Exists(x => !declaredTypes.Exists(y => y.Name == x.Name))) + { + _declaredTypes = declaredTypes; + InvalidateHighlighting(); + } + + _declaredTypes = declaredTypes; + + //for (int i = 0; i < TextArea.TextView.LineTransformers.Count; i++) + //{ + // if (TextArea.TextView.LineTransformers[i] is OffsetColorizer) + // { + // TextArea.TextView.LineTransformers.RemoveAt(i); + // } + //} + + //foreach (var cls in scriptClasses) + //{ + // Document.BeginUpdate(); + + // var line = Document.GetLineByOffset(cls.Index); + + // OffsetColorizer colorizer = new OffsetColorizer(line, cls.Index, cls.Index + cls.Name.Length, Brushes.Red); + // TextArea.TextView.LineTransformers.Add(colorizer); + + // Document.EndUpdate(); + //} + } + + private void InvalidateUsings() + { + var oldUsings = _current_usings.ToList(); + _current_usings = _parser.GetUsings(Text); + + if (_current_usings.Exists(x => !oldUsings.Exists(y => y == x)) || oldUsings.Exists(x => !_current_usings.Exists(y => y == x))) + { + InvalidateHighlighting(); + } + } + + private void InvalidateFolding() + { + if (EnableFolding) + { + if (foldingManager == null) + { + foldingManager = FoldingManager.Install(TextArea); + } + + foldingStrategy.UpdateFoldings(foldingManager, Document); + } + } + + private void IndentCode() + { + Text = Indentation.CSharp.CSharpIndentationHelper.IndentCSharpCode(Text); + //Text = _parser.IndentCSharpCode(Text); + } + + internal DocumentLine GetCurrentLine() + { + int offset = CaretOffset; + var line = Document.GetLineByOffset(offset); + return line; + } + + private String GetCurrentLineText() + { + var text = Document.GetText(GetCurrentLine()); + return text; + } + + internal String GetCurrentWord() + { + return GetWordByEndIndex(CaretOffset); + } + + private String GetWordByEndIndex(int index) + { + String word = String.Empty; + var line = GetCurrentLine(); + + int position = index; + + for (int i = position - 1; i >= line.Offset; i--) + { + char c = Document.GetText(i, 1).First(); + + if (word_separators.Contains(c)) + { + break; + } + + word += c; + } + + word = new string(word.Reverse().ToArray()); + + if (word.Length > 0) + { + word = word.Replace(".", ""); + } + + return word; + } + + internal int GetCurrentWordStartIndex() + { + var line = GetCurrentLine(); + + int position = CaretOffset; + + for (int i = position - 1; i >= line.Offset; i--) + { + char c = Document.GetText(i, 1).First(); + + if (word_separators.Contains(c)) + { + return i + 1; + } + } + + return line.Offset; + } + + private String GetPreviousWord() + { + int index = GetCurrentWordStartIndex() - 1; + return GetWordByEndIndex(index); + } + + private ConstructionSession GetConstructionSession() + { + var expression = _parser.GetCurrentConstructionExpression(GetCurrentLineText()); + + if (expression != null) + { + ConstructionSession session = new ConstructionSession(); + + var line = GetCurrentLine(); + int parameterIndex = 0; + for (int i = CaretOffset; i > line.Offset; i--) + { + String c = Document.GetText(i, 1); + + if (c == "(") + { + var typeDeclaration = expression.Type as GenericNameSyntax; + + KnownType type = null; + + if (typeDeclaration != null) + { + var typeName = typeDeclaration.Identifier.ToString(); + var argumentsCount = typeDeclaration.TypeArgumentList.Arguments.Count; + session.TypeArguments = typeDeclaration.TypeArgumentList.Arguments.Select(x => x.ToString()).ToList(); + + if (argumentsCount == 0) + { + type = _knownTypes.FirstOrDefault(x => x.Type.Name == expression.Type.ToString()); + } + else + { + type = _knownTypes.FirstOrDefault(x => x.Type.Name == typeName + "`" + argumentsCount); + } + } + else + { + type = _knownTypes.FirstOrDefault(x => x.Name == expression.Type.ToString()); + } + + if (type != null) + { + session.Type = type; + session.ParameterIndex = parameterIndex; + return session; + } + else + { + return null; + } + } + else if (c == ",") + { + parameterIndex++; + } + + } + } + + return null; + } + + private MethodSession GetMethodSession() + { + var words = GetCurrentLineText().Split(' '); + + if (words.Count() > 0 && (words.First() == "private" || words.First() == "public" || words.First() == "void")) + { + return null; + } + + var expression = words.LastOrDefault(); + + if (expression != null) + { + int parameterIndex = expression.Count(x => x == ','); + expression = new string(expression.TakeWhile(x => x != '(').ToArray()); + + var tree = expression.Split('.').Select(x => x.Remove(@"\n|\r|\s|\t|\(|\)|\[|\]|<.*>")).ToList(); + var variableName = tree.FirstOrDefault(); + + if (variableName != null && tree.Count > 1) + { + tree.RemoveAt(0); + var variables = _parser.GetContextSymbols(Document.Text, CaretOffset); + var variable = variables.FirstOrDefault(x => x.Name == variableName); + + if (variable != null) + { + var knownType = _knownTypes.FirstOrDefault(x => x.FriendlyName == Regex.Replace(variable.Type, "<.+>", "<T>")); + + if (knownType != null) + { + while (tree.Count > 1) + { + var memberName = tree.First(); + tree.RemoveAt(0); + var member = knownType.Members.FirstOrDefault(x => x.Name == memberName); + + if (member == null) + { + return null; + } + + knownType = _knownTypes.FirstOrDefault(x => x.Type.Namespace + "." + x.Type.Name == member.ReturnType.Namespace + "." + member.ReturnType.Name); + } + + return new MethodSession() + { + Type = knownType, + MethodName = tree.Last(), + ParameterIndex = parameterIndex, + }; + } + } + } + } + + return null; + } + + private DeclaredMethodSession GetDeclaredMethodSession() + { + var words = GetCurrentLineText().Split(' '); + + if (words.Count() > 0 && (words.First() == "private" || words.First() == "public" || words.First() == "void")) + { + return null; + } + + 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; + } + + private List<String> GetPreviousWords() + { + var currentLine = GetCurrentLine(); + var currentText = Document.GetText(currentLine.Offset, CaretOffset - currentLine.Offset); + return currentText.Split(' ', ',').ToList(); + } + #endregion } } diff --git a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptParser.cs b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptParser.cs index f022f7999..15760c950 100644 --- a/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptParser.cs +++ b/Software/Visual_Studio/TEMP/Tango.Scripting/Tango.Scripting/Parsing/ScriptParser.cs @@ -48,6 +48,8 @@ namespace Tango.Scripting.Parsing { var currentNode = GetCaretOffsetNode(code, caretOffset); + if (currentNode == null) return new List<ScriptSymbol>(); + if (currentNode.Ancestors().OfType<BaseTypeDeclarationSyntax>().Count() == 0) { var usings = GetUsingsFull(code); |
