public static void BindMember(ICompletionData item)
 {
     if (cur_sc != null && item != null)
     {
         ht[cur_sc.GetFullName()] = item.Text;
     }
     cur_sc = null;
 }
 	public static void BindMember(ICompletionData item)
 	{
 		if (cur_sc != null && item != null)
 			ht[cur_sc.GetFullName()] = item.Text;
 		cur_sc = null;
 	}
 	public static void AddMemberBeforeDot(CodeCompletion.SymScope sc)
 	{
 		cur_sc = sc;
 	}
        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 static string GetRecentUsedMember(CodeCompletion.SymScope sc)
 {
     return(ht[sc.GetFullName()] as string);
 }
 public static void AddMemberBeforeDot(CodeCompletion.SymScope sc)
 {
     cur_sc = sc;
 }
Пример #7
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);
        }
Пример #8
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)
     {
     }
 }