protected bool ProvideContextCompletion(ITextEditor editor, IReturnType expected, char charTyped) { if (expected == null) return false; IClass c = expected.GetUnderlyingClass(); if (c == null) return false; if (c.ClassType == ClassType.Enum) { CtrlSpaceCompletionItemProvider cdp = new NRefactoryCtrlSpaceCompletionItemProvider(languageProperties); var ctrlSpaceList = cdp.GenerateCompletionList(editor); if (ctrlSpaceList == null) return false; ContextCompletionItemList contextList = new ContextCompletionItemList(); contextList.Items.AddRange(ctrlSpaceList.Items); contextList.activationKey = charTyped; foreach (CodeCompletionItem item in contextList.Items.OfType<CodeCompletionItem>()) { IClass itemClass = item.Entity as IClass; if (itemClass != null && c.FullyQualifiedName == itemClass.FullyQualifiedName && c.TypeParameters.Count == itemClass.TypeParameters.Count) { contextList.SuggestedItem = item; break; } } if (contextList.SuggestedItem != null) { if (charTyped != ' ') contextList.InsertSpace = true; editor.ShowCompletionWindow(contextList); return true; } } return false; }
// TODO : remove this code duplication! // see NRefactoryCodeCompletionBinding bool ProvideContextCompletion(ITextEditor editor, IReturnType expected, char charTyped) { if (expected == null) { return(false); } IClass c = expected.GetUnderlyingClass(); if (c == null) { return(false); } if (c.ClassType == ClassType.Enum) { CtrlSpaceCompletionItemProvider cdp = new NRefactoryCtrlSpaceCompletionItemProvider(languageProperties); var ctrlSpaceList = cdp.GenerateCompletionList(editor); if (ctrlSpaceList == null) { return(false); } ContextCompletionItemList contextList = new ContextCompletionItemList(); contextList.Items.AddRange(ctrlSpaceList.Items); contextList.activationKey = charTyped; foreach (CodeCompletionItem item in contextList.Items.OfType <CodeCompletionItem>()) { IClass itemClass = item.Entity as IClass; if (itemClass != null && c.FullyQualifiedName == itemClass.FullyQualifiedName && c.TypeParameters.Count == itemClass.TypeParameters.Count) { contextList.SuggestedItem = item; break; } } if (contextList.SuggestedItem != null) { if (charTyped != ' ') { contextList.InsertSpace = true; } editor.ShowCompletionWindow(contextList); return(true); } } return(false); }