/// <summary> /// Find a list of items in the completion and return it /// Uses the position to filter the list the same way the autocompletion form would /// </summary> /// <returns></returns> public static List <CompletionItem> FindInCompletionData(string keyword, int position, bool dontCheckLine = false) { var filteredList = AutoCompletionForm.ExternalFilterItems(SavedAllItems.ToList(), Npp.LineFromPosition(position), dontCheckLine); if (filteredList == null || filteredList.Count <= 0) { return(null); } var found = filteredList.Where(data => data.DisplayText.EqualsCi(keyword)).ToList(); if (found.Count > 0) { return(found); } // search in tables fields var tableFound = ParserHandler.FindAnyTableOrBufferByName(Npp.GetFirstWordRightAfterPoint(position)); if (tableFound == null) { return(null); } var listOfFields = DataBase.GetFieldsList(tableFound).ToList(); return(listOfFields.Where(data => data.DisplayText.EqualsCi(keyword)).ToList()); }
/// <summary> /// Updates the CURRENT ITEMS LIST, /// handles the opening or the closing of the autocompletion form on key input, /// it is only called when the user adds or delete a char /// </summary> public static void UpdateAutocompletion() { if (!Config.Instance.AutoCompleteOnKeyInputShowSuggestions && !_openedFromShortCut) { return; } // dont show in string/comments..? if (!_openedFromShortCut && !IsVisible && !Config.Instance.AutoCompleteShowInCommentsAndStrings && !Style.IsCarretInNormalContext(Npp.CurrentPosition)) { return; } // get current word, current previous word (table or database name) int nbPoints; string previousWord = ""; var strOnLeft = Npp.GetTextOnLeftOfPos(Npp.CurrentPosition); var keyword = Abl.ReadAblWord(strOnLeft, false, out nbPoints); var splitted = keyword.Split('.'); string lastCharBeforeWord = ""; switch (nbPoints) { case 0: int startPos = strOnLeft.Length - 1 - keyword.Length; lastCharBeforeWord = startPos >= 0 ? strOnLeft.Substring(startPos, 1) : String.Empty; break; case 1: previousWord = splitted[0]; keyword = splitted[1]; break; case 2: previousWord = splitted[1]; keyword = splitted[2]; break; default: keyword = splitted[nbPoints]; break; } // list of fields or tables if (!string.IsNullOrEmpty(previousWord)) { // are we entering a field from a known table? var foundTable = ParserHandler.FindAnyTableOrBufferByName(previousWord); if (foundTable != null) { if (CurrentTypeOfList != TypeOfList.Fields) { CurrentTypeOfList = TypeOfList.Fields; SetCurrentItems(DataBase.GetFieldsList(foundTable).ToList()); } ShowSuggestionList(keyword); return; } // are we entering a table from a connected database? var foundDatabase = DataBase.FindDatabaseByName(previousWord); if (foundDatabase != null) { if (CurrentTypeOfList != TypeOfList.Tables) { CurrentTypeOfList = TypeOfList.Tables; SetCurrentItems(DataBase.GetTablesList(foundDatabase).ToList()); } ShowSuggestionList(keyword); return; } } // close if there is nothing to suggest if ((!_openedFromShortCut || _openedFromShortCutPosition != Npp.CurrentPosition) && (String.IsNullOrEmpty(keyword) || keyword != null && keyword.Length < Config.Instance.AutoCompleteStartShowingListAfterXChar)) { Close(); return; } // if the current is directly preceded by a :, we are entering an object field/method if (lastCharBeforeWord.Equals(":")) { if (CurrentTypeOfList != TypeOfList.KeywordObject) { CurrentTypeOfList = TypeOfList.KeywordObject; SetCurrentItems(SavedAllItems); } ShowSuggestionList(keyword); return; } // show normal complete list if (CurrentTypeOfList != TypeOfList.Complete) { CurrentTypeOfList = TypeOfList.Complete; SetCurrentItems(SavedAllItems); } ShowSuggestionList(keyword); }