public List <PascalABCCompiler.Parsers.Position> GetDefinition(string expr, string fileName, int line, int column, bool only_check)
        {
            List <PascalABCCompiler.Errors.Error> Errors = new List <PascalABCCompiler.Errors.Error>();

            PascalABCCompiler.SyntaxTree.expression   e   = null;
            List <PascalABCCompiler.Parsers.Position> loc = null;

            if (VisualPABCSingleton.MainForm.VisualEnvironmentCompiler.compilerLoaded)
            {
                e = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetExpression("test" + System.IO.Path.GetExtension(fileName), expr, Errors, new List <PascalABCCompiler.Errors.CompilerWarning>());
            }
            if (e is PascalABCCompiler.SyntaxTree.bin_expr && expr.Contains("<"))
            {
                expr = expr.Replace("<", "&<");
                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)
            {
                return(loc);
            }
            CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[fileName];
            if (dconv == null)
            {
                return(loc);
            }
            loc = dconv.GetDefinition(e, line, column, keyword, only_check);
            return(loc);
        }
        public ICompletionData[] GenerateCompletionDataForOverridableMethods(string fileName, TextArea textArea)
        {
            controller = new CodeCompletion.CodeCompletionController();
            List <ICompletionData> lst = new List <ICompletionData>();
            int line = textArea.Caret.Line;
            int col  = textArea.Caret.Column;

            try
            {
                CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[fileName];
                SymInfo[] mis = null;
                if (dconv != null)
                {
                    mis = dconv.GetOverridableMethods(line, col);
                }
                if (mis != null)
                {
                    foreach (SymInfo mi in mis)
                    {
                        UserDefaultCompletionData ddd = new UserDefaultCompletionData(mi.name, mi.description, ImagesProvider.GetPictureNum(mi), true);
                        lst.Add(ddd);
                    }
                }
            }
            catch (Exception e)
            {
            }

            //lst.Sort();
            ICompletionData[] res_arr = lst.ToArray();
            controller = null;
            return(res_arr);
        }
        public string GetRealizationTextToAdd(string fileName, int line, int col, ref PascalABCCompiler.Parsers.Position pos, TextArea textArea)
        {
            CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[fileName];
            if (dconv == null)
            {
                return(null);
            }
            CodeCompletion.ProcScope[] procs = dconv.GetNotImplementedMethods(line, col, ref pos);
            if (procs == null)
            {
                return(null);
            }
            System.Text.StringBuilder sb = new StringBuilder();
            sb.Append("\n\n");
            for (int i = 0; i < procs.Length; i++)
            {
                int    off  = textArea.Document.PositionToOffset(new TextLocation(procs[i].GetPosition().column - 1, procs[i].GetPosition().line - 1));
                string meth = textArea.Document.GetText(off, textArea.Document.PositionToOffset(new TextLocation(procs[i].GetPosition().end_column - 1, procs[i].GetPosition().end_line - 1)) - off + 1);
                meth = construct_header(meth, procs[i], VisualPABCSingleton.MainForm.UserOptions.CursorTabCount);

                if (i < procs.Length - 1)
                {
                    sb.Append(meth);
                    sb.Append('\n');
                }
                else
                {
                    sb.Append(meth.Trim());
                }
            }
            return(sb.ToString());
        }
예제 #4
0
        private static string GetPopupHintText(TextArea textArea, ToolTipRequestEventArgs e)
        {
            ICSharpCode.TextEditor.TextLocation logicPos = e.LogicalPosition;
            IDocument   doc      = textArea.Document;
            LineSegment seg      = doc.GetLineSegment(logicPos.Y);
            string      FileName = textArea.MotherTextEditorControl.FileName;

            PascalABCCompiler.Parsers.KeywordKind keyw = PascalABCCompiler.Parsers.KeywordKind.None;
            if (logicPos.X > seg.Length - 1)
            {
                return(null);
            }
            //string expr = FindFullExpression(doc.TextContent, seg.Offset + logicPos.X,e.LogicalPosition.Line,e.LogicalPosition.Column);
            string expr_without_brackets = null;
            string expr = CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.FindExpressionFromAnyPosition(seg.Offset + logicPos.X, doc.TextContent, e.LogicalPosition.Line, e.LogicalPosition.Column, out keyw, out expr_without_brackets);

            if (expr == null)
            {
                expr = expr_without_brackets;
            }
            if (expr_without_brackets == null)
            {
                return(null);
            }
            List <PascalABCCompiler.Errors.Error> Errors = new List <PascalABCCompiler.Errors.Error>();

            PascalABCCompiler.SyntaxTree.expression tree = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetExpression("test" + Path.GetExtension(FileName), expr, Errors, new List <PascalABCCompiler.Errors.CompilerWarning>());
            bool header = false;

            if (tree == null || Errors.Count > 0)
            {
                Errors.Clear();
                tree   = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetExpression("test" + Path.GetExtension(FileName), expr_without_brackets, Errors, new List <PascalABCCompiler.Errors.CompilerWarning>());
                header = true;
                if (tree == null || Errors.Count > 0)
                {
                    return(null);
                }
            }
            else
            {
                Errors.Clear();
                PascalABCCompiler.SyntaxTree.expression tree2 = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetExpression("test" + Path.GetExtension(FileName), expr_without_brackets, Errors, new List <PascalABCCompiler.Errors.CompilerWarning>());
                //header = true;
                if (tree2 == null || Errors.Count > 0)
                {
                    return(null);
                }
                //if (tree is PascalABCCompiler.SyntaxTree.new_expr && (tree as PascalABCCompiler.SyntaxTree.new_expr).params_list == null)
                //	tree = tree2;
            }
            CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[FileName];
            if (dconv == null)
            {
                return(null);
            }
            return(dconv.GetDescription(tree, FileName, expr_without_brackets, WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.StandartCompiler.ParsersController, e.LogicalPosition.Line, e.LogicalPosition.Column, keyw, header));
        }
 public CodeCompletion.SymScope FindScopeByLocation(string fileName, int line, int col)
 {
     CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[fileName];
     if (dconv == null)
     {
         return(null);
     }
     return(dconv.FindScopeByLocation(line, col));
 }
예제 #6
0
        public void SetupDataProvider(string fileName, TextArea textArea)
        {
            try
            {
                if (setupOnlyOnce && this.textArea != null)
                {
                    if (CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsMethodCallParameterSeparator(pressed_key))
                    {
                        FindExpression(textArea.Caret.Offset, textArea.Document.TextContent.Substring(0, textArea.Caret.Offset),
                                       textArea.Caret.Line, textArea.Caret.Column);
                        num_param++;
                        return;
                    }
                    else
                    {
                        return;
                    }
                }
                this.fileName = fileName;
                this.textArea = textArea;
                this.document = textArea.Document;
                int useOffset = (lookupOffset < 0) ? textArea.Caret.Offset : lookupOffset;
                initialOffset = useOffset;
                int    i    = initialOffset - 1;
                int    off  = textArea.Caret.Offset;
                string Text = textArea.Document.TextContent.Substring(0, textArea.Caret.Offset);
                int    line = textArea.Caret.Line;
                int    col  = textArea.Caret.Column;

                string expr = FindExpression(off, Text, line, col);
                List <PascalABCCompiler.Errors.Error>   Errors = new List <PascalABCCompiler.Errors.Error>();
                PascalABCCompiler.SyntaxTree.expression e      = VisualPABCSingleton.MainForm.VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetExpression("test.pas", expr, Errors, new List <PascalABCCompiler.Errors.CompilerWarning>());
                if (e == null || Errors.Count > 0)
                {
                    return;
                }
                CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[fileName];
                string fname = fileName;
                if (dconv != null)
                {
                    //if (pressed_key == '(' || pressed_key == ',')
                    if (CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsOpenBracketForMethodCall(pressed_key) || CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsMethodCallParameterSeparator(pressed_key))
                    {
                        methods = dconv.GetNameOfMethod(e, expr, line, col, num_param, ref defaultIndex, cur_param_num, out param_count);
                    }
                    else if (CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsOpenBracketForIndex(pressed_key))
                    {
                        methods = dconv.GetIndex(e, line, col);
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
        private List <SymbolsViewerSymbol> InternalFindReferences(string fname, PascalABCCompiler.SyntaxTree.expression expr, int line, int col, bool for_refact)
        {
            List <PascalABCCompiler.Parsers.Position> lst = new List <PascalABCCompiler.Parsers.Position>();
            List <SymbolsViewerSymbol> svs_lst            = new List <SymbolsViewerSymbol>();

            try
            {
                CodeCompletion.DomConverter dc = CodeCompletion.CodeCompletionController.comp_modules[fname] as CodeCompletion.DomConverter;
                IBaseScope fnd_scope           = null;
                IBaseScope cur_sc = null;
                if (dc != null)
                {
                    fnd_scope = dc.GetSymDefinition(expr, line, col, keyword);
                    cur_sc    = dc.FindScopeByLocation(line, col);
                }
                if (fnd_scope != null)
                {
                    foreach (string FileName in CodeCompletionParserController.open_files.Keys)
                    {
                        CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController();
                        string text = VisualPABCSingleton.MainForm.VisualEnvironmentCompiler.SourceFilesProvider(FileName, PascalABCCompiler.SourceFileOperation.GetText) as string;
                        PascalABCCompiler.SyntaxTree.compilation_unit cu = controller.ParseOnlySyntaxTree(FileName, text);
                        if (cu != null)
                        {
                            dc = CodeCompletion.CodeCompletionController.comp_modules[FileName] as CodeCompletion.DomConverter;
                            CodeCompletion.ReferenceFinder rf = null;
                            if (dc != null && dc.visitor.entry_scope != null)
                            {
                                rf = new CodeCompletion.ReferenceFinder(fnd_scope, dc.visitor.entry_scope, cu, FileName, for_refact);
                                lst.AddRange(rf.FindPositions());
                            }
                        }
                    }
                    PascalABCCompiler.Parsers.Position p = fnd_scope.GetPosition();
                    bool need_add_def = !for_refact; // true
                    if (p.file_name != null && need_add_def)
                    {
                        svs_lst.Add(new SymbolsViewerSymbol(new PascalABCCompiler.SourceLocation(p.file_name, p.line, p.column, p.end_line, p.end_column), ImagesProvider.GetPictureNum(fnd_scope.SymbolInfo)));
                    }
                    foreach (PascalABCCompiler.Parsers.Position pos in lst)
                    {
                        if (pos.file_name != null)
                        {
                            svs_lst.Add(new SymbolsViewerSymbol(new PascalABCCompiler.SourceLocation(pos.file_name, pos.line, pos.column, pos.end_line, pos.end_column), ImagesProvider.IconNumberGotoText));
                        }
                    }
                }
            }
            catch (Exception e)
            {
            }
            GC.Collect();
            return(svs_lst);
            //return svs_lst.ToArray();
        }
 public string GetMethodImplementationTextToAdd(string fileName, int line, int col, ref PascalABCCompiler.Parsers.Position pos, TextArea textArea)
 {
     CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[fileName];
     if (dconv == null)
     {
         return(null);
     }
     CodeCompletion.ProcScope[] procs = dconv.GetNotImplementedMethodHeaders(line, col, ref pos);
     if (procs == null || procs.Length == 0)
     {
         return(null);
     }
     System.Text.StringBuilder sb = new StringBuilder();
     for (int i = 0; i < procs.Length; i++)
     {
         string meth = construct_header(procs[i] as CodeCompletion.ProcRealization, VisualPABCSingleton.MainForm.UserOptions.CursorTabCount);
         sb.Append(meth);
         //sb.Append('\n');
     }
     return(sb.ToString());
 }
        public List <PascalABCCompiler.Parsers.Position> GetRealization(string expr, string fileName, int line, int column)
        {
            List <PascalABCCompiler.Errors.Error> Errors = new List <PascalABCCompiler.Errors.Error>();

            PascalABCCompiler.SyntaxTree.expression   e   = null;
            List <PascalABCCompiler.Parsers.Position> loc = null;

            if (VisualPABCSingleton.MainForm.VisualEnvironmentCompiler.compilerLoaded)
            {
                e = VisualPABCSingleton.MainForm.VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetExpression("test" + System.IO.Path.GetExtension(fileName), expr, Errors, new List <PascalABCCompiler.Errors.CompilerWarning>());
            }
            if (e == null /*|| Errors.Count > 0*/)
            {
                return(loc);
            }
            CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[fileName];
            if (dconv == null)
            {
                return(loc);
            }
            loc = dconv.GetRealization(e, line, column, keyword);
            return(loc);
        }
        public List <SymbolsViewerSymbol> FindReferences(string expr, string fileName, int line, int column, bool for_refact)
        {
            List <PascalABCCompiler.Errors.Error> Errors = new List <PascalABCCompiler.Errors.Error>();

            PascalABCCompiler.SyntaxTree.expression e = null;
            if (VisualPABCSingleton.MainForm.VisualEnvironmentCompiler.compilerLoaded)
            {
                e = VisualPABCSingleton.MainForm.VisualEnvironmentCompiler.StandartCompiler.ParsersController.GetExpression("test" + System.IO.Path.GetExtension(fileName), expr, Errors, new List <PascalABCCompiler.Errors.CompilerWarning>());
            }
            if (e == null)
            {
                return(new List <SymbolsViewerSymbol>());
            }
            CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[fileName];
            if (dconv == null)
            {
                return(new List <SymbolsViewerSymbol>());
            }
            List <SymbolsViewerSymbol> lst = InternalFindReferences(fileName, e, line, column, for_refact);

            //if (lst != null && expr != null && for_refact)
            //lst.Insert(0,new SymbolsViewerSymbol(new PascalABCCompiler.SourceLocation(fileName,line+1,column,line+1,column+expr.Length),ImagesProvider.IconNumberGotoText));
            return(lst);
        }
        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);
        }
예제 #13
0
        /// <summary>
        /// Return true to handle the keypress, return false to let the text area handle the keypress
        /// </summary>
        bool TextAreaKeyEventHandler(char key)
        {
            if (!WorkbenchServiceFactory.Workbench.UserOptions.AllowCodeCompletion || !VisualPABCSingleton.MainForm.VisualEnvironmentCompiler.compilerLoaded)
            {
                return(false);
            }
            if (CodeCompletion.CodeCompletionController.CurrentParser == null)
            {
                return(false);
            }
            if (codeCompletionWindow != null)
            {
                // If completion window is open and wants to handle the key, don't let the text area
                // handle it
                if (codeCompletionWindow.ProcessKeyEvent(key))
                {
                    return(true);
                }
            }
            else
            {
                PABCNETCodeCompletionWindow ccw = CodeCompletionNamesOnlyInModuleAction.comp_windows[editor.ActiveTextAreaControl.TextArea] as PABCNETCodeCompletionWindow;

                if (ccw != null && CodeCompletionNamesOnlyInModuleAction.is_begin)
                {
                    CodeCompletionNamesOnlyInModuleAction.is_begin = false;
                    if (key != ' ')
                    {
                        ccw.ProcessKeyEvent(key);
                    }
                    else
                    {
                        ccw.ProcessKeyEvent('_');
                        ccw.Close();
                    }
                }
                else if (ccw != null && ccw.ProcessKeyEvent(key))
                {
                    return(true);
                }
            }
            if (key == '.')
            {
                if (CodeCompletion.CodeCompletionController.CurrentParser == null)
                {
                    return(false);
                }
                if (!string.IsNullOrEmpty(WorkbenchServiceFactory.DocumentService.CurrentCodeFileDocument.TextEditor.ActiveTextAreaControl.SelectionManager.SelectedText))
                {
                    WorkbenchServiceFactory.DocumentService.CurrentCodeFileDocument.TextEditor.ActiveTextAreaControl.Caret.Position = WorkbenchServiceFactory.DocumentService.CurrentCodeFileDocument.TextEditor.ActiveTextAreaControl.SelectionManager.SelectionCollection[0].StartPosition;
                    WorkbenchServiceFactory.DocumentService.CurrentCodeFileDocument.TextEditor.ActiveTextAreaControl.SelectionManager.RemoveSelectedText();
                }

                if (WorkbenchServiceFactory.Workbench.UserOptions.CodeCompletionDot)
                {
                    completionDataProvider = new CodeCompletionProvider();

                    codeCompletionWindow = PABCNETCodeCompletionWindow.ShowCompletionWindow(
                        VisualPABCSingleton.MainForm,   // The parent window for the completion window
                        editor,                         // The text editor to show the window for
                        editor.FileName,                // Filename - will be passed back to the provider
                        completionDataProvider,         // Provider to get the list of possible completions
                        key,                            // Key pressed - will be passed to the provider
                        true,
                        true,
                        PascalABCCompiler.Parsers.KeywordKind.None
                        );
                    CodeCompletionNamesOnlyInModuleAction.is_begin = true;
                    CodeCompletionNamesOnlyInModuleAction.comp_windows[editor.ActiveTextAreaControl.TextArea] = codeCompletionWindow;
                    if (codeCompletionWindow != null)
                    {
                        codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow);
                    }
                }
            }
            else if (key == '(' || key == '[' || key == ',')
            {
                if (CodeCompletion.CodeCompletionController.CurrentParser == null)
                {
                    return(false);
                }
                if (VisualPABCSingleton.MainForm.UserOptions.CodeCompletionParams)
                {
                    ICSharpCode.TextEditor.Gui.InsightWindow.IInsightDataProvider idp = new DefaultInsightDataProvider(-1, false, key);
                    if (insightWindow == null || insightWindow.InsightProviderStackLength == 0)
                    {
                        insightWindow         = new PABCNETInsightWindow(VisualPABCSingleton.MainForm, editor);
                        insightWindow.Font    = new Font(Constants.CompletionInsightWindowFontName, insightWindow.Font.Size);
                        insightWindow.Closed += new EventHandler(CloseInsightWindow);
                    }
                    else
                    {
                        (idp as DefaultInsightDataProvider).defaultIndex  = insightWindow.GetCurrentData();
                        (idp as DefaultInsightDataProvider).cur_param_num = (insightWindow.GetInsightProvider() as DefaultInsightDataProvider).param_count;
                    }
                    insightWindow.AddInsightDataProvider(idp, editor.FileName);
                    insightWindow.ShowInsightWindow();
                }
            }
            else if (key == ' ')
            {
                if (CodeCompletion.CodeCompletionController.CurrentParser == null)
                {
                    return(false);
                }
                if (VisualPABCSingleton.MainForm.UserOptions.CodeCompletionDot)
                {
                    PascalABCCompiler.Parsers.KeywordKind keyw = KeywordChecker.TestForKeyword(editor.Document.TextContent, editor.ActiveTextAreaControl.TextArea.Caret.Offset - 1);
                    if (keyw == PascalABCCompiler.Parsers.KeywordKind.New || keyw == PascalABCCompiler.Parsers.KeywordKind.Uses)
                    {
                        completionDataProvider = new CodeCompletionProvider();
                        codeCompletionWindow   = PABCNETCodeCompletionWindow.ShowCompletionWindow(
                            VisualPABCSingleton.MainForm, // The parent window for the completion window
                            editor,                       // The text editor to show the window for
                            editor.FileName,              // Filename - will be passed back to the provider
                            completionDataProvider,       // Provider to get the list of possible completions
                            ' ',                          // Key pressed - will be passed to the provider
                            true,
                            false,
                            keyw
                            );
                        CodeCompletionNamesOnlyInModuleAction.comp_windows[editor.ActiveTextAreaControl.TextArea] = codeCompletionWindow;
                        if (codeCompletionWindow != null)
                        {
                            codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow);
                        }
                        //return true;
                    }
                }
            }
            else if (key == '\n')
            {
                if (VisualPABCSingleton.MainForm.UserOptions.AllowCodeCompletion && CodeCompletion.CodeCompletionController.CurrentParser != null)
                {
                    try
                    {
                        CodeCompletion.DomConverter dconv = (CodeCompletion.DomConverter)CodeCompletion.CodeCompletionController.comp_modules[editor.FileName];
                        if (dconv != null)
                        {
                            CodeCompletion.SymScope ss = dconv.FindScopeByLocation(editor.ActiveTextAreaControl.TextArea.Caret.Line + 1, editor.ActiveTextAreaControl.TextArea.Caret.Column + 1);
                            ss.IncreaseEndLine();
                        }
                    }
                    catch
                    {
                    }
                }
            }
            else if (codeCompletionWindow == null && VisualPABCSingleton.MainForm.UserOptions.EnableSmartIntellisense && (char.IsLetter(key) || key == '_'))
            {
                if (VisualPABCSingleton.MainForm.UserOptions.CodeCompletionDot)
                {
                    if (CodeCompletion.CodeCompletionController.CurrentParser == null)
                    {
                        return(false);
                    }
                    PascalABCCompiler.Parsers.KeywordKind keyw = KeywordChecker.TestForKeyword(editor.Document.TextContent, editor.ActiveTextAreaControl.TextArea.Caret.Offset - 1);
                    if (CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.IsDefinitionIdentifierAfterKeyword(keyw))
                    {
                        return(false);
                    }

                    if (editor.ActiveTextAreaControl.TextArea.Caret.Offset > 0 && (char.IsLetterOrDigit(editor.Document.TextContent[editor.ActiveTextAreaControl.TextArea.Caret.Offset - 1]) || editor.Document.TextContent[editor.ActiveTextAreaControl.TextArea.Caret.Offset - 1] == '_'))
                    {
                        return(false);
                    }
                    completionDataProvider = new CodeCompletionProvider();
                    codeCompletionWindow   = PABCNETCodeCompletionWindow.ShowCompletionWindowWithFirstChar(
                        VisualPABCSingleton.MainForm,   // The parent window for the completion window
                        editor,                         // The text editor to show the window for
                        editor.FileName,                // Filename - will be passed back to the provider
                        completionDataProvider,         // Provider to get the list of possible completions
                        key,                            // Key pressed - will be passed to the provider
                        keyw
                        );
                    CodeCompletionNamesOnlyInModuleAction.comp_windows[editor.ActiveTextAreaControl.TextArea] = codeCompletionWindow;
                    if (codeCompletionWindow != null)
                    {
                        codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow);
                    }
                }
            }

            /*else if (codeCompletionWindow == null && key == '\n')
             * {
             *  if (mainForm.UserOptions.AllowCodeFormatting)
             *  {
             *          if (CodeCompletion.CodeCompletionController.currentParser == null) return false;
             *          string bracket = CodeCompletion.CodeCompletionController.currentParser.LanguageInformation.GetBodyStartBracket();
             *          string end_bracket = CodeCompletion.CodeCompletionController.currentParser.LanguageInformation.GetBodyEndBracket();
             *          if (bracket != null)
             *          {
             *                  int i = editor.ActiveTextAreaControl.TextArea.Caret.Offset-1;
             *                  int j = bracket.Length-1;
             *                  bool eq=true;
             *                  while (i >= 0 && j >= 0)
             *                  {
             *                          if (editor.Document.TextContent[i] != bracket[j])
             *                          {
             *                                  eq = false;
             *                                  break;
             *                          }
             *                          i--; j--;
             *                  }
             *                  if (eq && j<0)
             *                  {
             *                          TextArea textArea = editor.ActiveTextAreaControl.TextArea;
             *                          int col = textArea.Caret.Column-bracket.Length;
             *                                          textArea.InsertString("\n\n"+end_bracket);
             *                                          textArea.Caret.Column = 0;
             *                                          textArea.Caret.Line = textArea.Caret.Line-1;
             *                                          textArea.Caret.Column = VisualPABCSingleton.MainForm.UserOptions.CursorTabCount+col;
             *                                          return true;
             *                  }
             *          }
             *  }
             * }*/

            return(false);
        }
예제 #14
0
 internal void ParseInThread()
 {
     try
     {
         Hashtable open_files2  = (Hashtable)open_files.Clone();
         Hashtable recomp_files = new Hashtable(StringComparer.OrdinalIgnoreCase);
         bool      is_comp      = false;
         foreach (string FileName in open_files2.Keys)
         {
             //(ssyy) 18.05.08 Вставил проверку на null
             object o = open_files[FileName];
             if (o != null && (bool)o == true)
             {
                 is_comp = true;
                 CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController();
                 string text = visualEnvironmentCompiler.SourceFilesProvider(FileName, PascalABCCompiler.SourceFileOperation.GetText) as string;
                 if (string.IsNullOrEmpty(text))
                 {
                     text = "begin end.";
                 }
                 CodeCompletion.DomConverter tmp = CodeCompletion.CodeCompletionController.comp_modules[FileName] as CodeCompletion.DomConverter;
                 long cur_mem = Environment.WorkingSet;
                 CodeCompletion.DomConverter dc = controller.Compile(FileName, text);
                 mem_delta           += Environment.WorkingSet - cur_mem;
                 open_files[FileName] = false;
                 if (dc.is_compiled)
                 {
                     //CodeCompletion.CodeCompletionController.comp_modules.Remove(FileName);
                     if (tmp != null && tmp.visitor.entry_scope != null)
                     {
                         tmp.visitor.entry_scope.Clear();
                         if (tmp.visitor.cur_scope != null)
                         {
                             tmp.visitor.cur_scope.Clear();
                         }
                     }
                     CodeCompletion.CodeCompletionController.comp_modules[FileName] = dc;
                     recomp_files[FileName] = FileName;
                     open_files[FileName]   = false;
                     if (ParseInformationUpdated != null)
                     {
                         ParseInformationUpdated(dc.visitor.entry_scope, FileName);
                     }
                 }
                 else if (CodeCompletion.CodeCompletionController.comp_modules[FileName] == null)
                 {
                     CodeCompletion.CodeCompletionController.comp_modules[FileName] = dc;
                 }
             }
         }
         foreach (string FileName in open_files2.Keys)
         {
             CodeCompletion.DomConverter dc = CodeCompletion.CodeCompletionController.comp_modules[FileName] as CodeCompletion.DomConverter;
             CodeCompletion.SymScope     ss = null;
             if (dc != null)
             {
                 if (dc.visitor.entry_scope != null)
                 {
                     ss = dc.visitor.entry_scope;
                 }
                 else if (dc.visitor.impl_scope != null)
                 {
                     ss = dc.visitor.impl_scope;
                 }
                 int j = 0;
                 while (j < 2)
                 {
                     if (j == 0)
                     {
                         ss = dc.visitor.entry_scope;
                         j++;
                     }
                     else
                     {
                         ss = dc.visitor.impl_scope;
                         j++;
                     }
                     if (ss != null)
                     {
                         for (int i = 0; i < ss.used_units.Count; i++)
                         {
                             string s = ss.used_units[i].file_name;
                             if (s != null && open_files2.ContainsKey(s) && recomp_files.ContainsKey(s))
                             {
                                 is_comp = true;
                                 CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController();
                                 string text = visualEnvironmentCompiler.SourceFilesProvider(FileName, PascalABCCompiler.SourceFileOperation.GetText) as string;
                                 CodeCompletion.DomConverter tmp = CodeCompletion.CodeCompletionController.comp_modules[FileName] as CodeCompletion.DomConverter;
                                 long cur_mem = Environment.WorkingSet;
                                 dc                   = controller.Compile(FileName, text);
                                 mem_delta           += Environment.WorkingSet - cur_mem;
                                 open_files[FileName] = false;
                                 CodeCompletion.CodeCompletionController.comp_modules[FileName] = dc;
                                 if (dc.is_compiled)
                                 {
                                     /*if (tmp != null && tmp.stv.entry_scope != null)
                                      * {
                                      *  tmp.stv.entry_scope.Clear();
                                      *  if (tmp.stv.cur_scope != null) tmp.stv.cur_scope.Clear();
                                      * }*/
                                     CodeCompletion.CodeCompletionController.comp_modules[FileName] = dc;
                                     recomp_files[FileName] = FileName;
                                     ss.used_units[i]       = dc.visitor.entry_scope;
                                     if (ParseInformationUpdated != null)
                                     {
                                         ParseInformationUpdated(dc.visitor.entry_scope, FileName);
                                     }
                                 }
                                 else if (CodeCompletion.CodeCompletionController.comp_modules[FileName] == null)
                                 {
                                     CodeCompletion.CodeCompletionController.comp_modules[FileName] = dc;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (is_comp && mem_delta > 20000000 /*&& mem_delta > 10000000*/)
         //postavil delta dlja pamjati, posle kototoj delaetsja sborka musora
         {
             mem_delta = 0;
             GC.Collect();
         }
     }
     catch (Exception e)
     {
     }
 }