private void ComputeCurrentParameter()
 {
     if (this.provider.SignatureHelpBroker.IsSignatureHelpActive(this.textView))
     {
         foreach (var session in this.provider.SignatureHelpBroker.GetSessions(this.textView))
         {
             // Re-compute the "current" parameter.  This functionality isn't baked in
             // to the ISignature interface, unfortunately.
             ReplacementSignature replacementSignature = session.SelectedSignature as ReplacementSignature;
             if (replacementSignature != null)
             {
                 replacementSignature.ComputeCurrentParameter(this.textView.Caret.Position.BufferPosition);
             }
         }
     }
 }
Exemple #2
0
        public ISignature GetBestMatch(ISignatureHelpSession session)
        {
            if (session.Signatures == null || session.Signatures.Count == 0)
            {
                return(null);
            }

            List <ClassificationSpan> replacementSpans = this.GetReplacementSpans(session);

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

            ////ITrackingSpan applicableToSpan = completionSession.Signatures[0].ApplicableToSpan;
            // TODO: get the classifications for the span, and determine the best match...
            ////string text = applicableToSpan.GetText(applicableToSpan.TextBuffer.CurrentSnapshot);
            ClassificationSpan typeSpan      = replacementSpans.FirstOrDefault(s => s.ClassificationType.IsOfType(TypeConstants.ReplacementType));
            ClassificationSpan positionSpan  = replacementSpans.FirstOrDefault(s => s.ClassificationType.IsOfType(TypeConstants.ReplacementPosition));
            ClassificationSpan nameSpan      = replacementSpans.FirstOrDefault(s => s.ClassificationType.IsOfType(TypeConstants.ReplacementName));
            ClassificationSpan alignmentSpan = replacementSpans.FirstOrDefault(s => s.ClassificationType.IsOfType(TypeConstants.ReplacementAlignment));
            ClassificationSpan formatSpan    = replacementSpans.FirstOrDefault(s => s.ClassificationType.IsOfType(TypeConstants.ReplacementFormat));

            bool hasType      = typeSpan != null;
            bool hasPosition  = positionSpan != null;
            bool hasAlignment = alignmentSpan != null;
            bool hasFormat    = formatSpan != null;

            // Even if some of the optional values aren't present, the delimiters around them are enough to clue us in...
            if (!hasType && !hasPosition &&
                replacementSpans.Skip(1).Take(1).Any(s => "[" == s.Span.GetText()))
            {
                hasType = true;
            }
            else if (hasType && !hasPosition &&
                     replacementSpans.ElementsAfter(typeSpan).Take(1).Any(s => "," == s.Span.GetText()))
            {
                hasPosition = true;
            }

            if (!hasAlignment &&
                replacementSpans.ElementsAfter(nameSpan).Any(s => "," == s.Span.GetText()))
            {
                hasAlignment = true;
            }

            if (!hasFormat &&
                replacementSpans.ElementsAfter(nameSpan).Any(s => ":" == s.Span.GetText()))
            {
                hasFormat = true;
            }

            int signatureKey = ReplacementSignature.CalculateSignatureKey(hasType, hasPosition, hasAlignment, hasFormat);

            ISignature match = session.Signatures.FirstOrDefault(s =>
            {
                if (s is ReplacementSignature)
                {
                    return(((ReplacementSignature)s).SignatureKey == signatureKey);
                }

                return(false);
            });

            return(match);
        }
Exemple #3
0
        public void ComputeCurrentParameter(SnapshotPoint point)
        {
            if (this.Parameters.Count == 0)
            {
                this.CurrentParameter = null;
                return;
            }

            List <ClassificationSpan> replacementSpans = this.source.GetReplacementSpans(this.session);

            if (replacementSpans == null || replacementSpans.Count == 0)
            {
                this.CurrentParameter = null;
                return;
            }

            ClassificationSpan span = replacementSpans.FirstOrDefault(s => s.Span.Contains(point - 1));

            if (span == null)
            {
                this.CurrentParameter = null;
                return;
            }

            ClassificationSpan nameSpan = replacementSpans.FirstOrDefault(s => s.ClassificationType.IsOfType(TypeConstants.ReplacementName));

            bool inType      = false;
            bool inPosition  = false;
            bool inAlignment = false;
            bool inFormat    = false;

            if (span.ClassificationType.IsOfType(TypeConstants.ReplacementType) ||
                "[" == span.Span.GetText() && !replacementSpans.ElementsAfter(nameSpan).Contains(span))
            {
                inType = true;
            }
            else if (span.ClassificationType.IsOfType(TypeConstants.ReplacementPosition) ||
                     "," == span.Span.GetText() && !replacementSpans.ElementsAfter(nameSpan).Contains(span))
            {
                inPosition = true;
            }
            else if (span.ClassificationType.IsOfType(TypeConstants.ReplacementAlignment) ||
                     "," == span.Span.GetText() && replacementSpans.ElementsAfter(nameSpan).Contains(span))
            {
                inAlignment = true;
            }
            else if (span.ClassificationType.IsOfType(TypeConstants.ReplacementFormat) ||
                     ":" == span.Span.GetText() && replacementSpans.ElementsAfter(nameSpan).Contains(span))
            {
                inFormat = true;
            }

            int signatureKey = ReplacementSignature.CalculateSignatureKey(inType, inPosition, inAlignment, inFormat);

            IParameter match = this.Parameters.FirstOrDefault(p =>
            {
                if (p is ReplacementParameter)
                {
                    return(((ReplacementParameter)p).SignatureKey == signatureKey);
                }

                return(false);
            });

            this.CurrentParameter = match;
        }