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();
}