Ejemplo n.º 1
0
        private bool ISAC_EvaluateKeyDownEvent(Key k)
        {
            if (ISAC_Open && AC_Open)
            {
                switch (k)
                {
                case Key.Enter:
                {
                    var startOffset = editor.CaretOffset - 1;
                    var endOffset   = startOffset;
                    for (var i = startOffset; i >= 0; --i)
                    {
                        if (!IsValidFunctionChar(editor.Document.GetCharAt(i)))
                        {
                            break;
                        }
                        endOffset = i;
                    }

                    var    length = startOffset - endOffset + 1;
                    string replaceString;
                    if (AC_IsFuncC)
                    {
                        replaceString = ((ACNode)AutoCompleteBox.SelectedItem).EntryName;
                        if (acEntrys[AutoCompleteBox.SelectedIndex].IsExecuteable)
                        {
                            replaceString = replaceString + "(";
                        }
                    }
                    else
                    {
                        replaceString = ((ISNode)MethodAutoCompleteBox.SelectedItem).EntryName;
                        if (isEntrys[MethodAutoCompleteBox.SelectedIndex].IsExecuteable)
                        {
                            replaceString = replaceString + "(";
                        }
                    }

                    editor.Document.Replace(endOffset, length, replaceString);
                    return(true);
                }

                case Key.Up:
                {
                    if (AC_IsFuncC)
                    {
                        AutoCompleteBox.SelectedIndex = Math.Max(0, AutoCompleteBox.SelectedIndex - 1);
                        AutoCompleteBox.ScrollIntoView(AutoCompleteBox.SelectedItem);
                    }
                    else
                    {
                        MethodAutoCompleteBox.SelectedIndex = Math.Max(0, MethodAutoCompleteBox.SelectedIndex - 1);
                        MethodAutoCompleteBox.ScrollIntoView(MethodAutoCompleteBox.SelectedItem);
                    }

                    return(true);
                }

                case Key.Down:
                {
                    if (AC_IsFuncC)
                    {
                        AutoCompleteBox.SelectedIndex = Math.Min(AutoCompleteBox.Items.Count - 1,
                                                                 AutoCompleteBox.SelectedIndex + 1);
                        AutoCompleteBox.ScrollIntoView(AutoCompleteBox.SelectedItem);
                    }
                    else
                    {
                        MethodAutoCompleteBox.SelectedIndex = Math.Min(MethodAutoCompleteBox.Items.Count - 1,
                                                                       MethodAutoCompleteBox.SelectedIndex + 1);
                        MethodAutoCompleteBox.ScrollIntoView(MethodAutoCompleteBox.SelectedItem);
                    }

                    return(true);
                }

                case Key.Escape:
                {
                    HideISAC();
                    return(true);
                }
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        private void EvaluateIntelliSense()
        {
            if (editor.SelectionLength > 0)
            {
                HideISAC();
                return;
            }

            var currentLineIndex     = editor.TextArea.Caret.Line - 1;
            var line                 = editor.Document.Lines[currentLineIndex];
            var text                 = editor.Document.GetText(line.Offset, line.Length);
            var lineOffset           = editor.TextArea.Caret.Column - 1;
            var caretOffset          = editor.CaretOffset;
            var ForwardShowAC        = false;
            var ForwardShowIS        = false;
            var ISFuncNameStr        = string.Empty;
            var ISFuncDescriptionStr = string.Empty;
            var ForceReSet           = currentLineIndex != LastShowedLine;
            var ForceISKeepsClosed   = ForceReSet;
            var xPos                 = int.MaxValue;

            LastShowedLine = currentLineIndex;
            var quotationCount = 0;
            var MethodAC       = false;

            for (var i = 0; i < lineOffset; ++i)
            {
                if (text[i] == '"')
                {
                    if (i != 0)
                    {
                        if (text[i - 1] != '\\')
                        {
                            quotationCount++;
                        }
                    }
                }
                if (quotationCount % 2 == 0)
                {
                    if (text[i] == '/')
                    {
                        if (i != 0)
                        {
                            if (text[i - 1] == '/')
                            {
                                HideISAC();
                                return;
                            }
                        }
                    }
                }
            }

            foreach (var c in text)
            {
                if (c == '#')
                {
                    HideISAC();
                    return;
                }

                if (!char.IsWhiteSpace(c))
                {
                    break;
                }
            }

            var mc = multilineCommentRegex.Matches(editor.Text,
                                                   0); //it hurts me to do it here..but i have no other choice...
            var mlcCount = mc.Count;

            for (var i = 0; i < mlcCount; ++i)
            {
                if (caretOffset >= mc[i].Index)
                {
                    if (caretOffset <= mc[i].Index + mc[i].Length)
                    {
                        HideISAC();
                        return;
                    }
                }
                else
                {
                    break;
                }
            }

            if (lineOffset > 0)
            {
                #region IS

                var ISMatches  = ISFindRegex.Matches(text);
                var scopeLevel = 0;
                for (var i = lineOffset - 1; i >= 0; --i)
                {
                    if (text[i] == ')')
                    {
                        scopeLevel++;
                    }
                    else if (text[i] == '(')
                    {
                        scopeLevel--;
                        if (scopeLevel < 0)
                        {
                            var FoundMatch  = false;
                            var searchIndex = i;
                            for (var j = 0; j < ISMatches.Count; ++j)
                            {
                                if (searchIndex >= ISMatches[j].Index &&
                                    searchIndex <= ISMatches[j].Index + ISMatches[j].Length)
                                {
                                    FoundMatch = true;
                                    var testString  = ISMatches[j].Groups["name"].Value;
                                    var classString = ISMatches[j].Groups["class"].Value;
                                    if (classString.Length > 0)
                                    {
                                        var methodString = ISMatches[j].Groups["method"].Value;
                                        var found        = false;

                                        // Match for static methods.
                                        var staticMethodMap = methodMaps.FirstOrDefault(e => e.Name == classString);
                                        var staticMethod    =
                                            staticMethodMap?.Methods.FirstOrDefault(e => e.Name == methodString);
                                        if (staticMethod != null)
                                        {
                                            xPos = ISMatches[j].Groups["method"].Index +
                                                   ISMatches[j].Groups["method"].Length;
                                            ForwardShowIS        = true;
                                            ISFuncNameStr        = staticMethod.FullName;
                                            ISFuncDescriptionStr = staticMethod.CommentString;
                                            ForceReSet           = true;
                                            found = true;
                                        }

                                        // Try to find declaration
                                        if (!found)
                                        {
                                            var pattern =
                                                $@"\b((?<class>[a-zA-Z_]([a-zA-Z0-9_]?)+))\s+({classString})\s*(;|=)";
                                            var findDecl   = new Regex(pattern, RegexOptions.Compiled);
                                            var match      = findDecl.Match(editor.Text);
                                            var classMatch = match.Groups["class"].Value;
                                            if (classMatch.Length > 0)
                                            {
                                                var methodMap = methodMaps.FirstOrDefault(e => e.Name == classMatch);
                                                var method    =
                                                    methodMap?.Methods.FirstOrDefault(e => e.Name == methodString);
                                                if (method != null)
                                                {
                                                    xPos = ISMatches[j].Groups["method"].Index +
                                                           ISMatches[j].Groups["method"].Length;
                                                    ForwardShowIS        = true;
                                                    ISFuncNameStr        = method.FullName;
                                                    ISFuncDescriptionStr = method.CommentString;
                                                    ForceReSet           = true;
                                                    found = true;
                                                }
                                            }
                                        }

                                        // Match the first found
                                        if (!found)
                                        {
                                            // Many any methodmap, since the ide is not aware of the types
                                            foreach (var methodMap in methodMaps)
                                            {
                                                var method =
                                                    methodMap.Methods.FirstOrDefault(e => e.Name == methodString);

                                                if (method == null)
                                                {
                                                    continue;
                                                }

                                                xPos = ISMatches[j].Groups["method"].Index +
                                                       ISMatches[j].Groups["method"].Length;
                                                ForwardShowIS        = true;
                                                ISFuncNameStr        = method.FullName;
                                                ISFuncDescriptionStr = method.CommentString;
                                                ForceReSet           = true;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        var func = funcs.FirstOrDefault(e => e.Name == testString);
                                        if (func != null)
                                        {
                                            xPos = ISMatches[j].Groups["name"].Index +
                                                   ISMatches[j].Groups["name"].Length;
                                            ForwardShowIS        = true;
                                            ISFuncNameStr        = func.FullName;
                                            ISFuncDescriptionStr = func.CommentString;
                                            ForceReSet           = true;
                                        }
                                    }

                                    break;
                                }
                            }

                            if (FoundMatch)
                            {
                                // ReSharper disable once RedundantAssignment
                                scopeLevel--; //i have no idea why this works...
                                break;
                            }
                        }
                    }
                }

                #endregion

                #region AC

                if (IsValidFunctionChar(text[lineOffset - 1]) && quotationCount % 2 == 0)
                {
                    var IsNextCharValid = true;
                    if (text.Length > lineOffset)
                    {
                        if (IsValidFunctionChar(text[lineOffset]) || text[lineOffset] == '(')
                        {
                            IsNextCharValid = false;
                        }
                    }
                    if (IsNextCharValid)
                    {
                        var endOffset = lineOffset - 1;
                        for (var i = endOffset; i >= 0; --i)
                        {
                            if (!IsValidFunctionChar(text[i]))
                            {
                                if (text[i] == '.')
                                {
                                    MethodAC = true;
                                }
                                break;
                            }

                            endOffset = i;
                        }

                        var testString = text.Substring(endOffset, lineOffset - 1 - endOffset + 1);
                        if (testString.Length > 0)
                        {
                            if (MethodAC)
                            {
                                for (var i = 0; i < isEntrys.Length; ++i)
                                {
                                    if (isEntrys[i].EntryName.StartsWith(testString,
                                                                         StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        if (testString != isEntrys[i].EntryName)
                                        {
                                            ForwardShowAC = true;
                                            MethodAutoCompleteBox.SelectedIndex = i;
                                            MethodAutoCompleteBox.ScrollIntoView(MethodAutoCompleteBox.SelectedItem);
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                for (var i = 0; i < acEntrys.Length; ++i)
                                {
                                    if (acEntrys[i].EntryName.StartsWith(testString,
                                                                         StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        if (testString != acEntrys[i].EntryName)
                                        {
                                            ForwardShowAC = true;
                                            AutoCompleteBox.SelectedIndex = i;
                                            AutoCompleteBox.ScrollIntoView(AutoCompleteBox.SelectedItem);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                #endregion
            }

            if (!ForwardShowAC)
            {
                if (ForceISKeepsClosed)
                {
                    ForwardShowIS = false;
                }
            }
            if (ForwardShowAC | ForwardShowIS)
            {
                if (ForwardShowAC)
                {
                    ShowAC(!MethodAC);
                }
                else
                {
                    HideAC();
                }
                if (ForwardShowIS)
                {
                    ShowIS(ISFuncNameStr, ISFuncDescriptionStr);
                }
                else
                {
                    HideIS();
                }
                if (ForceReSet && ISAC_Open)
                {
                    SetISACPosition(xPos);
                }
                ShowISAC(xPos);
            }
            else
            {
                HideISAC();
            }
        }
Ejemplo n.º 3
0
        private void EvaluateIntelliSense()
        {
            if (editor.SelectionLength > 0)
            {
                HideISAC();
                return;
            }
            int    currentLineIndex     = editor.TextArea.Caret.Line - 1;
            var    line                 = editor.Document.Lines[currentLineIndex];
            string text                 = editor.Document.GetText(line.Offset, line.Length);
            int    lineOffset           = editor.TextArea.Caret.Column - 1;
            int    caretOffset          = editor.CaretOffset;
            bool   ForwardShowAC        = false;
            bool   ForwardShowIS        = false;
            string ISFuncNameStr        = string.Empty;
            string ISFuncDescriptionStr = string.Empty;
            bool   ForceReSet           = (currentLineIndex != LastShowedLine);
            bool   ForceISKeepsClosed   = ForceReSet;
            int    xPos                 = int.MaxValue;

            LastShowedLine = currentLineIndex;
            int  quotationCount = 0;
            bool MethodAC       = false;

            for (int i = 0; i < lineOffset; ++i)
            {
                if (text[i] == '"')
                {
                    if (i != 0)
                    {
                        if (text[i - 1] != '\\')
                        {
                            quotationCount++;
                        }
                    }
                }
                if ((quotationCount % 2) == 0)
                {
                    if (text[i] == '/')
                    {
                        if (i != 0)
                        {
                            if (text[i - 1] == '/')
                            {
                                HideISAC();
                                return;
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < text.Length; ++i)
            {
                if (text[i] == '#')
                {
                    HideISAC();
                    return;
                }
                if (!char.IsWhiteSpace(text[i]))
                {
                    break;
                }
            }
            MatchCollection mc       = multilineCommentRegex.Matches(editor.Text, 0); //it hurts me to do it here..but i have no other choice...
            int             mlcCount = mc.Count;

            for (int i = 0; i < mlcCount; ++i)
            {
                if (caretOffset >= mc[i].Index)
                {
                    if (caretOffset <= (mc[i].Index + mc[i].Length))
                    {
                        HideISAC();
                        return;
                    }
                }
                else
                {
                    break;
                }
            }
            if (lineOffset > 0)
            {
                #region IS
                MatchCollection ISMatches  = ISFindRegex.Matches(text);
                int             scopeLevel = 0;
                for (int i = lineOffset - 1; i >= 0; --i)
                {
                    if (text[i] == ')')
                    {
                        scopeLevel++;
                    }
                    else if (text[i] == '(')
                    {
                        scopeLevel--;
                        if (scopeLevel < 0)
                        {
                            bool FoundMatch  = false;
                            int  searchIndex = i;
                            for (int j = 0; j < ISMatches.Count; ++j)
                            {
                                if ((searchIndex >= ISMatches[j].Index) && (searchIndex <= (ISMatches[j].Index + ISMatches[j].Length)))
                                {
                                    FoundMatch = true;
                                    string testString = ISMatches[j].Groups["name"].Value;
                                    for (int k = 0; k < funcs.Length; ++k)
                                    {
                                        if (testString == funcs[k].Name)
                                        {
                                            xPos                 = ISMatches[j].Groups["name"].Index + ISMatches[j].Groups["name"].Length;
                                            ForwardShowIS        = true;
                                            ISFuncNameStr        = funcs[k].FullName;
                                            ISFuncDescriptionStr = funcs[k].Comment;
                                            ForceReSet           = true;
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }
                            if (FoundMatch)
                            {
                                scopeLevel--; //i have no idea why this works...
                                break;
                            }
                        }
                    }
                }
                #endregion
                #region AC
                if (IsValidFunctionChar(text[lineOffset - 1]) && (quotationCount % 2) == 0)
                {
                    bool IsNextCharValid = true;
                    if (text.Length > lineOffset)
                    {
                        if (IsValidFunctionChar(text[lineOffset]) || text[lineOffset] == '(')
                        {
                            IsNextCharValid = false;
                        }
                    }
                    if (IsNextCharValid)
                    {
                        int endOffset = lineOffset - 1;
                        for (int i = endOffset; i >= 0; --i)
                        {
                            if (!IsValidFunctionChar(text[i]))
                            {
                                if (text[i] == '.')
                                {
                                    MethodAC = true;
                                }
                                break;
                            }
                            endOffset = i;
                        }
                        string testString = text.Substring(endOffset, ((lineOffset - 1) - endOffset) + 1);
                        if (testString.Length > 0)
                        {
                            if (MethodAC)
                            {
                                for (int i = 0; i < isEntrys.Length; ++i)
                                {
                                    if (isEntrys[i].Name.StartsWith(testString, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        if (testString != isEntrys[i].Name)
                                        {
                                            ForwardShowAC = true;
                                            MethodAutoCompleteBox.SelectedIndex = i;
                                            MethodAutoCompleteBox.ScrollIntoView(MethodAutoCompleteBox.SelectedItem);
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                for (int i = 0; i < acEntrys.Length; ++i)
                                {
                                    if (acEntrys[i].Name.StartsWith(testString, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        if (testString != acEntrys[i].Name)
                                        {
                                            ForwardShowAC = true;
                                            AutoCompleteBox.SelectedIndex = i;
                                            AutoCompleteBox.ScrollIntoView(AutoCompleteBox.SelectedItem);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion
            }
            if (!ForwardShowAC)
            {
                if (ForceISKeepsClosed)
                {
                    ForwardShowIS = false;
                }
            }
            if (ForwardShowAC | ForwardShowIS)
            {
                if (ForwardShowAC)
                {
                    ShowAC(!MethodAC);
                }
                else
                {
                    HideAC();
                }
                if (ForwardShowIS)
                {
                    ShowIS(ISFuncNameStr, ISFuncDescriptionStr);
                }
                else
                {
                    HideIS();
                }
                if (ForceReSet && ISAC_Open)
                {
                    SetISACPosition(xPos);
                }
                ShowISAC(xPos);
            }
            else
            {
                HideISAC();
            }
        }