private static void ImportKeywords(ConfLine conf) { Keywords.Import(); // Update autocompletion AutoComplete.RefreshStaticItems(); ParserHandler.ParseCurrentDocument(); }
/// <summary> /// Called from CTRL + Space shortcut /// </summary> public static void OnShowCompleteSuggestionList() { ParserHandler.ParseCurrentDocument(); _openedFromShortCut = true; _openedFromShortCutPosition = Npp.CurrentPosition; UpdateAutocompletion(); }
/// <summary> /// Gets the list of functions/proto of interest /// </summary> private static int GetPrototypesLists(out List <ParsedImplementation> listOfOutDatedProto, out List <ParsedImplementation> listOfSoloImplementation, out List <ParsedPrototype> listOfUselessProto) { // make sure to parse the current document before checking anything ParserHandler.ParseCurrentDocument(true, true); // list the outdated proto listOfOutDatedProto = ParserHandler.AblParser.ParsedItemsList.Where(item => { var funcItem = item as ParsedImplementation; return(funcItem != null && funcItem.HasPrototype && !funcItem.PrototypeUpdated); }).Select(item => (ParsedImplementation)item).ToList(); // list the implementation w/o prototypes listOfSoloImplementation = ParserHandler.AblParser.ParsedItemsList.Where(item => { var funcItem = item as ParsedImplementation; return(funcItem != null && !funcItem.HasPrototype); }).Select(item => (ParsedImplementation)item).ToList(); // list the prototypes w/o implementation listOfUselessProto = ParserHandler.AblParser.ParsedPrototypes.Where(item => { // it's a prototype with no implementation var proto = item.Value as ParsedPrototype; return(proto != null && proto.SimpleForward && !ParserHandler.AblParser.ParsedItemsList.Exists(func => func is ParsedImplementation && func.Name.EqualsCi(item.Value.Name))); }).Select(item => (ParsedPrototype)item.Value).ToList(); return(listOfOutDatedProto.Count + listOfSoloImplementation.Count + listOfUselessProto.Count); }
/// <summary> /// this method should be called at the plugin's start and when we change the current database /// It refreshed the "static" items of the autocompletion : keywords, snippets, databases, tables, sequences /// </summary> public static void RefreshStaticItems() { if (_itemsListLock.TryEnterWriteLock(-1)) { try { _staticItems.Clear(); _staticItems = Keywords.GetList().ToList(); _staticItems.AddRange(Snippets.Keys.Select(x => new CompletionItem { DisplayText = x, Type = CompletionType.Snippet, Ranking = 0, FromParser = false, Flag = 0 }).ToList()); _staticItems.AddRange(DataBase.GetDbList()); _staticItems.AddRange(DataBase.GetSequencesList()); _staticItems.AddRange(DataBase.GetTablesList()); // we do the sorting (by type and then by ranking), doing it now will reduce the time for the next sort() _staticItems.Sort(new CompletionDataSortingClass()); } finally { _itemsListLock.ExitWriteLock(); } } // update parser? if (_initialized) { ParserHandler.ParseCurrentDocument(); } _initialized = true; // OnUpdatedStaticItems if (OnUpdatedStaticItems != null) { OnUpdatedStaticItems(); } // refresh the list of all the saved items (static + dynamic) RefreshDynamicItems(); }
public static void OnSciModified(SCNotification nc) { bool deletedText = (nc.modificationType & (int)SciMsg.SC_MOD_DELETETEXT) != 0; // if the text has changed if (deletedText || (nc.modificationType & (int)SciMsg.SC_MOD_INSERTTEXT) != 0) { // observe modifications to lines (MANDATORY) Npp.UpdateLinesInfo(nc, !deletedText); // parse ParserHandler.ParseCurrentDocument(); } // did the user supress 1 char? if (deletedText && nc.length == 1) { AutoComplete.UpdateAutocompletion(); } }
public static void DeleteCode <T>() where T : ParsedScopeItem { // make sure to parse the current document before doing anything ParserHandler.ParseCurrentDocument(true, true); // make a list of existing items for this type var existingList = ParserHandler.AblParser.ParsedItemsList.Where(item => item.GetType() == typeof(T)).Cast <T>().ToList(); object nameToDelete = new ProCodeDelete { Value = string.Join("|", existingList.Select(arg => arg.Name)) }; if (string.IsNullOrEmpty(((ProCodeDelete)nameToDelete).Value)) { UserCommunication.Notify("Sorry, there was nothing to do!", MessageImg.MsgInfo, "Delete code", "Nothing to delete!", 5); return; } if (UserCommunication.Input(ref nameToDelete, "Please select which piece of code should be deleted", MessageImg.MsgQuestion, "Delete code", "Select the item to delete") != 0) { return; } var delete = (ProCodeDelete)nameToDelete; if (string.IsNullOrEmpty(delete.Value)) { return; } var toDelete = existingList.FirstOrDefault(item => item.Name.Equals(delete.Value)); if (toDelete != null) { DeleteCode(toDelete); } }
/// <summary> /// Call this method to insert a new piece of code /// </summary> public static void InsertCode <T>() where T : ParsedScopeItem { IProCode codeCode; string insertText; string blockDescription; // in case of an incorrect document, warn the user if (ParserHandler.AblParser.ParserErrors.Count > 0) { if (UserCommunication.Message("The internal parser of 3P has found inconsistencies in your document :<br>" + ProCodeFormat.GetParserErrorDescription() + "<br>You can still insert a new piece of code but the insertion position might not be calculated correctly; take caution of what is generated if you decide to go through with it.", MessageImg.MsgQuestion, "Generate code", "Problems spotted", new List <string> { "Continue", "Abort" }) != 0) { return; } } if (typeof(ParsedImplementation) == typeof(T)) { object input = new ProCodeFunction(); if (UserCommunication.Input(ref input, "Please provide information about the procedure that will be created", MessageImg.MsgQuestion, "Generate code", "Insert a new function") != 0) { return; } codeCode = (IProCode)input; blockDescription = @"_FUNCTION " + codeCode.Name + " Procedure"; insertText = Encoding.Default.GetString(DataResources.FunctionImplementation).Trim(); insertText = insertText.Replace("{&type}", ((ProCodeFunction)codeCode).Type); insertText = insertText.Replace("{&private}", ((ProCodeFunction)codeCode).IsPrivate ? " PRIVATE" : ""); } else if (typeof(ParsedProcedure) == typeof(T)) { object input = new ProCodeProcedure(); if (UserCommunication.Input(ref input, "Please provide information about the procedure that will be created", MessageImg.MsgQuestion, "Generate code", "Insert a new procedure") != 0) { return; } codeCode = (IProCode)input; blockDescription = @"_PROCEDURE " + codeCode.Name + " Procedure"; insertText = Encoding.Default.GetString(DataResources.InternalProcedure).Trim(); insertText = insertText.Replace("{&private}", ((ProCodeProcedure)codeCode).IsPrivate ? " PRIVATE" : ""); } else { return; } if (string.IsNullOrEmpty(codeCode.Name)) { return; } // make sure to parse the current document before checking anything ParserHandler.ParseCurrentDocument(true, true); // check if the code already exists if (ParserHandler.AblParser.ParsedItemsList.Exists(item => item.GetType() == typeof(T) && item.Name.EqualsCi(codeCode.Name))) { UserCommunication.Notify("Sorry, this name is already taken by another existing instance", MessageImg.MsgHighImportance, "Invalid name", "Existing name", 5); return; } insertText = insertText.Replace("{&name}", codeCode.Name); // reposition caret and insert bool insertBefore; int insertPos = GetCaretPositionForInsertion <T>(codeCode.Name, codeCode.InsertPosition, out insertBefore); if (insertPos < 0) { insertPos = Npp.GetPosFromLineColumn(Npp.Line.CurrentLine, 0); } insertText = FormatInsertion(insertText, blockDescription, insertBefore); int internalCaretPos = insertText.IndexOf("|||", StringComparison.Ordinal); insertText = insertText.Replace("|||", ""); Npp.SetSelection(insertPos); Npp.ModifyTextAroundCaret(0, 0, insertText); Npp.GoToLine(Npp.LineFromPosition(insertPos)); Npp.GotoPosition(insertPos + (internalCaretPos > 0 ? internalCaretPos : 0)); // in the case of a new function, create the prototype if needed if (typeof(ParsedImplementation) == typeof(T)) { UpdateFunctionPrototypesIfNeeded(true); } }
public static void DoNppDocumentSwitched(bool initiating = false) { // update current file info IsPreviousFileProgress = IsCurrentFileProgress; IsCurrentFileProgress = Abl.IsCurrentProgressFile; CurrentFilePath = Npp.GetCurrentFilePath(); CurrentFileObject = FilesInfo.GetFileInfo(CurrentFilePath); // accept advanced notifications only if the current file is a progress file CurrentFileAllowed = IsCurrentFileProgress; // update current scintilla Npp.UpdateScintilla(); // Apply options to npp and scintilla depending if we are on a progress file or not ApplyOptionsForScintilla(); // close popups.. ClosePopups(); // Update info on the current file FilesInfo.UpdateErrorsInScintilla(); // refresh file explorer currently opened file FileExplorer.RedrawFileExplorerList(); if (!initiating) { if (Config.Instance.CodeExplorerAutoHideOnNonProgressFile) { CodeExplorer.Toggle(IsCurrentFileProgress); } if (Config.Instance.FileExplorerAutoHideOnNonProgressFile) { FileExplorer.Toggle(IsCurrentFileProgress); } } else { // make sure to use the ProEnvironment and colorize the error counter FilesInfo.UpdateFileStatus(); ProEnvironment.Current.ReComputeProPath(); } if (IsCurrentFileProgress) { // Need to compute the propath again, because we take into account relative path ProEnvironment.Current.ReComputeProPath(); // rebuild lines info (MANDATORY) Npp.RebuildLinesInfo(); } // Parse the document ParserHandler.ParseCurrentDocument(true); // publish the event if (OnDocumentChangedEnd != null) { OnDocumentChangedEnd(); } }