示例#1
0
        /// <summary>
        /// Initializes a new instance with the specified properties.
        /// </summary>
        /// <param name="moniker">The unique, non-localized identifier for the
        /// completion set.</param>
        /// <param name="displayName">The localized name of the completion set.
        /// </param>
        /// <param name="applicableTo">The tracking span to which the
        /// completions apply.</param>
        /// <param name="completions">The list of completions.</param>
        /// <param name="options">The options to use for filtering and
        /// selecting items.</param>
        /// <param name="comparer">The comparer to use to order the provided
        /// completions.</param>
        public FuzzyCompletionSet(string moniker, string displayName, ITrackingSpan applicableTo,
                                  IEnumerable <DynamicallyVisibleCompletion> completions,
                                  CompletionOptions options, IComparer <Completion> comparer,
                                  Func <string, IEnumerable <DynamicallyVisibleCompletion> > deferredLoadCallback) :
            base(moniker, displayName, applicableTo, null, null)
        {
            _options         = options;
            _initialComparer = comparer;
            _completions     = new BulkObservableCollection <Completion>();
            _loadedDeferredCompletionSubsets = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            _deferredLoadCallback            = deferredLoadCallback;
            _completions.AddRange(completions
                                  .Where(c => c != null && !string.IsNullOrWhiteSpace(c.DisplayText))
                                  .OrderBy(c => c, comparer)
                                  );
            _comparer = new FuzzyStringMatcher(options.SearchMode);

            _shouldFilter       = options.FilterCompletions;
            _shouldHideAdvanced = options.HideAdvancedMembers && !_completions.All(IsAdvanced);

            if (_shouldFilter | _shouldHideAdvanced)
            {
                _filteredCompletions = new WritableFilteredObservableCollection <Completion>(_completions);

                foreach (var c in _completions.Cast <DynamicallyVisibleCompletion>())
                {
                    c.Visible = !_shouldHideAdvanced || !IsAdvanced(c);
                }
                _filteredCompletions.Filter(IsVisible);
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance with the specified properties.
        /// </summary>
        /// <param name="moniker">The unique, non-localized identifier for the
        /// completion set.</param>
        /// <param name="displayName">The localized name of the completion set.
        /// </param>
        /// <param name="applicableTo">The tracking span to which the
        /// completions apply.</param>
        /// <param name="completions">The list of completions.</param>
        /// <param name="options">The options to use for filtering and
        /// selecting items.</param>
        /// <param name="comparer">The comparer to use to order the provided
        /// completions.</param>
        /// <param name="matchInsertionText">If true, matches user input against
        /// the insertion text; otherwise, uses the display text.</param>
        public FuzzyCompletionSet(
            string moniker,
            string displayName,
            ITrackingSpan applicableTo,
            IEnumerable <DynamicallyVisibleCompletion> completions,
            CompletionOptions options,
            IComparer <Completion> comparer,
            bool matchInsertionText = false
            ) :
            base(moniker, displayName, applicableTo, null, null)
        {
            _matchInsertionText = matchInsertionText;
            _completions        = new BulkObservableCollection <Completion>();
            _completions.AddRange(completions
                                  .Where(c => c != null && !string.IsNullOrWhiteSpace(c.DisplayText))
                                  .OrderBy(c => c, comparer)
                                  );
            _comparer = new FuzzyStringMatcher(FuzzyMatchMode.Default);

            _shouldFilter       = options.FilterCompletions;
            _shouldHideAdvanced = options.HideAdvancedMembers && !_completions.All(IsAdvanced);

            if (!_completions.Any())
            {
                _completions = null;
            }

            if (_completions != null && _shouldFilter | _shouldHideAdvanced)
            {
                _filteredCompletions = new FilteredObservableCollection <Completion>(_completions);

                foreach (var c in _completions.Cast <DynamicallyVisibleCompletion>())
                {
                    c.Visible = !_shouldHideAdvanced || !IsAdvanced(c);
                }
                _filteredCompletions.Filter(IsVisible);
            }

            CommitByDefault = DefaultCommitByDefault;
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance with the specified properties.
        /// </summary>
        /// <param name="moniker">The unique, non-localized identifier for the completion set.</param>
        /// <param name="displayName">The localized name of the completion set.</param>
        /// <param name="applicableTo">The tracking span to which the completions apply.</param>
        /// <param name="completions">The list of completions.</param>
        /// <param name="options">The options to use for filtering and selecting items.</param>
        /// <param name="comparer">The comparer to use to order the provided completions.</param>
        /// <param name="matchInsertionText">If true, matches user input against
        /// the insertion text; otherwise, uses the display text.</param>
        public FuzzyCompletionSet(
            string moniker,
            string displayName,
            ITrackingSpan applicableTo,
            IEnumerable<DynamicallyVisibleCompletion> completions,
            IComparer<Completion> comparer,
            bool matchInsertionText = false
        ) :
            base(moniker, displayName, applicableTo, null, null) {
            _matchInsertionText = matchInsertionText;
            _completions = new BulkObservableCollection<Completion>();
            _completions.AddRange(completions
                .Where(c => c != null && !string.IsNullOrWhiteSpace(c.DisplayText))
                .OrderBy(c => c, comparer)
            );
            _comparer = new FuzzyStringMatcher(FuzzyMatchMode.Default);

#if FALSE
            _shouldFilter = options.FilterCompletions;
            _shouldHideAdvanced = options.HideAdvancedMembers && !_completions.All(IsAdvanced);
#endif
            _shouldFilter = true;
            _shouldHideAdvanced = false;

            if (_shouldFilter | _shouldHideAdvanced) {
                _filteredCompletions = new FilteredObservableCollection<Completion>(_completions);

                foreach (var c in _completions.Cast<DynamicallyVisibleCompletion>()) {
                    c.Visible = !_shouldHideAdvanced || !IsAdvanced(c);
                }
                _filteredCompletions.Filter(IsVisible);
            }
        }
示例#4
0
        /// <summary>
        /// Restricts the set of completions to those that match the applicability text
        /// of the completion set, and then determines the best match.
        /// </summary>
        public override void Filter()
        {
            if (_filteredCompletions == null)
            {
                foreach (var c in _completions.Cast <DynamicallyVisibleCompletion>())
                {
                    c.Visible = true;
                }
                return;
            }

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

            if (text.Length > 0)
            {
                bool hideAdvanced = _shouldHideAdvanced && !text.StartsWith("__");
                bool anyVisible   = false;
                foreach (var c in _completions.Cast <DynamicallyVisibleCompletion>())
                {
                    if (hideAdvanced && IsAdvanced(c))
                    {
                        c.Visible = false;
                    }
                    else if (_shouldFilter)
                    {
                        c.Visible = _comparer.IsCandidateMatch(_matchInsertionText ? c.InsertionText : c.DisplayText, text);
                    }
                    else
                    {
                        c.Visible = true;
                    }
                    anyVisible |= c.Visible;
                }
                if (!anyVisible)
                {
                    foreach (var c in _completions.Cast <DynamicallyVisibleCompletion>())
                    {
                        // UndoVisible only works reliably because we always
                        // set Visible in the previous loop.
                        c.UndoVisible();
                    }
                }
                _filteredCompletions.Filter(IsVisible);
            }
            else if (_shouldHideAdvanced)
            {
                foreach (var c in _completions.Cast <DynamicallyVisibleCompletion>())
                {
                    c.Visible = !IsAdvanced(c);
                }
                _filteredCompletions.Filter(IsVisible);
            }
            else
            {
                foreach (var c in _completions.Cast <DynamicallyVisibleCompletion>())
                {
                    c.Visible = true;
                }
                _filteredCompletions.StopFiltering();
            }
        }
示例#5
0
        /// <summary>
        /// Restricts the set of completions to those that match the applicability text
        /// of the completion set, and then determines the best match.
        /// </summary>
        public override async void Filter()
        {
            if (_filteredCompletions == null)
            {
                foreach (var c in _completions.Cast <DynamicallyVisibleCompletion>())
                {
                    c.Visible = true;
                }
                return;
            }

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

            if (text.Length > 0)
            {
                bool anyVisible = false;
                foreach (var c in _completions.Cast <DynamicallyVisibleCompletion>())
                {
                    if (_shouldHideAdvanced && IsAdvanced(c) && !text.StartsWith("__"))
                    {
                        c.Visible = false;
                    }
                    else if (_shouldFilter)
                    {
                        c.Visible = _comparer.IsCandidateMatch(c.DisplayText, text);
                    }
                    else
                    {
                        c.Visible = true;
                    }
                    anyVisible |= c.Visible;
                }
                if (!anyVisible)
                {
                    foreach (var c in _completions.Cast <DynamicallyVisibleCompletion>())
                    {
                        // UndoVisible only works reliably because we always
                        // set Visible in the previous loop.
                        c.UndoVisible();
                    }
                }
                _filteredCompletions.Filter(IsVisible);

                if (_options.DeferredLoadPreCharacters > 0)
                {
                    var useText = text;
                    if (text.Length > _options.DeferredLoadPreCharacters)
                    {
                        useText = text.Substring(0, _options.DeferredLoadPreCharacters);
                        if (_loadedDeferredCompletionSubsets.Contains(useText))
                        {
                            return;
                        }
                    }
                    else if (text.Length < _options.DeferredLoadPreCharacters)
                    {
                        return;
                    }

                    // check to see if the deferred load has been done already
                    if (_deferredLoadCallback != null && !_loadedDeferredCompletionSubsets.Contains(useText))
                    {
                        _loadedDeferredCompletionSubsets.Add(text);
                        var completions = await Task.Factory.StartNew <IList <DynamicallyVisibleCompletion> >(() => _deferredLoadCallback(text).ToList());

                        _filteredCompletions.AddRange(completions);

                        SelectBestMatch();
                    }
                }
            }
            else if (_shouldHideAdvanced)
            {
                foreach (var c in _completions.Cast <DynamicallyVisibleCompletion>())
                {
                    c.Visible = !IsAdvanced(c);
                }
                _filteredCompletions.Filter(IsVisible);
            }
            else
            {
                foreach (var c in _completions.Cast <DynamicallyVisibleCompletion>())
                {
                    c.Visible = true;
                }
                _filteredCompletions.StopFiltering();
            }
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance with the specified properties.
        /// </summary>
        /// <param name="moniker">The unique, non-localized identifier for the
        /// completion set.</param>
        /// <param name="displayName">The localized name of the completion set.
        /// </param>
        /// <param name="applicableTo">The tracking span to which the
        /// completions apply.</param>
        /// <param name="completions">The list of completions.</param>
        /// <param name="options">The options to use for filtering and
        /// selecting items.</param>
        /// <param name="comparer">The comparer to use to order the provided
        /// completions.</param>
        public FuzzyCompletionSet(string moniker, string displayName, ITrackingSpan applicableTo, IEnumerable<DynamicallyVisibleCompletion> completions, CompletionOptions options, IComparer<Completion> comparer)
            : base(moniker, displayName, applicableTo, null, null)
        {
            _completions = new BulkObservableCollection<Completion>();
            _completions.AddRange(completions.OrderBy(c => c, comparer));
            _comparer = new FuzzyStringMatcher(options.SearchMode);

            _shouldFilter = options.FilterCompletions;
            _shouldHideAdvanced = options.HideAdvancedMembers;

            if (_shouldFilter | _shouldHideAdvanced) {
                _filteredCompletions = new FilteredObservableCollection<Completion>(_completions);

                foreach (var c in _completions.Cast<DynamicallyVisibleCompletion>()) {
                    c.Visible = !_shouldHideAdvanced || !IsAdvanced(c);
                }
                _filteredCompletions.Filter(IsVisible);
            }
        }