Inheritance: CompletionSet
Beispiel #1
0
        /// <summary>
        /// Populates R completion list for a given position
        /// </summary>
        /// <param name="position">Position in R text buffer</param>
        /// <param name="session">Completion session</param>
        /// <param name="completionSets">Completion sets to add to</param>
        /// <param name="ast">Document abstract syntax tree</param>
        internal void PopulateCompletionList(int position, ICompletionSession session, IList <CompletionSet> completionSets, AstRoot ast)
        {
            RCompletionContext context = new RCompletionContext(session, _textBuffer, ast, position);

            bool autoShownCompletion = true;

            if (session.TextView.Properties.ContainsProperty(CompletionController.AutoShownCompletion))
            {
                autoShownCompletion = session.TextView.Properties.GetProperty <bool>(CompletionController.AutoShownCompletion);
            }

            IReadOnlyCollection <IRCompletionListProvider> providers =
                RCompletionEngine.GetCompletionForLocation(context, autoShownCompletion, _shell);

            // Position is in R as is the applicable spa, so no need to map down
            Span?applicableSpan = GetApplicableSpan(position, session);

            if (applicableSpan.HasValue)
            {
                ITrackingSpan      trackingSpan = context.TextBuffer.CurrentSnapshot.CreateTrackingSpan(applicableSpan.Value, SpanTrackingMode.EdgeInclusive);
                List <RCompletion> completions  = new List <RCompletion>();
                bool sort = true;

                foreach (IRCompletionListProvider provider in providers)
                {
                    IReadOnlyCollection <RCompletion> entries = provider.GetEntries(context);
                    Debug.Assert(entries != null);

                    if (entries.Count > 0)
                    {
                        completions.AddRange(entries);
                    }
                    sort &= provider.AllowSorting;
                }

                if (sort)
                {
                    completions.Sort(RCompletion.CompareOrdinal);
                    completions.RemoveDuplicates(RCompletion.CompareOrdinal);
                }

                CompletionSet completionSet = new RCompletionSet(session.TextView.TextBuffer, trackingSpan, completions);
                completionSets.Add(completionSet);
            }
        }
        internal void PopulateCompletionList(int position, ICompletionSession session, IList<CompletionSet> completionSets, AstRoot ast) {
            RCompletionContext context = new RCompletionContext(session, _textBuffer, ast, position);

            bool autoShownCompletion = true;
            if (session.TextView.Properties.ContainsProperty(CompletionController.AutoShownCompletion))
                autoShownCompletion = session.TextView.Properties.GetProperty<bool>(CompletionController.AutoShownCompletion);

            IReadOnlyCollection<IRCompletionListProvider> providers =
                RCompletionEngine.GetCompletionForLocation(context, autoShownCompletion);

            Span applicableSpan = GetApplicableSpan(position, session);
            ITrackingSpan trackingSpan = _textBuffer.CurrentSnapshot.CreateTrackingSpan(applicableSpan, SpanTrackingMode.EdgeInclusive);
            List<RCompletion> completions = new List<RCompletion>();
            bool sort = true;

            foreach (IRCompletionListProvider provider in providers) {
                IReadOnlyCollection<RCompletion> entries = provider.GetEntries(context);
                Debug.Assert(entries != null);

                if (entries.Count > 0) {
                    completions.AddRange(entries);
                }
                sort &= provider.AllowSorting;
            }

            if (sort) {
                completions.Sort(RCompletion.Compare);
                completions.RemoveDuplicates();
            }

            CompletionSet completionSet = new RCompletionSet(_textBuffer, trackingSpan, completions);
            completionSets.Add(completionSet);
        }