Exemplo n.º 1
0
        public Model(
            DisconnectedBufferGraph disconnectedBufferGraph,
            TextSpan textSpan,
            ISignatureHelpProvider provider,
            IList<SignatureHelpItem> items,
            SignatureHelpItem selectedItem,
            int argumentIndex,
            int argumentCount,
            string argumentName,
            int? selectedParameter)
        {
            Contract.ThrowIfNull(selectedItem);
            Contract.ThrowIfFalse(items.Count != 0, "Must have at least one item.");
            Contract.ThrowIfFalse(items.Contains(selectedItem), "Selected item must be in list of items.");

            _disconnectedBufferGraph = disconnectedBufferGraph;
            this.TextSpan = textSpan;
            this.Items = items;
            this.Provider = provider;
            this.SelectedItem = selectedItem;
            this.ArgumentIndex = argumentIndex;
            this.ArgumentCount = argumentCount;
            this.ArgumentName = argumentName;
            this.SelectedParameter = selectedParameter;
        }
Exemplo n.º 2
0
 public SignatureHelpItem(SIGHLP.SignatureHelpItem signatureHelpItem)
 {
     if (signatureHelpItem == null)
     {
         throw new ArgumentNullException(nameof(signatureHelpItem));
     }
     this.signatureHelpItem = signatureHelpItem;
 }
Exemplo n.º 3
0
        public Signature(ITrackingSpan applicableToSpan, SignatureHelpItem signatureHelpItem, int selectedParameterIndex)
        {
            if (selectedParameterIndex < -1 || selectedParameterIndex >= signatureHelpItem.Parameters.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(selectedParameterIndex));
            }

            this.ApplicableToSpan = applicableToSpan;
            _signatureHelpItem = signatureHelpItem;
            _parameterIndex = selectedParameterIndex;
        }
 public static SignatureHelpSelection GetSelection(
     IList<SignatureHelpItem> items,
     SignatureHelpItem selectedItem,
     int argumentIndex,
     int argumentCount,
     string argumentName,
     bool isCaseSensitive)
 {
     var bestItem = GetBestItem(selectedItem, items, argumentIndex, argumentCount, argumentName, isCaseSensitive);
     var selectedParameter = GetSelectedParameter(bestItem, argumentIndex, argumentName, isCaseSensitive);
     return new SignatureHelpSelection(bestItem, selectedParameter);
 }
                private static int GetSelectedParameter(SignatureHelpItem bestItem, int parameterIndex, string parameterName, bool isCaseSensitive)
                {
                    if (parameterName != null)
                    {
                        var comparer = isCaseSensitive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase;
                        var index = bestItem.Parameters.IndexOf(p => comparer.Equals(p.Name, parameterName));
                        if (index >= 0)
                        {
                            return index;
                        }
                    }

                    return parameterIndex;
                }
Exemplo n.º 6
0
        private SignatureHelpItem UpdateItem(SignatureHelpItem item, SupportedPlatformData platformData, ISymbol symbol)
        {
            var platformParts = platformData.ToDisplayParts().ToTaggedText();

            if (platformParts.Length == 0)
            {
                return(item);
            }

            var startingNewLine = new List <TaggedText>();

            startingNewLine.AddLineBreak();

            var concatted          = startingNewLine.Concat(platformParts);
            var updatedDescription = item.DescriptionParts.IsDefault
                ? concatted
                : item.DescriptionParts.Concat(concatted);

            item.DescriptionParts = updatedDescription.ToImmutableArrayOrEmpty();
            return(item);
        }
                private static SignatureHelpItem GetBestItem(
                    SignatureHelpItem currentItem, IList<SignatureHelpItem> filteredItems, int selectedParameter, int argumentCount, string name, bool isCaseSensitive)
                {
                    // If the current item is still applicable, then just keep it.
                    if (filteredItems.Contains(currentItem) &&
                        IsApplicable(currentItem, argumentCount, name, isCaseSensitive))
                    {
                        return currentItem;
                    }

                    // Try to find the first applicable item.  If there is none, then that means the
                    // selected parameter was outside the bounds of all methods.  i.e. all methods only
                    // went up to 3 parameters, and selected parameter is 3 or higher.  In that case,
                    // just pick the very last item as it is closest in parameter count.
                    var result = filteredItems.FirstOrDefault(i => IsApplicable(i, argumentCount, name, isCaseSensitive));
                    if (result != null)
                    {
                        return result;
                    }

                    // if we couldn't find a best item, and they provided a name, then try again without
                    // a name.
                    if (name != null)
                    {
                        return GetBestItem(currentItem, filteredItems, selectedParameter, argumentCount, null, isCaseSensitive);
                    }

                    // If we don't have an item that can take that number of parameters, then just pick
                    // the last item.  Or stick with the current item if the last item isn't any better.
                    var lastItem = filteredItems.Last();
                    if (currentItem.IsVariadic || currentItem.Parameters.Length == lastItem.Parameters.Length)
                    {
                        return currentItem;
                    }

                    return lastItem;
                }
 private static bool Include(SignatureHelpItem item, IEnumerable<string> parameterNames)
 {
     var itemParameterNames = item.Parameters.Select(p => p.Name).ToSet();
     return parameterNames.All(itemParameterNames.Contains);
 }
        private SignatureHelpItem UpdateItem(SignatureHelpItem item, SupportedPlatformData platformData, ISymbol symbol)
        {
            var platformParts = platformData.ToDisplayParts();
            if (platformParts.Count == 0)
            {
                return item;
            }

            var startingNewLine = new List<SymbolDisplayPart>();
            startingNewLine.AddLineBreak();

            var updatedDescription = item.DescriptionParts == null
                ? item.DescriptionParts.Concat(startingNewLine.Concat(platformParts))
                : startingNewLine.Concat(platformParts);

            item.DescriptionParts = updatedDescription.ToImmutableArrayOrEmpty();
            return item;
        }
        private SignatureHelpItem UpdateItem(SignatureHelpItem item, SupportedPlatformData platformData, ISymbol symbol)
        {
            var platformParts = platformData.ToDisplayParts().ToTaggedText();
            if (platformParts.Length == 0)
            {
                return item;
            }

            var startingNewLine = new List<TaggedText>();
            startingNewLine.AddLineBreak();

            var concatted = startingNewLine.Concat(platformParts);
            var updatedDescription = item.DescriptionParts.IsDefault
                ? concatted
                : item.DescriptionParts.Concat(concatted);

            item.DescriptionParts = updatedDescription.ToImmutableArrayOrEmpty();
            return item;
        }
            private static int GetParameterIndexForItem(SignatureHelpItem item, int? selectedParameter)
            {
                if (selectedParameter.HasValue)
                {
                    if (selectedParameter.Value < item.Parameters.Length)
                    {
                        // If the selected parameter is within the range of parameters of this item then set
                        // that as the current parameter.
                        return selectedParameter.Value;
                    }
                    else if (item.IsVariadic)
                    {
                        // It wasn't in range, but the item takes an unlimited number of parameters.  So
                        // just set current parameter to the last parameter (the variadic one).
                        return item.Parameters.Length - 1;
                    }
                }

                // It was out of bounds, there is no current parameter now.
                return -1;
            }
 public SignatureHelpSelection(SignatureHelpItem selectedItem, int? selectedParameter) : this()
 {
     _selectedItem = selectedItem;
     _selectedParameter = selectedParameter;
 }
Exemplo n.º 13
0
 public Model WithSelectedItem(SignatureHelpItem selectedItem)
 {
     return selectedItem == this.SelectedItem
         ? this
         : new Model(_disconnectedBufferGraph, TextSpan, Provider, Items, selectedItem, ArgumentIndex, ArgumentCount, ArgumentName, SelectedParameter);
 }
Exemplo n.º 14
0
        private SignatureHelpItem FixAnonymousTypeParts(
            ISymbol orderSymbol, SignatureHelpItem item, SemanticModel semanticModel, int position, ISymbolDisplayService symbolDisplayService, IAnonymousTypeDisplayService anonymousTypeDisplayService)
        {
            var currentItem = new SymbolKeySignatureHelpItem(
                orderSymbol, item.IsVariadic, item.DocumentationFactory,
                anonymousTypeDisplayService.InlineDelegateAnonymousTypes(item.PrefixDisplayParts, semanticModel, position, symbolDisplayService),
                anonymousTypeDisplayService.InlineDelegateAnonymousTypes(item.SeparatorDisplayParts, semanticModel, position, symbolDisplayService),
                anonymousTypeDisplayService.InlineDelegateAnonymousTypes(item.SuffixDisplayParts, semanticModel, position, symbolDisplayService),
                item.Parameters.Select(p => InlineDelegateAnonymousTypes(p, semanticModel, position, symbolDisplayService, anonymousTypeDisplayService)),
                item.DescriptionParts);

            var directAnonymousTypeReferences =
                    from part in currentItem.GetAllParts()
                    where part.Symbol.IsNormalAnonymousType()
                    select (INamedTypeSymbol)part.Symbol;

            var info = anonymousTypeDisplayService.GetNormalAnonymousTypeDisplayInfo(
                orderSymbol, directAnonymousTypeReferences, semanticModel, position, symbolDisplayService);

            if (info.AnonymousTypesParts.Count > 0)
            {
                var anonymousTypeParts = new List<SymbolDisplayPart>
                {
                    new SymbolDisplayPart(SymbolDisplayPartKind.Space, null, "\r\n\r\n")
                };

                anonymousTypeParts.AddRange(info.AnonymousTypesParts);

                currentItem = new SymbolKeySignatureHelpItem(
                    orderSymbol,
                    currentItem.IsVariadic,
                    currentItem.DocumentationFactory,
                    info.ReplaceAnonymousTypes(currentItem.PrefixDisplayParts),
                    info.ReplaceAnonymousTypes(currentItem.SeparatorDisplayParts),
                    info.ReplaceAnonymousTypes(currentItem.SuffixDisplayParts),
                    currentItem.Parameters.Select(p => ReplaceAnonymousTypes(p, info)),
                    anonymousTypeParts);
            }

            return currentItem;
        }
                private static bool IsApplicable(SignatureHelpItem item, int argumentCount, string name, bool isCaseSensitive)
                {
                    // If they provided a name, then the item is only valid if it has a parameter that
                    // matches that name.
                    if (name != null)
                    {
                        var comparer = isCaseSensitive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase;
                        return item.Parameters.Any(p => comparer.Equals(p.Name, name));
                    }

                    // An item is applicable if it has at least as many parameters as the selected
                    // parameter index.  i.e. if it has 2 parameters and we're at index 0 or 1 then it's
                    // applicable.  However, if it has 2 parameters and we're at index 2, then it's not
                    // applicable.  
                    if (item.Parameters.Length >= argumentCount)
                    {
                        return true;
                    }

                    // However, if it is variadic then it is applicable as it can take any number of
                    // items.
                    if (item.IsVariadic)
                    {
                        return true;
                    }

                    // Also, we special case 0.  that's because if the user has "Foo(" and foo takes no
                    // arguments, then we'll see that it's arg count is 0.  We still want to consider
                    // any item applicable here though.
                    return argumentCount == 0;
                }
Exemplo n.º 16
0
        private static bool Include(SignatureHelpItem item, IEnumerable <string> parameterNames)
        {
            var itemParameterNames = item.Parameters.Select(p => p.Name).ToSet();

            return(parameterNames.All(itemParameterNames.Contains));
        }
 private static bool DisplayPartsMatch(SignatureHelpItem i1, SignatureHelpItem i2)
 {
     return i1.GetAllParts().SequenceEqual(i2.GetAllParts(), CompareParts);
 }
            public void PresentItems(
                ITrackingSpan triggerSpan,
                IList<SignatureHelpItem> signatureHelpItems,
                SignatureHelpItem selectedItem,
                int? selectedParameter)
            {
                _signatureHelpItems = signatureHelpItems;
                _selectedItem = selectedItem;

                // Create all the editor signatures for the sig help items we have.
                this.CreateSignatures(triggerSpan, selectedParameter);

                // It's a new list of items.  Either create the editor session if this is the
                // first time, or ask the editor session that we already have to recalculate.
                if (_editorSessionOpt == null)
                {
                    // We're tracking the caret.  Don't have the editor do it. 
                    _editorSessionOpt = _sigHelpBroker.CreateSignatureHelpSession(
                        _textView,
                        triggerSpan.GetStartTrackingPoint(PointTrackingMode.Negative),
                        trackCaret: false);

                    var debugTextView = _textView as IDebuggerTextView;
                    if (debugTextView != null && !debugTextView.IsImmediateWindow)
                    {
                        debugTextView.HACK_StartCompletionSession(_editorSessionOpt);
                    }

                    _editorSessionOpt.Dismissed += (s, e) => OnEditorSessionDismissed();
                    _editorSessionOpt.SelectedSignatureChanged += OnSelectedSignatureChanged;
                }

                // So here's the deal.  We cannot create the editor session and give it the right
                // signatures (even though we know what they are).  Instead, the session with
                // call back into the ISignatureHelpSourceProvider (which is us) to get those
                // values. It will pass itself along with the calls back into
                // ISignatureHelpSourceProvider. So, in order to make that connection work, we
                // add properties to the session so that we can call back into ourselves, get
                // the signatures and add it to the session.
                if (!_editorSessionOpt.Properties.ContainsProperty(s_augmentSessionKey))
                {
                    _editorSessionOpt.Properties.AddProperty(s_augmentSessionKey, this);
                }

                try
                {
                    // Don't want to get any callbacks while we do this.
                    _ignoreSelectionStatusChangedEvent = true;

                    _editorSessionOpt.Recalculate();

                    // Now let the editor know what the currently selected item is.
                    Contract.Requires(_signatureMap.ContainsKey(selectedItem));
                    Contract.ThrowIfNull(_signatureMap);

                    var defaultValue = _signatureMap.GetValueOrDefault(_selectedItem);
                    if (_editorSessionOpt != null)
                    {
                        _editorSessionOpt.SelectedSignature = defaultValue;
                    }
                }
                finally
                {
                    _ignoreSelectionStatusChangedEvent = false;
                }
            }
Exemplo n.º 19
0
		public SignatureHelpResult(SignatureHelpItems items, SignatureHelpItem selectedItem, int? selectedParameter) {
			Items = items;
			SelectedItem = selectedItem;
			SelectedParameter = selectedParameter;
		}