public CodeCompletionParserController() { //this.visualEnvironmentCompiler = visualEnvironmentCompiler; this.th = new System.Threading.Thread(new System.Threading.ThreadStart(ParseInThread)); ccp = new CodeCompletionProvider(); //CodeCompletion.CodeCompletionController.OpenFiles = open_files; }
public static void RenameUnit(string FileName, string new_val) { if (CodeCompletion.CodeCompletionController.CurrentParser == null) return; ccp = new CodeCompletionProvider(); IDocument doc = null; CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController(); string text = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.SourceFilesProvider(FileName, PascalABCCompiler.SourceFileOperation.GetText) as string; PascalABCCompiler.SyntaxTree.compilation_unit cu = controller.ParseOnlySyntaxTree(FileName, text); PascalABCCompiler.SyntaxTree.ident unitName = null; if (cu is PascalABCCompiler.SyntaxTree.unit_module) { unitName = (cu as PascalABCCompiler.SyntaxTree.unit_module).unit_name.idunit_name; } else if (cu is PascalABCCompiler.SyntaxTree.program_module) { if ((cu as PascalABCCompiler.SyntaxTree.program_module).program_name == null) return; unitName = (cu as PascalABCCompiler.SyntaxTree.program_module).program_name.prog_name; } List<SymbolsViewerSymbol> refers = ccp.Rename(unitName.name, unitName.name, FileName, unitName.source_context.begin_position.line_num, unitName.source_context.begin_position.column_num); if (refers == null || new_val == null) return; int addit = 0; PascalABCCompiler.SourceLocation tmp = new PascalABCCompiler.SourceLocation(null, 0, 0, 0, 0); string file_name = null; VisualPABCSingleton.MainForm.StopTimer(); WorkbenchServiceFactory.CodeCompletionParserController.StopParseThread(); foreach (IFileInfo fi in ProjectFactory.Instance.CurrentProject.SourceFiles) { WorkbenchServiceFactory.CodeCompletionParserController.RegisterFileForParsing(fi.Path); } WorkbenchServiceFactory.CodeCompletionParserController.ParseInThread(); foreach (SymbolsViewerSymbol svs in refers) { if (svs.SourceLocation.BeginPosition.Line != tmp.BeginPosition.Line) addit = 0; else if (svs.SourceLocation.BeginPosition.Column < tmp.BeginPosition.Column) addit = 0; if (svs.SourceLocation.FileName != file_name) { CodeFileDocumentControl cfdoc = VisualPABCSingleton.MainForm.FindTab(svs.SourceLocation.FileName); if (cfdoc == null) continue; doc = cfdoc.TextEditor.ActiveTextAreaControl.TextArea.Document; file_name = svs.SourceLocation.FileName; } tmp = svs.SourceLocation; TextLocation tl_beg = new TextLocation(svs.SourceLocation.BeginPosition.Column - 1, svs.SourceLocation.BeginPosition.Line - 1); //TextLocation tl_end = new TextLocation(svs.SourceLocation.EndPosition.Line,svs.SourceLocation.EndPosition.Column); int offset = doc.PositionToOffset(tl_beg); //addit += new_val.Length - unitName.name.Length; doc.Replace(offset, unitName.name.Length, new_val); doc.CommitUpdate(); } WorkbenchServiceFactory.CodeCompletionParserController.RunParseThread(); VisualPABCSingleton.MainForm.StartTimer(); }
public static bool CanFindReferences(TextArea textArea) { try { if (CodeCompletion.CodeCompletionController.CurrentParser == null) { return(false); } ccp = new CodeCompletionProvider(); string full_expr; string expressionResult = FindFullExpression(textArea.Document.TextContent, textArea, out ccp.keyword, out full_expr); if (expressionResult != null) { expressionResult = expressionResult.Trim(' ', '\n', '\t', '\r'); return(expressionResult != null && expressionResult != ""); } return(expressionResult != null && expressionResult != ""); } catch (Exception e) { return(false); } }
public static void Rename(TextArea textArea) { if (CodeCompletion.CodeCompletionController.CurrentParser == null) return; IDocument doc = textArea.Document; string textContent = doc.TextContent; ccp = new CodeCompletionProvider(); string name = null; string expressionResult = FindOnlyIdent(textContent, textArea, ref name).Trim(' ', '\n', '\t', '\r'); string new_val = null; List<SymbolsViewerSymbol> refers = ccp.Rename(expressionResult, name, textArea.MotherTextEditorControl.FileName, textArea.Caret.Line, textArea.Caret.Column, ref new_val); if (refers == null || new_val == null) return; int addit = 0; PascalABCCompiler.SourceLocation tmp = new PascalABCCompiler.SourceLocation(null, 0, 0, 0, 0); string file_name = null; foreach (SymbolsViewerSymbol svs in refers) { if (svs.SourceLocation.BeginPosition.Line != tmp.BeginPosition.Line) addit = 0; else if (svs.SourceLocation.BeginPosition.Column < tmp.BeginPosition.Column) addit = 0; if (svs.SourceLocation.FileName != file_name) { CodeFileDocumentControl cfdoc = VisualPABCSingleton.MainForm.FindTab(svs.SourceLocation.FileName); if (cfdoc == null) continue; doc = cfdoc.TextEditor.ActiveTextAreaControl.TextArea.Document; file_name = svs.SourceLocation.FileName; } tmp = svs.SourceLocation; TextLocation tl_beg = new TextLocation(svs.SourceLocation.BeginPosition.Column - 1 + addit, svs.SourceLocation.BeginPosition.Line - 1); //TextLocation tl_end = new TextLocation(svs.SourceLocation.EndPosition.Line,svs.SourceLocation.EndPosition.Column); int offset = doc.PositionToOffset(tl_beg); addit += new_val.Length - name.Length; doc.Replace(offset, name.Length, new_val); doc.CommitUpdate(); } }
/// <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('_'); } else if (ccw != null && ccw.ProcessKeyEvent(key)) return true; } if (key == '.') { if (CodeCompletion.CodeCompletionController.CurrentParser == null) return false; 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 || VisualPABCSingleton.MainForm.UserOptions.EnableSmartIntellisense && 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; }
/// <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); }
public CodeCompletionParserController() { this.th = new System.Threading.Thread(new System.Threading.ThreadStart(ParseInThread)); ccp = new CodeCompletionProvider(); }
public static List<SymbolsViewerSymbol> FindReferences(TextArea textArea) { if (CodeCompletion.CodeCompletionController.CurrentParser == null) return new List<SymbolsViewerSymbol>(); ccp = new CodeCompletionProvider(); string full_expr; string expressionResult = FindFullExpression(textArea.Document.TextContent, textArea, out ccp.keyword, out full_expr); return ccp.FindReferences(expressionResult, textArea.MotherTextEditorControl.FileName, textArea.Caret.Line, textArea.Caret.Column, false); }
public override void Execute(TextArea _textArea) { //try { textArea = _textArea; int off = textArea.Caret.Offset; string text = textArea.Document.TextContent.Substring(0, textArea.Caret.Offset); if (key == '\0') { if (off > 2 && text[off - 1] == '/' && text[off - 2] == '/' && text[off - 3] == '/') { CodeCompletionActionsManager.GenerateCommentTemplate(textArea); return; } else { string prev = get_prev_text(text, off - 1); if (!string.IsNullOrEmpty(prev)) { CodeCompletionActionsManager.GenerateTemplate(prev, textArea); return; } } } if (!WorkbenchServiceFactory.Workbench.UserOptions.CodeCompletionDot) { return; } if (CodeCompletion.CodeCompletionController.CurrentParser == null) { return; } CodeCompletionProvider completionDataProvider = new CodeCompletionProvider(); bool is_pattern = false; is_begin = true; completionDataProvider.preSelection = CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.FindPattern(off, text, out is_pattern); if (!is_pattern && off > 0 && text[off - 1] == '.') { key = '$'; } codeCompletionWindow = PABCNETCodeCompletionWindow.ShowCompletionWindow( VisualPABCSingleton.MainForm, // The parent window for the completion window textArea.MotherTextEditorControl, // The text editor to show the window for textArea.MotherTextEditorControl.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 false, false, PascalABCCompiler.Parsers.KeywordKind.None ); key = '_'; CodeCompletionNamesOnlyInModuleAction.comp_windows[textArea] = codeCompletionWindow; if (codeCompletionWindow != null) { // ShowCompletionWindow can return null when the provider returns an empty list codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow); } } //catch (Exception e) { } }
public static void GenerateClassOrMethodRealization(TextArea textArea) { if (CodeCompletion.CodeCompletionController.CurrentParser == null) return; ccp = new CodeCompletionProvider(); Position pos = new Position(); //string text = "procedure Test(a : integer);\n begin \n x := 1; \n end;";//ccp.GetRealizationTextToAdd(out pos); string text = ccp.GetRealizationTextToAdd(textArea.MotherTextEditorControl.FileName, textArea.Caret.Line, textArea.Caret.Column, ref pos, textArea); if (text != null && pos.file_name != null) { textArea.Caret.Line = pos.line - 1; textArea.Caret.Column = pos.column - 1; textArea.InsertString(text); textArea.Caret.Line = pos.line + 4 - 1; textArea.Caret.Column = VisualPABCSingleton.MainForm.UserOptions.CursorTabCount + 1; } }
public static void GenerateOverridableMethods(TextArea textArea) { if (CodeCompletion.CodeCompletionController.CurrentParser == null) return; ccp = new CodeCompletionProvider(); _textArea = textArea; int off = textArea.Caret.Offset; codeCompletionWindow = PABCNETCodeCompletionWindow.ShowOverridableMethodsCompletionWindows (VisualPABCSingleton.MainForm, textArea.MotherTextEditorControl, textArea.MotherTextEditorControl.FileName, ccp); CodeCompletionAllNamesAction.comp_windows[textArea] = codeCompletionWindow; if (codeCompletionWindow != null) { // ShowCompletionWindow can return null when the provider returns an empty list codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow); } }
public static void GenerateMethodImplementationHeaders(TextArea textArea) { try { if (CodeCompletion.CodeCompletionController.CurrentParser == null) return; ccp = new CodeCompletionProvider(); Position pos = new Position(); //string text = "procedure Test(a : integer);\n begin \n x := 1; \n end;";//ccp.GetRealizationTextToAdd(out pos); string text = ccp.GetMethodImplementationTextToAdd(textArea.MotherTextEditorControl.FileName, textArea.Caret.Line, textArea.Caret.Column, ref pos, textArea); if (!string.IsNullOrEmpty(text) && pos.file_name != null) { textArea.Caret.Line = pos.line - 1; textArea.Caret.Column = 0; textArea.InsertString(text); textArea.Caret.Line = pos.line - 1; textArea.Caret.Column = 0; } } catch (System.Exception e) { } }
public static bool CanGenerateRealization(TextArea textArea) { try { if (CodeCompletion.CodeCompletionController.CurrentParser == null) return false; ccp = new CodeCompletionProvider(); Position pos = new Position(); //string text = "procedure Test(a : integer);\n begin \n x := 1; \n end;";//ccp.GetRealizationTextToAdd(out pos); string text = ccp.GetRealizationTextToAdd(textArea.MotherTextEditorControl.FileName, textArea.Caret.Line, textArea.Caret.Column, ref pos, textArea); return text != null && pos.file_name != null; } catch (Exception e) { return false; } }
public static bool CanFindReferences(TextArea textArea) { try { if (CodeCompletion.CodeCompletionController.CurrentParser == null) return false; ccp = new CodeCompletionProvider(); string full_expr; string expressionResult = FindFullExpression(textArea.Document.TextContent, textArea, out ccp.keyword, out full_expr); if (expressionResult != null) { expressionResult = expressionResult.Trim(' ', '\n', '\t', '\r'); return expressionResult != null && expressionResult != ""; } return expressionResult != null && expressionResult != ""; } catch (Exception e) { return false; } }
public static bool GenerateCommentTemplate(TextArea textArea) { if (CodeCompletion.CodeCompletionController.CurrentParser == null) return false; ccp = new CodeCompletionProvider(); //if (!should_insert_comment(textArea)) // return false; string lineText = get_next_line(textArea); string addit = CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.GetDocumentTemplate( lineText, textArea.Document.TextContent, textArea.Caret.Line, textArea.Caret.Column, textArea.Caret.Offset); if (addit == null) return false; int col = textArea.Caret.Column; int line = textArea.Caret.Line; int len; string desc = get_possible_description(textArea, out len); StringBuilder sb = new StringBuilder(); sb.AppendLine(" <summary>"); for (int i = 0; i < col - 3; i++) sb.Append(' '); sb.Append("/// "); if (desc != null) sb.Append(desc); sb.AppendLine(); for (int i = 0; i < col - 3; i++) sb.Append(' '); sb.Append("/// </summary>"); if (addit != "") { sb.Append(addit); } if (desc == null) textArea.InsertString(sb.ToString()); else { IDocument doc = textArea.Document; TextLocation tl_beg = new TextLocation(col, line); //TextLocation tl_end = new TextLocation(svs.SourceLocation.EndPosition.Line,svs.SourceLocation.EndPosition.Column); int offset = doc.PositionToOffset(tl_beg); doc.Replace(offset, len, ""); doc.CommitUpdate(); textArea.InsertString(sb.ToString()); } textArea.Caret.Line = line + 1; textArea.Caret.Column = col + 1; return true; }
public static bool GenerateCommentTemplate(TextArea textArea) { if (CodeCompletion.CodeCompletionController.CurrentParser == null) { return(false); } ccp = new CodeCompletionProvider(); //if (!should_insert_comment(textArea)) // return false; string lineText = get_next_line(textArea); string addit = CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.GetDocumentTemplate( lineText, textArea.Document.TextContent, textArea.Caret.Line, textArea.Caret.Column, textArea.Caret.Offset); if (addit == null) { return(false); } int col = textArea.Caret.Column; int line = textArea.Caret.Line; int len; string desc = get_possible_description(textArea, out len); StringBuilder sb = new StringBuilder(); sb.AppendLine(" <summary>"); for (int i = 0; i < col - 3; i++) { sb.Append(' '); } sb.Append("/// "); if (desc != null) { sb.Append(desc); } sb.AppendLine(); for (int i = 0; i < col - 3; i++) { sb.Append(' '); } sb.Append("/// </summary>"); if (addit != "") { sb.Append(addit); } if (desc == null) { textArea.InsertString(sb.ToString()); } else { IDocument doc = textArea.Document; TextLocation tl_beg = new TextLocation(col, line); //TextLocation tl_end = new TextLocation(svs.SourceLocation.EndPosition.Line,svs.SourceLocation.EndPosition.Column); int offset = doc.PositionToOffset(tl_beg); doc.Replace(offset, len, ""); doc.CommitUpdate(); textArea.InsertString(sb.ToString()); } textArea.Caret.Line = line + 1; textArea.Caret.Column = col + 1; return(true); }
public override void Execute(TextArea _textArea) { //try { textArea = _textArea; int off = textArea.Caret.Offset; string text = textArea.Document.TextContent.Substring(0, textArea.Caret.Offset); if (key == '\0') if (off > 2 && text[off - 1] == '/' && text[off - 2] == '/' && text[off - 3] == '/') { CodeCompletionActionsManager.GenerateCommentTemplate(textArea); return; } else { string prev = get_prev_text(text, off - 1); if (!string.IsNullOrEmpty(prev)) { CodeCompletionActionsManager.GenerateTemplate(prev, textArea); return; } } if (!WorkbenchServiceFactory.Workbench.UserOptions.CodeCompletionDot) return; if (CodeCompletion.CodeCompletionController.CurrentParser == null) return; CodeCompletionProvider completionDataProvider = new CodeCompletionProvider(); bool is_pattern = false; is_begin = true; completionDataProvider.preSelection = CodeCompletion.CodeCompletionController.CurrentParser.LanguageInformation.FindPattern(off, text, out is_pattern); if (!is_pattern && off > 0 && text[off - 1] == '.') key = '$'; codeCompletionWindow = PABCNETCodeCompletionWindow.ShowCompletionWindow( VisualPABCSingleton.MainForm, // The parent window for the completion window textArea.MotherTextEditorControl, // The text editor to show the window for textArea.MotherTextEditorControl.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 false, false, PascalABCCompiler.Parsers.KeywordKind.None ); key = '_'; CodeCompletionNamesOnlyInModuleAction.comp_windows[textArea] = codeCompletionWindow; if (codeCompletionWindow != null) { // ShowCompletionWindow can return null when the provider returns an empty list codeCompletionWindow.Closed += new EventHandler(CloseCodeCompletionWindow); } } //catch (Exception e) { } }
public static void RenameUnit(string FileName, string new_val) { if (CodeCompletion.CodeCompletionController.CurrentParser == null) { return; } ccp = new CodeCompletionProvider(); IDocument doc = null; CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController(); string text = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.SourceFilesProvider(FileName, PascalABCCompiler.SourceFileOperation.GetText) as string; PascalABCCompiler.SyntaxTree.compilation_unit cu = controller.ParseOnlySyntaxTree(FileName, text); PascalABCCompiler.SyntaxTree.ident unitName = null; if (cu is PascalABCCompiler.SyntaxTree.unit_module) { unitName = (cu as PascalABCCompiler.SyntaxTree.unit_module).unit_name.idunit_name; } else if (cu is PascalABCCompiler.SyntaxTree.program_module) { if ((cu as PascalABCCompiler.SyntaxTree.program_module).program_name == null) { return; } unitName = (cu as PascalABCCompiler.SyntaxTree.program_module).program_name.prog_name; } List <SymbolsViewerSymbol> refers = ccp.Rename(unitName.name, unitName.name, FileName, unitName.source_context.begin_position.line_num, unitName.source_context.begin_position.column_num); if (refers == null || new_val == null) { return; } int addit = 0; PascalABCCompiler.SourceLocation tmp = new PascalABCCompiler.SourceLocation(null, 0, 0, 0, 0); string file_name = null; VisualPABCSingleton.MainForm.StopTimer(); WorkbenchServiceFactory.CodeCompletionParserController.StopParseThread(); foreach (IFileInfo fi in ProjectFactory.Instance.CurrentProject.SourceFiles) { WorkbenchServiceFactory.CodeCompletionParserController.RegisterFileForParsing(fi.Path); } WorkbenchServiceFactory.CodeCompletionParserController.ParseInThread(); foreach (SymbolsViewerSymbol svs in refers) { if (svs.SourceLocation.BeginPosition.Line != tmp.BeginPosition.Line) { addit = 0; } else if (svs.SourceLocation.BeginPosition.Column < tmp.BeginPosition.Column) { addit = 0; } if (svs.SourceLocation.FileName != file_name) { CodeFileDocumentControl cfdoc = VisualPABCSingleton.MainForm.FindTab(svs.SourceLocation.FileName); if (cfdoc == null) { continue; } doc = cfdoc.TextEditor.ActiveTextAreaControl.TextArea.Document; file_name = svs.SourceLocation.FileName; } tmp = svs.SourceLocation; TextLocation tl_beg = new TextLocation(svs.SourceLocation.BeginPosition.Column - 1, svs.SourceLocation.BeginPosition.Line - 1); //TextLocation tl_end = new TextLocation(svs.SourceLocation.EndPosition.Line,svs.SourceLocation.EndPosition.Column); int offset = doc.PositionToOffset(tl_beg); //addit += new_val.Length - unitName.name.Length; doc.Replace(offset, unitName.name.Length, new_val); doc.CommitUpdate(); } WorkbenchServiceFactory.CodeCompletionParserController.RunParseThread(); VisualPABCSingleton.MainForm.StartTimer(); }
public static List<Position> GetRealizationPosition(TextArea textArea) { if (CodeCompletion.CodeCompletionController.CurrentParser == null) return new List<Position>(); IDocument doc = textArea.Document; string textContent = doc.TextContent; ccp = new CodeCompletionProvider(); string full_expr; string expressionResult = FindFullExpression(textContent, textArea, out ccp.keyword, out full_expr); List<Position> poses = ccp.GetRealization(full_expr, textArea.MotherTextEditorControl.FileName, textArea.Caret.Line, textArea.Caret.Column); if (poses == null) poses = ccp.GetRealization(expressionResult, textArea.MotherTextEditorControl.FileName, textArea.Caret.Line, textArea.Caret.Column); return poses; }