public Session(Controller controller, ModelComputation <Model> computation, ICompletionRules completionRules, ICompletionPresenterSession presenterSession) : base(controller, computation, presenterSession) { _completionRules = completionRules; this.PresenterSession.ItemCommitted += OnPresenterSessionItemCommitted; this.PresenterSession.ItemSelected += OnPresenterSessionItemSelected; }
private bool MatchesFilterText( CompletionItem item, string filterText, ICompletionRules completionRules, CompletionTriggerInfo triggerInfo, CompletionFilterReason reason) { return(completionRules.MatchesFilterText(item, filterText, triggerInfo, reason) ?? false); }
private bool IsBetterFilterMatch( CompletionItem item, CompletionItem bestItem, string filterText, ICompletionRules completionRules, CompletionTriggerInfo triggerInfo, CompletionFilterReason filterReason) { return(completionRules.IsBetterFilterMatch(item, bestItem, filterText, triggerInfo, filterReason) ?? false); }
private bool IsHardSelection( Model model, CompletionItem bestFilterMatch, ITextSnapshot textSnapshot, ICompletionRules completionRules, CompletionTriggerInfo triggerInfo, CompletionFilterReason reason) { if (model.Builder != null) { return(bestFilterMatch != null && bestFilterMatch.DisplayText == model.Builder.DisplayText); } if (bestFilterMatch == null || model.UseSuggestionCompletionMode) { return(false); } // We don't have a builder and we have a best match. Normally this will be hard // selected, except for a few cases. Specifically, if no filter text has been // provided, and this is not a preselect match then we will soft select it. This // happens when the completion list comes up implicitly and there is something in // the MRU list. In this case we do want to select it, but not with a hard // selection. Otherwise you can end up with the following problem: // // dim i as integer =<space> // // Completion will comes up after = with 'integer' selected (Because of MRU). We do // not want 'space' to commit this. var viewSpan = model.GetSubjectBufferFilterSpanInViewBuffer(bestFilterMatch.FilterSpan); var fullFilterText = model.GetCurrentTextInSnapshot(viewSpan, textSnapshot, endPoint: null); var shouldSoftSelect = completionRules.ShouldSoftSelectItem(GetExternallyUsableCompletionItem(bestFilterMatch), fullFilterText, triggerInfo); if (shouldSoftSelect == true) { return(false); } // If the user moved the caret left after they started typing, the 'best' match may not match at all // against the full text span that this item would be replacing. if (!MatchesFilterText(bestFilterMatch, fullFilterText, completionRules, triggerInfo, reason)) { return(false); } // There was either filter text, or this was a preselect match. In either case, we // can hard select this. return(true); }
private static void ReplaceExistingItem( CompletionItem item, Dictionary<string, List<CompletionItem>> displayNameToItemsMap, ICompletionRules completionRules) { // See if we have an item with var sameNamedItems = displayNameToItemsMap.GetOrAdd(item.DisplayText, s_createList); for (int i = 0; i < sameNamedItems.Count; i++) { var existingItem = sameNamedItems[i]; Contract.Assert(item.DisplayText == existingItem.DisplayText); if (completionRules.ItemsMatch(item, existingItem).Value) { sameNamedItems[i] = Disambiguate(item, existingItem); return; } } sameNamedItems.Add(item); }
private static CompletionList MergeAndPruneCompletionLists(IEnumerable<CompletionList> completionLists, ICompletionRules completionRules) { var displayNameToItemsMap = new Dictionary<string, List<CompletionItem>>(); CompletionItem builder = null; foreach (var completionList in completionLists) { Contract.Assert(completionList != null); foreach (var item in completionList.Items) { Contract.Assert(item != null); // New items that match an existing item will replace it. ReplaceExistingItem(item, displayNameToItemsMap, completionRules); } builder = builder ?? completionList.Builder; } if (displayNameToItemsMap.Count == 0) { return null; } // TODO(DustinCa): Revisit performance of this. var totalItems = displayNameToItemsMap.Values.Flatten().ToList(); totalItems.Sort(); // TODO(DustinCa): This is lossy -- we lose the IsExclusive field. Fix that. return new CompletionList(totalItems.ToImmutableArray(), builder); }
private bool MatchesFilterText( CompletionItem item, string filterText, ICompletionRules completionRules, CompletionTriggerInfo triggerInfo, CompletionFilterReason reason) { return completionRules.MatchesFilterText(item, filterText, triggerInfo, reason) ?? false; }
private bool IsBetterFilterMatch( CompletionItem item, CompletionItem bestItem, string filterText, ICompletionRules completionRules, CompletionTriggerInfo triggerInfo, CompletionFilterReason filterReason) { return completionRules.IsBetterFilterMatch(item, bestItem, filterText, triggerInfo, filterReason) ?? false; }
private bool IsHardSelection( Model model, CompletionItem bestFilterMatch, ITextSnapshot textSnapshot, ICompletionRules completionRules, CompletionTriggerInfo triggerInfo, CompletionFilterReason reason) { if (model.Builder != null) { return bestFilterMatch != null && bestFilterMatch.DisplayText == model.Builder.DisplayText; } if (bestFilterMatch == null || model.UseSuggestionCompletionMode) { return false; } // We don't have a builder and we have a best match. Normally this will be hard // selected, except for a few cases. Specifically, if no filter text has been // provided, and this is not a preselect match then we will soft select it. This // happens when the completion list comes up implicitly and there is something in // the MRU list. In this case we do want to select it, but not with a hard // selection. Otherwise you can end up with the following problem: // // dim i as integer =<space> // // Completion will comes up after = with 'integer' selected (Because of MRU). We do // not want 'space' to commit this. var viewSpan = model.GetSubjectBufferFilterSpanInViewBuffer(bestFilterMatch.FilterSpan); var fullFilterText = model.GetCurrentTextInSnapshot(viewSpan, textSnapshot, endPoint: null); var shouldSoftSelect = completionRules.ShouldSoftSelectItem(GetExternallyUsableCompletionItem(bestFilterMatch), fullFilterText, triggerInfo); if (shouldSoftSelect == true) { return false; } // If the user moved the caret left after they started typing, the 'best' match may not match at all // against the full text span that this item would be replacing. if (!MatchesFilterText(bestFilterMatch, fullFilterText, completionRules, triggerInfo, reason)) { return false; } // There was either filter text, or this was a preselect match. In either case, we // can hard select this. return true; }