コード例 #1
0
        private RichText GetSignatureCore(string[] namedArguments, AnnotationsDisplayKind?showAnnotations, out TextRange[] parameterRanges, out int[] mapToOriginalOrder,
                                          out ExtensionMethodInfo extensionMethodInfo)
        {
            if (showAnnotations == null)
            {
                showAnnotations = _settings.GetValue((ParameterInfoSettings s) => s.ShowAnnotations);
            }

            // TODO: handle named arguments with reordering; currently falling back to non-colored display
            if (namedArguments.Any(s => s != null))
            {
                string signature = _underlyingCandidate.GetSignature(namedArguments, showAnnotations.Value, out parameterRanges, out mapToOriginalOrder, out extensionMethodInfo);
                if (!IsIdentityMap(mapToOriginalOrder))
                {
                    return(signature);
                }
            }

            var                 options            = PresenterOptions.ForParameterInfo(_settings, showAnnotations.Value);
            bool                useReSharperColors = _settings.GetValue(HighlightingSettingsAccessor.IdentifierHighlightingEnabled);
            PresentedInfo       presentedInfo;
            InvocationCandidate invocationCandidate = _underlyingCandidate.InvocationCandidate;
            var                 elementInstance     = new DeclaredElementInstance(invocationCandidate.Element, invocationCandidate.Substitution);

            RichText richText = _colorizerPresenter.TryPresent(elementInstance, options, _underlyingCandidate.Language, useReSharperColors, out presentedInfo);

            if (richText == null)
            {
                return(_underlyingCandidate.GetSignature(namedArguments, showAnnotations.Value, out parameterRanges, out mapToOriginalOrder, out extensionMethodInfo));
            }

            if (presentedInfo.Parameters.Count == 0)
            {
                parameterRanges     = EmptyArray <TextRange> .Instance;
                mapToOriginalOrder  = EmptyArray <int> .Instance;
                extensionMethodInfo = ExtensionMethodInfo.NoExtension;
            }
            else if (presentedInfo.IsExtensionMethod)
            {
                parameterRanges    = presentedInfo.Parameters.Skip(1).ToArray();
                mapToOriginalOrder = CreateIdentityMap(presentedInfo.Parameters.Count - 1);
                TextRange firstParameterRange = presentedInfo.Parameters[0].TrimLeft(5);                 // keeps "this " highlighted with the keyword color
                extensionMethodInfo = new ExtensionMethodInfo(firstParameterRange, TextRange.InvalidRange);
            }
            else
            {
                parameterRanges     = presentedInfo.Parameters.ToArray();
                mapToOriginalOrder  = CreateIdentityMap(presentedInfo.Parameters.Count);
                extensionMethodInfo = ExtensionMethodInfo.NoExtension;
            }

            return(richText);
        }
コード例 #2
0
        public RichText GetSignature(
            string[] namedArguments,
            AnnotationsDisplayKind showAnnotations,
            out TextRange[] parameterRanges,
            out int[] mapToOriginalOrder,
            out ExtensionMethodInfo extensionMethodInfo)
        {
            // TODO: handle named arguments with reordering; currently falling back to non-colored display
            if (namedArguments.Any(s => s != null))
            {
                string signature = UnderlyingCandidate.GetSignature(namedArguments, showAnnotations, out parameterRanges, out mapToOriginalOrder, out extensionMethodInfo);
                if (!IsIdentityMap(mapToOriginalOrder))
                {
                    return(signature);
                }
            }

            var                 options = PresenterOptions.ForParameterInfo(_settings, showAnnotations);
            var                 highlighterIdProvider = _highlighterIdProviderFactory.CreateProvider(_settings);
            PresentedInfo       presentedInfo;
            InvocationCandidate invocationCandidate = UnderlyingCandidate.InvocationCandidate;
            var                 elementInstance     = new DeclaredElementInstance(invocationCandidate.Element, invocationCandidate.Substitution);

            RichText richText = _colorizerPresenter.TryPresent(elementInstance, options, UnderlyingCandidate.Language, highlighterIdProvider, out presentedInfo);

            if (richText == null)
            {
                return(UnderlyingCandidate.GetSignature(namedArguments, showAnnotations, out parameterRanges, out mapToOriginalOrder, out extensionMethodInfo));
            }

            if (presentedInfo.Parameters.Count == 0)
            {
                parameterRanges     = EmptyArray <TextRange> .Instance;
                mapToOriginalOrder  = EmptyArray <int> .Instance;
                extensionMethodInfo = ExtensionMethodInfo.NoExtension;
            }
            else if (presentedInfo.IsExtensionMethod && UnderlyingCandidate.InvocationCandidate.IsExtensionMethod)
            {
                parameterRanges    = presentedInfo.Parameters.Skip(1).ToArray();
                mapToOriginalOrder = CreateOffsetMap(presentedInfo.Parameters.Count - 1, 1);
                TextRange firstParameterRange = presentedInfo.Parameters[0].TrimLeft(5);                 // keeps "this " highlighted with the keyword color
                extensionMethodInfo = new ExtensionMethodInfo(firstParameterRange, TextRange.InvalidRange);
            }
            else
            {
                parameterRanges     = presentedInfo.Parameters.ToArray();
                mapToOriginalOrder  = CreateOffsetMap(presentedInfo.Parameters.Count, 0);
                extensionMethodInfo = ExtensionMethodInfo.NoExtension;
            }

            return(richText);
        }
        protected override RichText TryGetSignatureCore(
            PresenterOptions options,
            HighlighterIdProvider highlighterIdProvider,
            out TextRange[] parameterRanges,
            out int[] mapToOriginalOrder,
            out ExtensionMethodInfo extensionMethodInfo)
        {
            parameterRanges     = EmptyArray <TextRange> .Instance;
            mapToOriginalOrder  = EmptyArray <int> .Instance;
            extensionMethodInfo = ExtensionMethodInfo.NoExtension;

            InvocationCandidate invocationCandidate = UnderlyingCandidate.InvocationCandidate;
            var      elementInstance = new DeclaredElementInstance(invocationCandidate.Element, invocationCandidate.Substitution);
            RichText richText        = _colorizerPresenter.TryPresent(elementInstance, options, UnderlyingCandidate.Language, highlighterIdProvider, null, out PresentedInfo presentedInfo);

            if (richText == null)
            {
                return(null);
            }

            if (presentedInfo.Parameters.Count > 0)
            {
                if (presentedInfo.IsExtensionMethod && UnderlyingCandidate.InvocationCandidate.IsExtensionMethodInvocation)
                {
                    parameterRanges     = presentedInfo.Parameters.Skip(1).ToArray();
                    mapToOriginalOrder  = CreateIdentityMap(presentedInfo.Parameters.Count - 1);
                    extensionMethodInfo = new ExtensionMethodInfo(presentedInfo.Parameters[0], TextRange.InvalidRange);
                }
                else
                {
                    parameterRanges    = presentedInfo.Parameters.ToArray();
                    mapToOriginalOrder = CreateIdentityMap(presentedInfo.Parameters.Count);
                }
            }

            return(richText);
        }