public override void SelectBestMatch()
        {
            ITextSnapshot snapshot  = ApplicableTo.TextBuffer.CurrentSnapshot;
            string        typedText = ApplicableTo.GetText(snapshot).Trim();

            if (string.IsNullOrWhiteSpace(typedText))
            {
                if (_filteredCompletions.Any())
                {
                    SelectionStatus = new CompletionSelectionStatus(_filteredCompletions.First(), true, true);
                }

                return;
            }

            foreach (Completion comp in _filteredCompletions)
            {
                int index = comp.DisplayText.IndexOf(typedText, StringComparison.OrdinalIgnoreCase);

                if (index == 0)
                {
                    SelectionStatus = new CompletionSelectionStatus(comp, true, true);
                    return;
                }
                else if (index > -1)
                {
                    SelectionStatus = new CompletionSelectionStatus(comp, true, true);
                    return;
                }
            }
        }
예제 #2
0
        public override void SelectBestMatch()
        {
            var text = ApplicableTo.GetText(ApplicableTo.TextBuffer.CurrentSnapshot);
            if (string.IsNullOrWhiteSpace(text))
            {
                SelectionStatus = new CompletionSelectionStatus(null, false, false);
                return;
            }

            Microsoft.VisualStudio.Language.Intellisense.Completion bestMatch = null;
            var bestValue = 0;
            var isUnique = true;
            foreach (var completion in Completions)
            {
                int value = CompareCompletionText(completion.DisplayText, text);
                if (bestMatch == null || value > bestValue)
                {
                    bestMatch = completion;
                    bestValue = value;
                    isUnique = true;
                }
                else if (value == bestValue)
                {
                    isUnique = false;
                }
            }

            SelectionStatus = new CompletionSelectionStatus(bestMatch, bestValue > 0, isUnique);
        }
예제 #3
0
        /// <summary>
        /// Selects the best match to what the user typed
        /// </summary>
        /// <remarks>
        /// The steps to determine the best match:
        /// 1. Check if there is a precise match in the builders list
        /// 2. If not - check if there is a precise match in the completions list
        /// 3. If not - look up the closest match in the completions list
        /// </remarks>
        public override void SelectBestMatch()
        {
            string prefix = getPrefix();

            // precise match to a completion builder
            Completion completion = CompletionBuilders.FirstOrDefault(c => c.DisplayText.CompareTo(prefix) == 0);

            // if none - precise match to a completion
            if (completion == null)
            {
                completion = Completions.FirstOrDefault(c => c.DisplayText.CompareTo(prefix) == 0);
            }

            // if none - position the completion list
            if (completion == null)
            {
                completion = Completions.FirstOrDefault(c => c.DisplayText.CompareTo(prefix) >= 0);
            }

            if (completion != null)
            {
                SelectionStatus = new CompletionSelectionStatus(completion,
                                                                completion.DisplayText == prefix,
                                                                true
                                                                );
            }
        }
        private TabCompleteSession CreateTabSessionWithNoSelectedCompletion(CompletionSelectionStatus selectionStatus)
        {
            _mockedScript = String.Format(TestScript, String.Empty);
            _mockedCaret  = TestStartPoint;

            return(new TabCompleteSession(TestCompletions, selectionStatus, TestStartPoint));
        }
예제 #5
0
        public override void SelectBestMatch()
        {
            var text = ApplicableTo.GetText(ApplicableTo.TextBuffer.CurrentSnapshot);

            if (string.IsNullOrWhiteSpace(text))
            {
                SelectionStatus = new CompletionSelectionStatus(null, false, false);
                return;
            }

            Microsoft.VisualStudio.Language.Intellisense.Completion bestMatch = null;
            var bestValue = 0;
            var isUnique  = true;

            foreach (var completion in Completions)
            {
                int value = CompareCompletionText(completion.DisplayText, text);
                if (bestMatch == null || value > bestValue)
                {
                    bestMatch = completion;
                    bestValue = value;
                    isUnique  = true;
                }
                else if (value == bestValue)
                {
                    isUnique = false;
                }
            }

            SelectionStatus = new CompletionSelectionStatus(bestMatch, bestValue > 0, isUnique);
        }
예제 #6
0
        public void SetCompletionItems(
            IList <RoslynCompletionItem> completionItems,
            RoslynCompletionItem selectedItem,
            RoslynCompletionItem suggestionModeItem,
            bool suggestionMode,
            bool isSoftSelected,
            ImmutableArray <CompletionItemFilter> completionItemFilters,
            string filterText)
        {
            CompletionPresenterSession.AssertIsForeground();

            // Initialize the completion map to a reasonable default initial size (+1 for the builder)
            CompletionItemMap ??= new Dictionary <RoslynCompletionItem, VSCompletion>(completionItems.Count + 1);
            FilterText         = filterText;
            SuggestionModeItem = suggestionModeItem;

            // If more than one filter was provided, then present it to the user.
            if (_showFilters && _filters == null && completionItemFilters.Length > 1)
            {
                _filters = completionItemFilters.Select(f => new IntellisenseFilter2(this, f))
                           .ToArray();
            }

            CreateCompletionListBuilder(selectedItem, suggestionModeItem, suggestionMode);
            CreateNormalCompletionListItems(completionItems);

            var selectedCompletionItem = selectedItem != null?GetVSCompletion(selectedItem) : null;

            SelectionStatus = new CompletionSelectionStatus(
                selectedCompletionItem,
                isSelected: !isSoftSelected, isUnique: selectedCompletionItem != null);
        }
예제 #7
0
        public override void Filter()
        {
            try {
                var text = ApplicableTo.GetText(ApplicableTo.TextBuffer.CurrentSnapshot);
                text = text.TrimStart('.').Trim(' ');

                //if (IsNullOrWhiteSpace(text)) {
                //    _session.Dismiss();
                //    return;
                //}

                var orderedByDistance = _items.Where(c => ContainsAllSymbols(text, c.InsertionText))
                                        .OfType <MyCompletion>()
                                        .OrderBy(c => {
                    var distance = GetSymbolDistance(c, text);
                    c.OrderIndex = distance;
                    return(distance);
                })
                                        .Distinct(new CompletionEqualityComparer());

                var zeroIndex  = new List <Completion>();
                var properties = new List <Completion>();
                var nodes      = new List <Completion>();
                var other      = new List <Completion>();

                foreach (var item in orderedByDistance)
                {
                    if (item.OrderIndex == 0)
                    {
                        zeroIndex.Add(item);
                    }
                    else if (item.CompletionType == CompletionType.Property)
                    {
                        properties.Add(item);
                    }
                    else if (item.CompletionType == CompletionType.Node)
                    {
                        nodes.Add(item);
                    }
                    else
                    {
                        other.Add(item);
                    }
                }

                WritableCompletions.Clear();
                WritableCompletions.AddRange(zeroIndex.Concat(properties)
                                             .Concat(nodes)
                                             .Concat(other)
                                             .ToList());

                if (WritableCompletions.Count > 0)
                {
                    SelectionStatus = new CompletionSelectionStatus(WritableCompletions[0], true, true);
                }
            } catch (Exception e) {
                Debug.WriteLine("Filter failed");
                Debug.WriteLine(e.ToString());
            }
        }
예제 #8
0
        public override void SelectBestMatch()
        {
            ITextSnapshot snapshot = ApplicableTo.TextBuffer.CurrentSnapshot;
            string typedText = ApplicableTo.GetText(snapshot).Trim();

            if (string.IsNullOrWhiteSpace(typedText))
            {
                if (_filteredCompletions.Any())
                    SelectionStatus = new CompletionSelectionStatus(_filteredCompletions.First(), true, true);

                return;
            }   

            foreach (Completion comp in _filteredCompletions)
            {
                int index = comp.DisplayText.IndexOf(typedText, StringComparison.OrdinalIgnoreCase);

                if (index == 0)
                {
                    SelectionStatus = new CompletionSelectionStatus(comp, true, true);
                    return;
                }
                else if (index > -1)
                {
                    SelectionStatus = new CompletionSelectionStatus(comp, true, true);
                    return;
                }
            }
        }
예제 #9
0
        private bool HandleCompletion()
        {
            ReadOnlyCollection <ICompletionSession> completionSessions = _completionBroker.GetSessions(_textView);

            if (completionSessions.Count == 0)
            {
                return(false);
            }

            ICompletionSession completionSession = completionSessions[0];

            if (completionSession.IsDismissed)
            {
                return(false);
            }

            CompletionSet             completionSet   = completionSession.SelectedCompletionSet;
            CompletionSelectionStatus selectionStatus = completionSet.SelectionStatus;

            if (selectionStatus.Completion.GetType().Name == "CustomCommitCompletion")
            {
                // let Roslyn handle its own completions
                return(false);
            }

            completionSession.Commit();
            return(true);
        }
예제 #10
0
        public override void SelectBestMatch()
        {
            var text = FilterSpan.GetText(FilterSpan.TextBuffer.CurrentSnapshot);

            if (text.Length == 0)
            {
                SelectionStatus = new CompletionSelectionStatus(null, false, false);
                return;
            }
            var        num        = int.MaxValue;
            Completion completion = null;

            foreach (var current in Completions)
            {
                var startIndex = current.DisplayText.StartsWith(InitialApplicableTo, StringComparison.OrdinalIgnoreCase) ? this.InitialApplicableTo.Length : 0;
                var num2       = current.DisplayText.IndexOf(text, startIndex, StringComparison.OrdinalIgnoreCase);
                if (num2 != -1 && num2 < num)
                {
                    completion = current;
                    num        = num2;
                }
            }
            if (completion == null)
            {
                SelectionStatus = new CompletionSelectionStatus(null, false, false);
                return;
            }
            SelectionStatus = new CompletionSelectionStatus(completion, true, true);
        }
예제 #11
0
        /// <summary>
        /// Determines and selects the only match in the completion set.
        /// This ignores the user's filtering preferences.
        /// </summary>
        /// <returns>
        /// True if a match is found and selected; otherwise, false if there
        /// is no single match in the completion set.
        /// </returns>
        public bool SelectSingleBest()
        {
            var text = ApplicableTo.GetText(ApplicableTo.TextBuffer.CurrentSnapshot);

            Completion bestMatch = null;

            // Using the _completions field to search through all completions
            // and ignore filtering settings.
            foreach (var comp in _completions)
            {
                if (_comparer.IsCandidateMatch(comp.DisplayText, text))
                {
                    if (bestMatch == null)
                    {
                        bestMatch = comp;
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            if (bestMatch != null)
            {
                SelectionStatus = new CompletionSelectionStatus(bestMatch,
                                                                isSelected: true,
                                                                isUnique: true);
                return(true);
            }
            else
            {
                return(false);
            }
        }
 public static bool IsHollowSelected(this CompletionSelectionStatus status)
 {
     if (!CompletionSessionExtensions.IsSelected(status))
     {
         return(status.SelectedCompletion != null);
     }
     return(false);
 }
예제 #13
0
        /// <summary>
        /// Determines the best match in the completion set.
        /// </summary>
        public override void SelectBestMatch()
        {
            if (_completions == null)
            {
                return;
            }

            var text = ApplicableTo.GetText(ApplicableTo.TextBuffer.CurrentSnapshot);

            Completion bestMatch   = _previousSelection;
            int        bestValue   = 0;
            bool       isUnique    = true;
            bool       allowSelect = true;

            // Using the Completions property to only search through visible
            // completions.
            foreach (var comp in Completions)
            {
                int value = _comparer.GetSortKey(_matchInsertionText ? comp.InsertionText : comp.DisplayText, text);
                if (bestMatch == null || value > bestValue)
                {
                    bestMatch = comp;
                    bestValue = value;
                    isUnique  = true;
                }
                else if (value == bestValue)
                {
                    isUnique = false;
                }
            }

            if (!CommitByDefault)
            {
                allowSelect = false;
                isUnique    = false;
            }

            if (((DynamicallyVisibleCompletion)bestMatch).Visible)
            {
                SelectionStatus = new CompletionSelectionStatus(
                    bestMatch,
                    isSelected: allowSelect && bestValue > 0,
                    isUnique: isUnique
                    );
            }
            else
            {
                SelectionStatus = new CompletionSelectionStatus(
                    null,
                    isSelected: false,
                    isUnique: false
                    );
            }

            _previousSelection = bestMatch;
        }
예제 #14
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            CompletionSelectionStatus completionSelectionStatu = value as CompletionSelectionStatus;

            if (completionSelectionStatu == null)
            {
                return(false);
            }
            return((completionSelectionStatu.SelectionOptions & CompletionSelectionOptions.Selected) == CompletionSelectionOptions.Selected);
        }
예제 #15
0
        private bool HandleCompletion(char commitCharacter)
        {
            ReadOnlyCollection <ICompletionSession> completionSessions = _completionBroker.GetSessions(_textView);

            if (completionSessions.Count == 0)
            {
                return(false);
            }

            ICompletionSession completionSession = completionSessions[0];

            if (completionSession.IsDismissed)
            {
                return(false);
            }

            CompletionSet             completionSet   = completionSession.SelectedCompletionSet;
            CompletionSelectionStatus selectionStatus = completionSet.SelectionStatus;

            if (selectionStatus.Completion.GetType().Name == "CustomCommitCompletion")
            {
                // let Roslyn handle its own completions
                return(false);
            }

            string insertionText = selectionStatus.Completion.InsertionText;

            completionSession.Commit();

            bool passCharacterToEditor;

            switch (commitCharacter)
            {
            case '/':
            case '>':
                // if the insertion text doesn't end with '>' or '/>', allow the user to complete the item and insert
                // the closing element character by typing '/' or '>'.
                passCharacterToEditor = !insertionText.EndsWith(">");
                break;

            case ' ':
                // only pass the space through if the completion item doesn't contain any replaceable elements
                passCharacterToEditor = insertionText.IndexOf('\xFF') < 0;
                break;

            case '\n':
            case '\t':
            default:
                // these items trigger completion, but aren't written to the output
                passCharacterToEditor = false;
                break;
            }

            return(!passCharacterToEditor);
        }
        /// <summary>
        /// Determines whether two instances of <see cref="CompletionSelectionStatus"/> are the same.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            CompletionSelectionStatus otherStatus = obj as CompletionSelectionStatus;

            if (otherStatus != null)
            {
                return(this == otherStatus);
            }

            return(false);
        }
예제 #17
0
        /// <summary>
        /// Only commit the completion selection if there is a unique choice in the list
        /// </summary>
        protected void CommitUniqueCompletionSession()
        {
            if (HasActiveCompletionSession)
            {
                CompletionSelectionStatus status = CompletionSession.SelectedCompletionSet.SelectionStatus;

                if (status.IsSelected && status.IsUnique)
                {
                    CommitCompletionSession();
                }
            }
        }
예제 #18
0
        /// <summary>
        /// Creates and initializes the TabCompleteSession
        /// </summary>
        /// <param name="completions">The completions</param>
        /// <param name="selectionStatus">The selection status</param>
        /// <param name="startPoint">The start point of the completions</param>
        public TabCompleteSession(IList <Completion> completions, CompletionSelectionStatus selectionStatus, int startPoint)
        {
            _completions = completions;
            _startPoint  = startPoint;

            if (_completions != null && selectionStatus != null && selectionStatus.IsSelected)
            {
                _index = _completions.IndexOf(selectionStatus.Completion);
            }
            else
            {
                _index = -1;
            }
        }
        public override void SelectBestMatch()
        {
            ITextSnapshot snapshot = ApplicableTo.TextBuffer.CurrentSnapshot;
            string text = ApplicableTo.GetText(snapshot);

            if (!String.IsNullOrEmpty(text))
            {
                var completion = Completions.
                FirstOrDefault(c => !String.IsNullOrEmpty(c.DisplayText) &&
                c.DisplayText.IndexOf(text, StringComparison.OrdinalIgnoreCase) != -1);

                if (completion != null)
                    SelectionStatus = new CompletionSelectionStatus(completion, true, false);
            }
        }
예제 #20
0
        private CodeAidContext CreateCodeAidContext()
        {
            ITextSnapshot             currentSnapshot = this.textView.TextBuffer.CurrentSnapshot;
            CompletionSelectionStatus status          = this.activeSession != null ? this.activeSession.SelectionStatus : (CompletionSelectionStatus)null;
            ICompletion completion1 = status == null || !CompletionSessionExtensions.IsSelected(status) ? (ICompletion)null : this.activeSession.SelectionStatus.SelectedCompletion;
            ICompletion completion2 = status == null || !CompletionSessionExtensions.IsHollowSelected(status) ? (ICompletion)null : this.activeSession.SelectionStatus.SelectedCompletion;
            int         position    = this.LeftmostTextViewSelection();

            return(new CodeAidContext()
            {
                CurrentPosition = new SnapshotPoint(currentSnapshot, position),
                SelectionSpan = this.textView.Selection.SelectionSpan,
                SessionStartingPosition = this.activeSessionStartPoint,
                SessionSelectedCompletion = completion1,
                SessionHollowSelectedCompletion = completion2
            });
        }
예제 #21
0
        /// <summary>
        /// Determines and selects the only match in the completion set.
        /// This ignores the user's filtering preferences.
        /// </summary>
        /// <returns>
        /// True if a match is found and selected; otherwise, false if there
        /// is no single match in the completion set.
        /// </returns>
        public bool SelectSingleBest()
        {
            if (_completions == null)
            {
                return(false);
            }

            var text = ApplicableTo.GetText(ApplicableTo.TextBuffer.CurrentSnapshot);

            Completion bestMatch = null;

            // Unfilter and then search all completions
            FilterToPredicate(_ => true);

            foreach (var comp in _completions)
            {
                if (_comparer.IsCandidateMatch(_matchInsertionText ? comp.InsertionText : comp.DisplayText, text))
                {
                    if (bestMatch == null)
                    {
                        bestMatch = comp;
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            try {
                if (bestMatch != null)
                {
                    SelectionStatus = new CompletionSelectionStatus(
                        bestMatch,
                        isSelected: true,
                        isUnique: true
                        );
                    return(true);
                }
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                ex.ReportUnhandledException(null, GetType(), allowUI: false);
            }

            return(false);
        }
예제 #22
0
        public override void SelectBestMatch()
        {
            _typed = ApplicableTo.GetText(ApplicableTo.TextBuffer.CurrentSnapshot);

            CustomFilter();

            IOrderedEnumerable <Completion> ordered = currentCompletions.OrderByDescending(c => GetHighlightedSpansInDisplayText(c.DisplayText).Sum(s => s.Length));

            if (ordered.Any())
            {
                int count = ordered.Count();
                SelectionStatus = new CompletionSelectionStatus(ordered.First(), count == 1, count == 1);
            }
            else
            {
                SelectBestMatch(CompletionMatchType.MatchDisplayText, false);
            }
        }
예제 #23
0
        public void SetCompletionItems(
            IList <CompletionItem> completionItems,
            CompletionItem selectedItem,
            CompletionItem suggestionModeItem,
            bool suggestionMode,
            bool isSoftSelected,
            ImmutableArray <CompletionItemFilter> completionItemFilters,
            string filterText)
        {
            _foregroundThread.AssertIsForeground();

            foreach (var item in completionItems)
            {
                if (!_displayTextToBoldingTextMap.ContainsKey(item.DisplayText))
                {
                    _displayTextToBoldingTextMap.Add(item.DisplayText, CompletionHelper.GetDisplayTextForMatching(item));
                }
            }

            // Initialize the completion map to a reasonable default initial size (+1 for the builder)
            CompletionItemMap  = CompletionItemMap ?? new Dictionary <CompletionItem, VSCompletion>(completionItems.Count + 1);
            FilterText         = filterText;
            SuggestionModeItem = suggestionModeItem;

            // If more than one filter was provided, then present it to the user.
            if (_showFilters && _filters == null && completionItemFilters.Length > 1)
            {
                _filters = completionItemFilters.Select(f => new IntellisenseFilter2(this, f))
                           .ToArray();
            }

            CreateCompletionListBuilder(selectedItem, suggestionModeItem, suggestionMode);
            CreateNormalCompletionListItems(completionItems);

            var selectedCompletionItem = selectedItem != null?GetVSCompletion(selectedItem) : null;

            SelectionStatus = new CompletionSelectionStatus(
                selectedCompletionItem,
                isSelected: !isSoftSelected, isUnique: selectedCompletionItem != null);
        }
        public void SetCompletionItems(
            IList <CompletionItem> completionItems,
            CompletionItem selectedItem,
            CompletionItem suggestionModeItem,
            bool suggestionMode,
            bool isSoftSelected,
            ImmutableArray <CompletionItemFilter> completionItemFilters,
            string filterText)
        {
            // Initialize the completion map to a reasonable default initial size (+1 for the builder)
            CompletionItemMap  = CompletionItemMap ?? new Dictionary <CompletionItem, VSCompletion>(completionItems.Count + 1);
            FilterText         = filterText;
            SuggestionModeItem = suggestionModeItem;

            CreateCompletionListBuilder(selectedItem, suggestionModeItem, suggestionMode);
            CreateNormalCompletionListItems(completionItems);

            var selectedCompletionItem = selectedItem != null?GetVSCompletion(selectedItem) : null;

            SelectionStatus = new CompletionSelectionStatus(
                selectedCompletionItem,
                isSelected: !isSoftSelected, isUnique: selectedCompletionItem != null);
        }
예제 #25
0
        protected virtual bool CanCommitCompletionSession(char typedCharacter)
        {
            if (!HasActiveCompletionSession)
            {
                return(false);
            }

            CompletionSet             completionSet = CompletionSession.SelectedCompletionSet;
            CompletionSelectionStatus status        = completionSet.SelectionStatus;

            if (status.Completion == null)
            {
                return(false);
            }

            if (status.IsSelected)
            {
                return(true);
            }

            // Tab character commits any entry, whether it's really selected or not.
            // However, it should not complete if entry doesn't start with the text
            // typed so far. Otherwise it interferes with snippet insertion on Tab-Tab.
            if (typedCharacter == '\t')
            {
                try {
                    var snapshot = completionSet.ApplicableTo.TextBuffer.CurrentSnapshot;
                    var span     = completionSet.ApplicableTo.GetSpan(snapshot);
                    if (status.Completion.InsertionText.StartsWithOrdinal(span.GetText()))
                    {
                        return(true);
                    }
                } catch (ArgumentException) { }
            }

            return(false);
        }
예제 #26
0
        public override void SelectBestMatch()
        {
            ITextSnapshot snapshot  = ApplicableTo.TextBuffer.CurrentSnapshot;
            string        typedText = ApplicableTo.GetText(snapshot);

            if (string.IsNullOrWhiteSpace(typedText))
            {
                if (this.WritableCompletions.Any())
                {
                    SelectionStatus = new CompletionSelectionStatus(WritableCompletions.First(), true, true);
                }

                return;
            }

            foreach (Completion comp in WritableCompletions)
            {
                if (comp.DisplayText.IndexOf(typedText, StringComparison.InvariantCultureIgnoreCase) > -1)
                {
                    SelectionStatus = new CompletionSelectionStatus(comp, true, true);
                    return;
                }
            }
        }
예제 #27
0
        public override void SelectBestMatch()
        {
            ITextSnapshot snapshot  = ApplicableTo.TextBuffer.CurrentSnapshot;
            string        typedText = ApplicableTo.GetText(snapshot);

            if (string.IsNullOrWhiteSpace(typedText))
            {
                if (this.WritableCompletions.Any())
                {
                    SelectionStatus = new CompletionSelectionStatus(WritableCompletions.First(), true, true);
                }

                return;
            }

            foreach (CrmCompletion comp in WritableCompletions)
            {
                if (comp.IsMatch(typedText))
                {
                    SelectionStatus = new CompletionSelectionStatus(comp, true, true);
                    return;
                }
            }
        }
예제 #28
0
        /// <summary>
        /// Determines and selects the only match in the completion set.
        /// This ignores the user's filtering preferences.
        /// </summary>
        /// <returns>
        /// True if a match is found and selected; otherwise, false if there
        /// is no single match in the completion set.
        /// </returns> 
        public bool SelectSingleBest() {
            var text = ApplicableTo.GetText(ApplicableTo.TextBuffer.CurrentSnapshot);

            Completion bestMatch = null;

            // Using the _completions field to search through all completions
            // and ignore filtering settings.
            foreach (var comp in _completions) {
                if (_comparer.IsCandidateMatch(_matchInsertionText ? comp.InsertionText : comp.DisplayText, text)) {
                    if (bestMatch == null) {
                        bestMatch = comp;
                    } else {
                        return false;
                    }
                }
            }

            if (bestMatch != null) {
                SelectionStatus = new CompletionSelectionStatus(
                    bestMatch,
                    isSelected: true,
                    isUnique: true
                );
                return true;
            } else {
                return false;
            }
        }
예제 #29
0
        /// <summary>
        /// Determines the best match in the completion set.
        /// </summary>
        public override void SelectBestMatch() {
            var text = ApplicableTo.GetText(ApplicableTo.TextBuffer.CurrentSnapshot);

            Completion bestMatch = _previousSelection;
            int bestValue = 0;
            bool isUnique = true;
            bool allowSelect = true;

            // Using the Completions property to only search through visible
            // completions.
            foreach (var comp in Completions) {
                int value = _comparer.GetSortKey(_matchInsertionText ? comp.InsertionText : comp.DisplayText, text);
                if (bestMatch == null || value > bestValue) {
                    bestMatch = comp;
                    bestValue = value;
                    isUnique = true;
                } else if (value == bestValue) {
                    isUnique = false;
                }
            }

            if (Moniker == "PythonOverrides") {
                allowSelect = false;
                isUnique = false;
            }

            if (((DynamicallyVisibleCompletion)bestMatch).Visible) {
                SelectionStatus = new CompletionSelectionStatus(
                    bestMatch,
                    isSelected: allowSelect && bestValue > 0,
                    isUnique: isUnique
                );
            } else {
                SelectionStatus = new CompletionSelectionStatus(
                    null,
                    isSelected: false,
                    isUnique: false
                );
            }

            _previousSelection = bestMatch;
        }
 public override void SelectBestMatch()
 {
     var text = FilterSpan.GetText(FilterSpan.TextBuffer.CurrentSnapshot);
     if (text.Length == 0)
     {
         SelectionStatus = new CompletionSelectionStatus(null, false, false);
         return;
     }
     var num = int.MaxValue;
     Completion completion = null;
     foreach (var current in Completions)
     {
         var startIndex = current.DisplayText.StartsWith(InitialApplicableTo, StringComparison.OrdinalIgnoreCase) ? this.InitialApplicableTo.Length : 0;
         var num2 = current.DisplayText.IndexOf(text, startIndex, StringComparison.OrdinalIgnoreCase);
         if (num2 != -1 && num2 < num)
         {
             completion = current;
             num = num2;
         }
     }
     if (completion == null)
     {
         SelectionStatus = new CompletionSelectionStatus(null, false, false);
         return;
     }
     SelectionStatus = new CompletionSelectionStatus(completion, true, true);
 }
 public override void SelectBestMatch()
 {
     SelectionStatus = new CompletionSelectionStatus(Completions[0], false, true);
 }
예제 #32
0
 bool Equals(CompletionSelectionStatus other) => (object)other != null && other.IsSelected == IsSelected && other.IsUnique == IsUnique && Equals(other.Completion, Completion);
예제 #33
0
        // !EFW - This has been throwing random null reference exceptions in VS 2019.  It's not something I've
        // been able to duplicate so I've added null checks everywhere to see if that stops it.
        private bool HandleCompletion(char commitCharacter)
        {
            ReadOnlyCollection <ICompletionSession> completionSessions = _completionBroker.GetSessions(_textView);

            if (completionSessions == null || completionSessions.Count == 0)
            {
                return(false);
            }

            ICompletionSession completionSession = completionSessions[0];

            if (completionSession == null || completionSession.IsDismissed)
            {
                return(false);
            }

            CompletionSet             completionSet   = completionSession.SelectedCompletionSet;
            CompletionSelectionStatus selectionStatus = completionSet?.SelectionStatus;

            if (!(selectionStatus?.Completion is SandcastleCompletion))
            {
                // Workaround some odd behavior in the completion when trying to enter "</".  This prevents it
                // from converting it to an XML comment ("<!--/-->").
                if (commitCharacter == '/' && selectionStatus?.Completion?.InsertionText == "!--")
                {
                    completionSession.Dismiss();
                }

                // Let other providers handle their own completions
                return(false);
            }

            string insertionText = selectionStatus.Completion.InsertionText;

            if (insertionText == null)
            {
                return(false);
            }

            completionSession.Commit();

            bool passCharacterToEditor;

            switch (commitCharacter)
            {
            case '/':
            case '>':
                // If the insertion text doesn't end with '>' or '/>', allow the user to complete the item and insert
                // the closing element character by typing '/' or '>'.
                passCharacterToEditor = !insertionText.EndsWith(">");
                break;

            case ' ':
                // Only pass the space through if the completion item doesn't contain any replaceable elements
                passCharacterToEditor = insertionText.IndexOf('\xFF') < 0;
                break;

            case '\n':
            case '\t':
            default:
                // These items trigger completion, but aren't written to the output
                passCharacterToEditor = false;
                break;
            }

            return(!passCharacterToEditor);
        }
 public static bool IsUnique(this CompletionSelectionStatus status)
 {
     return((status.SelectionOptions & CompletionSelectionOptions.Unique) == CompletionSelectionOptions.Unique);
 }
예제 #35
0
        public override void SelectBestMatch()
        {
            var text = FilterSpan.GetText(FilterSpan.TextBuffer.CurrentSnapshot);

            if (text.Length == 0)
            {
                if (InitialApplicableTo.EndsWith("\\", StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }

                foreach (var current in Completions)
                {
                    if (current.InsertionText.StartsWith(InitialApplicableTo, StringComparison.OrdinalIgnoreCase))
                    {
                        SelectionStatus = new CompletionSelectionStatus(current, true, true);
                        return;
                    }
                }
                return;
            }
            int        num          = int.MaxValue;
            int        matchedCount = 0;
            Completion completion   = null;

            foreach (var current in Completions)
            {
                string currentInsertionText = current.InsertionText;
                if (current.InsertionText.StartsWith("\"", StringComparison.OrdinalIgnoreCase) && current.InsertionText.EndsWith("\"", StringComparison.OrdinalIgnoreCase))
                {
                    currentInsertionText = currentInsertionText.Substring(1, currentInsertionText.Length - 2);
                }

                var startIndex = current.InsertionText.StartsWith(InitialApplicableTo, StringComparison.OrdinalIgnoreCase) ? this.InitialApplicableTo.Length : 0;
                var num2       = currentInsertionText.IndexOf(text, startIndex, StringComparison.OrdinalIgnoreCase);

                if (num2 != -1 && num2 < num)
                {
                    completion = current;
                    num        = num2;
                    ++matchedCount;
                }
            }
            if (completion == null)
            {
                SelectionStatus = new CompletionSelectionStatus(null, false, false);
                return;
            }

            bool isFullyMatched = completion.InsertionText.Equals(InitialApplicableTo + text, StringComparison.OrdinalIgnoreCase);

            var propertiesCollection = FilterSpan.TextBuffer.Properties;

            if (propertiesCollection.ContainsProperty(BufferProperties.SessionCompletionFullyMatchedStatus))
            {
                propertiesCollection.RemoveProperty(BufferProperties.SessionCompletionFullyMatchedStatus);
            }
            propertiesCollection.AddProperty(BufferProperties.SessionCompletionFullyMatchedStatus, isFullyMatched);

            bool isSelected = (matchedCount > 0);
            bool isUnique   = (matchedCount == 1);

            SelectionStatus = new CompletionSelectionStatus(completion, isSelected, isUnique);
        }
예제 #36
0
        /// <summary>
        /// Selects the best match to what the user typed
        /// </summary>
        /// <remarks>
        /// The steps to determine the best match:
        /// 1. Check if there is a precise match in the builders list
        /// 2. If not - check if there is a precise match in the completions list
        /// 3. If not - look up the closest match in the completions list
        /// </remarks>
        public override void SelectBestMatch()
        {
            string prefix = getPrefix();

            // precise match to a completion builder
            Completion completion = CompletionBuilders.FirstOrDefault(c => c.DisplayText.CompareTo(prefix) == 0);

            // if none - precise match to a completion
            if (completion == null)
                completion = Completions.FirstOrDefault(c => c.DisplayText.CompareTo(prefix) == 0);

            // if none - position the completion list
            if (completion == null)
                completion = Completions.FirstOrDefault(c => c.DisplayText.CompareTo(prefix) >= 0);

            if (completion != null)
                SelectionStatus = new CompletionSelectionStatus(completion,
                    completion.DisplayText == prefix,
                    true
                    );
        }
 public override void SelectBestMatch()
 {
     SelectionStatus = new CompletionSelectionStatus(Completions[0], false, true);
 }
예제 #38
0
        /// <summary>
        /// Determines the best match in the completion set.
        /// </summary>
        public override void SelectBestMatch()
        {
            var text = ApplicableTo.GetText(ApplicableTo.TextBuffer.CurrentSnapshot);

            Completion bestMatch   = _previousSelection;
            int        bestValue   = 0;
            bool       isUnique    = true;
            bool       allowSelect = true;

            if (!string.IsNullOrWhiteSpace(text))
            {
                // Using the Completions property to only search through visible
                // completions.
                foreach (var comp in Completions)
                {
                    int value = _comparer.GetSortKey(comp.DisplayText, text);
                    if (bestMatch == null || value > bestValue)
                    {
                        bestMatch = comp;
                        bestValue = value;
                        isUnique  = true;
                    }
                    else if (value == bestValue)
                    {
                        isUnique = false;
                    }
                }
            }
            else
            {
                foreach (var comp in Completions)
                {
                    int temp;
                    if (IntellisenseExtensions.LastCommittedCompletions.TryGetValue(comp.DisplayText, out temp))
                    {
                        if (bestMatch == null || temp > bestValue)
                        {
                            bestMatch = comp;
                            bestValue = temp;
                            isUnique  = true;
                        }
                    }
                }
            }

            if (bestMatch == null)
            {
                bestMatch = Completions[0];
            }

            if (((DynamicallyVisibleCompletion)bestMatch).Visible)
            {
                SelectionStatus = new CompletionSelectionStatus(bestMatch,
                                                                isSelected: allowSelect && bestValue > 0,
                                                                isUnique: isUnique);
            }
            else
            {
                SelectionStatus = new CompletionSelectionStatus(null,
                                                                isSelected: false,
                                                                isUnique: false);
            }

            _previousSelection = bestMatch;
        }