Esempio n. 1
0
        private static string FindFullExpression(string Text, TextArea _textArea, out PascalABCCompiler.Parsers.KeywordKind keyw, out string full_expr)
        {
            keyw = PascalABCCompiler.Parsers.KeywordKind.None;
            string expr_without_brackets = null;

            full_expr = null;
            if (CodeCompletion.CodeCompletionController.CurrentParser != null)
            {
                full_expr = CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.FindExpressionFromAnyPosition(_textArea.Caret.Offset, Text, _textArea.Caret.Line, _textArea.Caret.Column, out keyw, out expr_without_brackets);
                return(expr_without_brackets);
            }
            return(null);
        }
        public ICompletionData[] GenerateCompletionDataByFirstChar(string fileName, TextArea textArea, char charTyped, PascalABCCompiler.Parsers.KeywordKind keyw)
        {
            controller = new CodeCompletion.CodeCompletionController();
            int    off  = textArea.Caret.Offset;
            string text = textArea.Document.TextContent.Substring(0, textArea.Caret.Offset);

            //controller.Compile(fileName, text /*+ ")))));end."*/);
            FileName = fileName; Text = text;
            ICompletionData[] data = GetCompletionDataByFirst(off, text, textArea.Caret.Line, textArea.Caret.Column, charTyped, keyw);
            CodeCompletion.AssemblyDocCache.CompleteDocumentation();
            CodeCompletion.UnitDocCache.CompleteDocumentation();
            controller = null;
            //GC.Collect();
            return(data);
        }
        public ICompletionData[] GetCompletionData(int off, string Text, int line, int col, char charTyped, PascalABCCompiler.Parsers.KeywordKind keyw)
        {
            List <ICompletionData> resultList = new List <ICompletionData>();

            try
            {
                string pattern            = null;
                string expr               = null;
                bool   ctrl_space         = charTyped == '\0' || charTyped == '_';
                bool   shift_space        = charTyped == '\0';
                bool   inside_dot_pattern = false;
                bool   new_space          = keyw == PascalABCCompiler.Parsers.KeywordKind.New;
                if (ctrl_space)
                {
                    bool is_pattern = false;
                    pattern = CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.FindPattern(off, Text, out is_pattern);
                    if (is_pattern && Text[off - pattern.Length - 1] == '.')
                    {
                        inside_dot_pattern = true;
                        expr = FindExpression(off - pattern.Length - 1, Text, line, col);
                    }
                }
                else if (new_space)
                {
                    expr = CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.SkipNew(off - 1, Text, ref keyword);
                }
                else
                if (!new_space && keyw != PascalABCCompiler.Parsers.KeywordKind.Uses)
                {
                    if (charTyped != '$')
                    {
                        expr = FindExpression(off, Text, line, col);
                    }
                    else
                    {
                        expr = FindExpression(off - 1, Text, line, col);
                    }
                }
                List <PascalABCCompiler.Errors.Error>   Errors = new List <PascalABCCompiler.Errors.Error>();
                PascalABCCompiler.SyntaxTree.expression e      = null;
                if (ctrl_space && !shift_space && (pattern == null || pattern == ""))
                {
                    string[] keywords = CodeCompletion.CodeCompletionNameHelper.Helper.GetKeywords();
                    foreach (string key in keywords)
                    {
                        //if (key.StartsWith(pattern, StringComparison.CurrentCultureIgnoreCase))
                        resultList.Add(new UserDefaultCompletionData(key, null, ImagesProvider.IconNumberKeyword, false));
                    }
                }
                if ((!ctrl_space || inside_dot_pattern) && expr != null)
                {
                    e = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetTypeAsExpression("test" + System.IO.Path.GetExtension(FileName), expr, Errors, new List <PascalABCCompiler.Errors.CompilerWarning>());
                    if (e == null)
                    {
                        Errors.Clear();
                        e = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetExpression("test" + System.IO.Path.GetExtension(FileName), expr, Errors, new List <PascalABCCompiler.Errors.CompilerWarning>());
                    }
                    if ((e == null || Errors.Count > 0) && !new_space)
                    {
                        return(null);
                    }
                }
                SymInfo[] mis = null;
                CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[FileName];
                if (dconv == null)
                {
                    if (keyw == PascalABCCompiler.Parsers.KeywordKind.Uses)
                    {
                        mis = CodeCompletion.DomConverter.standard_units;
                    }
                    else if (!ctrl_space)
                    {
                        return(new ICompletionData[0]);
                    }
                }
                string  fname            = FileName;
                SymInfo sel_si           = null;
                string  last_used_member = null;
                if (dconv != null)
                {
                    if (new_space)
                    {
                        mis = dconv.GetTypes(e, line, col, out sel_si);
                    }
                    else if (keyw == PascalABCCompiler.Parsers.KeywordKind.Uses && mis == null)
                    {
                        if (WorkbenchServiceFactory.Workbench.UserOptions.EnableSmartIntellisense)
                        {
                            mis = dconv.GetNamespaces();
                        }
                        else
                        {
                            mis = CodeCompletion.DomConverter.standard_units;
                        }
                    }

                    else
                    if (!ctrl_space)
                    {
                        CodeCompletion.SymScope dot_sc = null;
                        mis = dconv.GetName(e, expr, line, col, keyword, ref dot_sc);
                        if (dot_sc != null && VisualPABCSingleton.MainForm.UserOptions.EnableSmartIntellisense)
                        {
                            CompletionDataDispatcher.AddMemberBeforeDot(dot_sc);
                            last_used_member = CompletionDataDispatcher.GetRecentUsedMember(dot_sc);
                        }
                    }
                    else
                    {
                        CodeCompletion.SymScope dot_sc = null;
                        if (inside_dot_pattern)
                        {
                            List <SymInfo> si_list   = new List <SymInfo>();
                            SymInfo[]      from_list = dconv.GetName(e, expr, line, col, keyword, ref dot_sc);
                            for (int i = 0; i < from_list.Length; i++)
                            {
                                if (from_list[i].name.StartsWith(pattern, StringComparison.OrdinalIgnoreCase))
                                {
                                    si_list.Add(from_list[i]);
                                }
                            }
                            mis = si_list.ToArray();
                        }

                        else
                        {
                            mis = dconv.GetNameByPattern(pattern, line, col, charTyped == '_', VisualPABCSingleton.MainForm.UserOptions.CodeCompletionNamespaceVisibleRange);
                        }
                    }
                }
                Hashtable cache = null;
                if (!CodeCompletion.CodeCompletionController.CurrentParser.CaseSensitive)
                {
                    cache = new Hashtable(StringComparer.CurrentCultureIgnoreCase);
                }
                else
                {
                    cache = new Hashtable();
                }
                int num = 0;
                if (mis != null)
                {
                    bool            stop = false;
                    ICompletionData data = null;

                    foreach (SymInfo mi in mis)
                    {
                        if (mi.not_include)
                        {
                            continue;
                        }
                        if (cache.Contains(mi.name))
                        {
                            continue;
                        }

                        UserDefaultCompletionData ddd = new UserDefaultCompletionData(mi.addit_name != null ? mi.addit_name : mi.name, mi.description, ImagesProvider.GetPictureNum(mi), false);

                        disp.Add(mi, ddd);
                        resultList.Add(ddd);
                        cache[mi.name] = mi;

                        /*if (VisualPABCSingleton.MainForm.UserOptions.EnableSmartIntellisense && mi.name != null && mi.name != "" && data == null)
                         * {
                         *              data = CompletionDataDispatcher.GetLastUsedItem(mi.name[0]);
                         *              if (data != null && data.Text == ddd.Text) data = ddd;
                         * }*/
                        if (last_used_member != null && last_used_member == mi.name)
                        {
                            defaultCompletionElement = ddd;
                        }
                        if (sel_si != null && mi == sel_si)
                        {
                            defaultCompletionElement = ddd;
                            stop = true;
                        }
                    }

                    if (defaultCompletionElement == null && data != null)
                    {
                        defaultCompletionElement = data as UserDefaultCompletionData;
                    }
                }
            }
            catch (Exception e)
            {
            }
            return(resultList.ToArray());
        }
        public ICompletionData[] GetCompletionDataByFirst(int off, string Text, int line, int col, char charTyped, PascalABCCompiler.Parsers.KeywordKind keyw)
        {
            List <ICompletionData> resultList = new List <ICompletionData>();
            List <ICompletionData> lst        = new List <ICompletionData>();

            try
            {
                CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[FileName];

                /*if (dconv == null && CodeCompletion.CodeCompletionNameHelper.system_unit_file_full_name != null
                 *  && (keyw == CodeCompletion.KeywordKind.kw_colon || keyw == CodeCompletion.KeywordKind.kw_of))
                 * {
                 *      dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[CodeCompletion.CodeCompletionNameHelper.system_unit_file_full_name];
                 *      special_module = true;
                 * }*/
                string   pattern  = charTyped.ToString();
                string[] keywords = CodeCompletion.CodeCompletionNameHelper.Helper.GetKeywords();
                if (CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsTypeAfterKeyword(keyw))
                {
                    keywords = CodeCompletion.CodeCompletionNameHelper.Helper.GetTypeKeywords();
                }
                if (!CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsNamespaceAfterKeyword(keyw))
                {
                    foreach (string key in keywords)
                    {
                        //if (key.StartsWith(pattern, StringComparison.CurrentCultureIgnoreCase))
                        resultList.Add(new UserDefaultCompletionData(key, null, ImagesProvider.IconNumberKeyword, false));
                    }
                }
                PascalABCCompiler.Parsers.SymInfo[] mis = null;
                if (CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsNamespaceAfterKeyword(keyw))
                {
                    mis = CodeCompletion.DomConverter.standard_units;
                }
                if (dconv != null)
                {
                    //if (keyw == PascalABCCompiler.Parsers.KeywordKind.Colon || keyw == PascalABCCompiler.Parsers.KeywordKind.Of || keyw == PascalABCCompiler.Parsers.KeywordKind.TypeDecl)
                    if (CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsTypeAfterKeyword(keyw))
                    {
                        mis = dconv.GetTypeByPattern(pattern, line, col, true, VisualPABCSingleton.MainForm.UserOptions.CodeCompletionNamespaceVisibleRange);
                    }
                    else if (CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsNamespaceAfterKeyword(keyw) && mis == null)
                    {
                        mis = dconv.GetNamespaces();
                    }
                    else
                    {
                        mis = dconv.GetNameByPattern(null, line, col, true, VisualPABCSingleton.MainForm.UserOptions.CodeCompletionNamespaceVisibleRange);
                    }
                }
                Hashtable cache = new Hashtable();
                if (mis != null)
                {
                    bool            stop = false;
                    ICompletionData data = CompletionDataDispatcher.GetLastUsedItem(charTyped);
                    foreach (PascalABCCompiler.Parsers.SymInfo mi in mis)
                    {
                        if (mi.not_include)
                        {
                            continue;
                        }

                        if (cache.Contains(mi.name))
                        {
                            continue;
                        }

                        UserDefaultCompletionData ddd = new UserDefaultCompletionData(mi.name, mi.description, ImagesProvider.GetPictureNum(mi), false);
                        if (!stop && data != null && string.Compare(mi.name, data.Text, true) == 0)
                        {
                            defaultCompletionElement = ddd;
                            stop = true;
                        }
                        else if (!stop && data == null && mi.name.StartsWith(charTyped.ToString(), StringComparison.CurrentCultureIgnoreCase))
                        {
                            //defaultCompletionElement = ddd;
                            lst.Add(ddd);
                            //stop = true;
                        }
                        disp.Add(mi, ddd);
                        resultList.Add(ddd);
                        cache[mi.name] = mi;
                    }
                    //resultList.Sort();
                    //defaultCompletionElement = resultList[0] as DefaultCompletionData;
                }
            }
            catch (Exception e)
            {
            }

            lst.Sort();
            if (lst.Count > 0)
            {
                defaultCompletionElement = lst[0] as UserDefaultCompletionData;
            }
            ICompletionData[] res_arr = resultList.ToArray();
            this.ByFirstChar = true;
            return(res_arr);
        }
Esempio n. 5
0
        public ICompletionData[] GenerateCompletionDataWithKeyword(string fileName, TextArea textArea, char charTyped, PascalABCCompiler.Parsers.KeywordKind keyw)
        {
            controller = new CodeCompletion.CodeCompletionController();
            int    off  = textArea.Caret.Offset;
            string text = textArea.Document.TextContent.Substring(0, textArea.Caret.Offset);

            //controller.Compile(fileName, text /*+ ")))));end."*/);
            FileName = fileName; Text = text;
            //System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(CompileInThread));
            //th.Start();
            //while (th.ThreadState == System.Threading.ThreadState.Running) {}
            ICompletionData[] data = GetCompletionData(off, text, textArea.Caret.Line, textArea.Caret.Column, charTyped, keyw);
            CodeCompletion.AssemblyDocCache.CompleteDocumentation();
            CodeCompletion.UnitDocCache.CompleteDocumentation();
            controller = null;
            //GC.Collect();
            return(data);
        }