AppKit.TextKit.Formatter.SourceTextViewDelegate.GetCompletions C# (CSharp) Method

GetCompletions() public method

Based on the user preferences set on the parent AppKit.TextKit.Formatter.SourceTextView, this method returns the available list of partial word completions.
public GetCompletions ( NSTextView textView, string words, NSRange charRange, nint &index ) : string[]
textView NSTextView The source .
words string A list of default words automatically provided by OS X in the user's language.
charRange NSRange The cursor location where the partial word exists.
index nint The word that should be selected when the list is displayed (usually 0 meaning /// the first item in the list). Pass -1 for no selected items.
return string[]
		public override string[] GetCompletions (NSTextView textView, string[] words, NSRange charRange, ref nint index)
		{
			List<string> completions = new List<string> ();

			// Is auto complete enabled?
			if (TextEditor.AllowAutoComplete) {
				// Use keywords in auto complete?
				if (TextEditor.AutoCompleteKeywords) {
					// Yes, grab word being expanded
					var range = TextEditor.Formatter.FindWordBoundries (TextEditor.TextStorage.Value, charRange);
					var word = TextEditor.TextStorage.Value.Substring ((int)range.Location, (int)range.Length);

					// Scan the keywords for the a possible match
					foreach (string keyword in TextEditor.Formatter.Language.Keywords.Keys) {
						// Found?
						if (keyword.Contains (word)) {
							completions.Add (keyword);
						}
					}
				}

				// Use default words?
				if (TextEditor.AutoCompleteDefaultWords) {
					// Only if keywords list is empty?
					if (TextEditor.DefaultWordsOnlyIfKeywordsEmpty) {
						if (completions.Count == 0) {
							// No keywords, add defaults
							completions.AddRange (words);
						}
					} else {
						// No, always include default words
						completions.AddRange (words);
					}
				}
			}

			// Return results
			return completions.ToArray();
		}