private bool IsBetter(SignatureHelpItems bestItems, TextSpan currentTextSpan)
        {
            // If we have no best text span, then this span is definitely better.
            if (bestItems == null)
            {
                return(true);
            }

            // Otherwise we want the one that is conceptually the innermost signature.  So it's
            // only better if the distance from it to the caret position is less than the best
            // one so far.
            return(currentTextSpan.Start > bestItems.ApplicableSpan.Start);
        }
Example #2
0
        /// <summary>
        /// Returns <code>null</code> if our work was preempted and we want to return the
        /// previous model we've computed.
        /// </summary>
        private async Task <(ISignatureHelpProvider provider, SignatureHelpItems items)> ComputeItemsAsync(
            ISignatureHelpProvider[] providers,
            int caretPosition,
            SIGHLP.SignatureHelpTriggerInfo triggerInfo,
            Document document,
            CancellationToken cancellationToken)
        {
            ISignatureHelpProvider bestProvider = null;
            SignatureHelpItems     bestItems    = null;

            // TODO(cyrusn): We're calling into extensions, we need to make ourselves resilient
            // to the extension crashing.
            foreach (var provider in providers)
            {
                // If this is a retrigger command, and another retrigger command has already
                // been issued then we can bail out immediately.
                //if (IsNonTypeCharRetrigger(triggerInfo) &&
                //	localRetriggerId != _retriggerId) {
                //	return null;
                //}

                cancellationToken.ThrowIfCancellationRequested();

                var currentItems = await provider.GetItemsAsync(document, caretPosition, triggerInfo, cancellationToken).ConfigureAwait(false);

                if (currentItems != null && currentItems.ApplicableSpan.IntersectsWith(caretPosition))
                {
                    // If another provider provides sig help items, then only take them if they
                    // start after the last batch of items.  i.e. we want the set of items that
                    // conceptually are closer to where the caret position is.  This way if you have:
                    //
                    //  Goo(new Bar($$
                    //
                    // Then invoking sig help will only show the items for "new Bar(" and not also
                    // the items for "Goo(..."
                    if (IsBetter(bestItems, currentItems.ApplicableSpan))
                    {
                        bestItems    = new SignatureHelpItems(currentItems);
                        bestProvider = provider;
                    }
                }
            }

            return(bestProvider, bestItems);
        }
        private static SignatureHelpItem GetSelectedItem(SignatureHelpItems items, ISignatureHelpProvider provider)
        {
            // Try to find the most appropriate item in the list to select by default.

            // If the provider specified one a selected item, then always stick with that one.
            if (items.SelectedItemIndex.HasValue)
            {
                return(items.Items[items.SelectedItemIndex.Value]);
            }

            // If the provider did not pick a default, and it's the same provider as the previous
            // model we have, then try to return the same item that we had before.
            //if (currentModel != null && currentModel.Provider == provider) {
            //	return items.Items.FirstOrDefault(i => DisplayPartsMatch(i, currentModel.SelectedItem)) ?? items.Items.First();
            //}

            // Otherwise, just pick the first item we have.
            return(items.Items.First());
        }
        private async Task <Tuple <ISignatureHelpProvider, SignatureHelpItems> > ComputeItemsAsync(
            IList <ISignatureHelpProvider> providers,
            int caretPosition,
            SIGHLP.SignatureHelpTriggerInfo triggerInfo,
            Document document,
            CancellationToken cancellationToken)
        {
            ISignatureHelpProvider bestProvider = null;
            SignatureHelpItems     bestItems    = null;

            // TODO(cyrusn): We're calling into extensions, we need to make ourselves resilient
            // to the extension crashing.
            foreach (var provider in providers)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var currentItems = await provider.GetItemsAsync(document, caretPosition, triggerInfo, cancellationToken).ConfigureAwait(false);

                if (currentItems != null && currentItems.ApplicableSpan.IntersectsWith(caretPosition))
                {
                    // If another provider provides sig help items, then only take them if they
                    // start after the last batch of items.  i.e. we want the set of items that
                    // conceptually are closer to where the caret position is.  This way if you have:
                    //
                    //  Foo(new Bar($$
                    //
                    // Then invoking sig help will only show the items for "new Bar(" and not also
                    // the items for "Foo(..."
                    if (IsBetter(bestItems, currentItems.ApplicableSpan))
                    {
                        bestItems    = new SignatureHelpItems(currentItems);
                        bestProvider = provider;
                    }
                }
            }

            return(Tuple.Create(bestProvider, bestItems));
        }
Example #5
0
 public SignatureHelpResult(SignatureHelpItems items, SignatureHelpItem selectedItem, int?selectedParameter)
 {
     Items             = items;
     SelectedItem      = selectedItem;
     SelectedParameter = selectedParameter;
 }