public RichText TryPresent(
            [NotNull] DeclaredElementInstance declaredElementInstance,
            [NotNull] PresenterOptions options,
            [NotNull] PsiLanguageType languageType,
            [NotNull] HighlighterIdProvider highlighterIdProvider)
        {
            PresentedInfo presentedInfo;

            return(TryPresent(declaredElementInstance, options, languageType, highlighterIdProvider, out presentedInfo));
        }
 private IColorizer TryCreateColorizer([NotNull] RichText richText, [NotNull] PresenterOptions options,
                                       [NotNull] PsiLanguageType languageType, [NotNull] PresentedInfo presentedInfo)
 {
     // TODO: remove constructor parameters and resolve as a language service
     if (languageType.Is <CSharpLanguage>())
     {
         return(new CSharpColorizer(richText, options, presentedInfo, _textStyleHighlighterManager, _codeAnnotationsCache));
     }
     return(null);
 }
Example #3
0
        public CSharpColorizer([NotNull] RichText richText, [NotNull] PresenterOptions options,
                               [NotNull] PresentedInfo presentedInfo, [NotNull] TextStyleHighlighterManager textStyleHighlighterManager,
                               [NotNull] CodeAnnotationsCache codeAnnotationsCache)
        {
            Debug.Assert(codeAnnotationsCache != null, "codeAnnotationsCache != null");

            _richText      = richText;
            _options       = options;
            _presentedInfo = presentedInfo;
            _textStyleHighlighterManager = textStyleHighlighterManager;
            _codeAnnotationsCache        = codeAnnotationsCache;
        }
Example #4
0
        public static PresentedInfo TryAppendDeclaredElement(
            [NotNull] this IColorizer colorizer,
            [CanBeNull] IDeclaredElement element,
            [CanBeNull] ISubstitution substitution,
            [NotNull] PresenterOptions options)
        {
            if (element == null || substitution == null)
            {
                return(new PresentedInfo());
            }

            return(colorizer.AppendDeclaredElement(element, substitution, options));
        }
        public static PresentedInfo TryAppendDeclaredElement(
            this IColorizer colorizer,
            IDeclaredElement?element,
            ISubstitution?substitution,
            PresenterOptions options,
            ITreeNode?contextualNode)
        {
            if (element is null || substitution is null)
            {
                return(new PresentedInfo());
            }

            return(colorizer.AppendDeclaredElement(element, substitution, options, contextualNode));
        }
Example #6
0
        private void AppendElementKind([CanBeNull] IDeclaredElement element, Context context, bool stylized)
        {
            PresenterOptions options = context.Options;
            string           kind    = element.GetElementKindString(
                options.UseExtensionMethodKind, options.UseAttributeClassKind, options.UseClassModifiersInKind, options.UseMethodModifiersInKind);

            if (stylized)
            {
                AppendText("(" + kind + ") ", new TextStyle(FontStyle.Italic));
            }
            else
            {
                AppendText(kind + " ", null);
            }
        }
Example #7
0
        public RichText?TryPresent(
            ITreeNode presentableNode,
            PresenterOptions options,
            PsiLanguageType languageType,
            HighlighterIdProvider highlighterIdProvider)
        {
            var richText = new RichText();

            if (TryCreateColorizer(richText, languageType, highlighterIdProvider) is { } colorizer)
            {
                colorizer.AppendPresentableNode(presentableNode, options);
                return(richText);
            }

            return(null);
        }
        public RichText TryPresent(
            [NotNull] ITreeNode presentableNode,
            [NotNull] PresenterOptions options,
            [NotNull] PsiLanguageType languageType,
            [NotNull] HighlighterIdProvider highlighterIdProvider)
        {
            var        richText  = new RichText();
            IColorizer colorizer = TryCreateColorizer(richText, languageType, highlighterIdProvider);

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

            colorizer.AppendPresentableNode(presentableNode, options);
            return(richText);
        }
Example #9
0
        /// <summary>
        /// Presents a given <see cref="DeclaredElementInstance"/> using a colorizer.
        /// </summary>
        /// <param name="declaredElementInstance">The declared element instance.</param>
        /// <param name="options">The options to use to present the element.</param>
        /// <param name="languageType">The type of language used to present the element.</param>
        /// <param name="highlighterIdProvider">An object determining which highlightings to use.</param>
        /// <param name="contextualNode">The tree node where the element is presented.</param>
        /// <param name="presentedInfo">When the method returns, a <see cref="PresentedInfo"/> containing range information about the presented element.</param>
        /// <returns>A <see cref="RichText"/> representing <paramref name="declaredElementInstance"/>.</returns>
        public RichText?TryPresent(
            DeclaredElementInstance declaredElementInstance,
            PresenterOptions options,
            PsiLanguageType languageType,
            HighlighterIdProvider highlighterIdProvider,
            ITreeNode?contextualNode,
            out PresentedInfo presentedInfo)
        {
            var richText = new RichText();

            if (TryCreateColorizer(richText, languageType, highlighterIdProvider) is { } colorizer)
            {
                presentedInfo = colorizer.AppendDeclaredElement(declaredElementInstance.Element, declaredElementInstance.Substitution, options, contextualNode);
                return(richText);
            }

            presentedInfo = new PresentedInfo();
            return(null);
        }
        public RichText TryPresent(
            [NotNull] DeclaredElementInstance declaredElementInstance,
            [NotNull] PresenterOptions options,
            [NotNull] PsiLanguageType languageType,
            [NotNull] HighlighterIdProvider highlighterIdProvider,
            [CanBeNull] ITreeNode contextualNode,
            [NotNull] out PresentedInfo presentedInfo)
        {
            var        richText  = new RichText();
            IColorizer colorizer = TryCreateColorizer(richText, languageType, highlighterIdProvider);

            if (colorizer == null)
            {
                presentedInfo = new PresentedInfo();
                return(null);
            }

            presentedInfo = colorizer.AppendDeclaredElement(declaredElementInstance.Element, declaredElementInstance.Substitution, options, contextualNode);
            return(richText);
        }
Example #11
0
        private void AppendParameter([NotNull] IParameter parameter, [NotNull] ISubstitution substitution, Context context)
        {
            if (parameter.IsVarArg)
            {
                AppendText("__arglist", VsHighlightingAttributeIds.Keyword);
                return;
            }

            string modifier = GetParameterModifier(parameter);

            if (!modifier.IsEmpty())
            {
                AppendText(modifier + " ", VsHighlightingAttributeIds.Keyword);
                if (context.PresentedInfo != null && modifier == "this")
                {
                    context.PresentedInfo.IsExtensionMethod = true;
                }
            }

            PresenterOptions options = context.Options;

            AppendAnnotations(parameter, options.ShowParametersAnnotations);

            if (options.ShowParametersType)
            {
                AppendElementType(parameter, substitution, QualifierDisplays.Parameters, null, options.ShowParametersName ? " " : null, context);
            }

            if (options.ShowParametersName)
            {
                string highlighterId = _useReSharperColors
                                        ? HighlightingAttributeIds.PARAMETER_IDENTIFIER_ATTRIBUTE
                                        : VsHighlightingAttributeIds.Identifier;
                AppendText(FormatShortName(parameter.ShortName), highlighterId);
            }

            if (options.ShowDefaultValues)
            {
                AppendDefaultValue(parameter, substitution, context);
            }
        }
Example #12
0
        private void AppendParameter([NotNull] IParameter parameter, [NotNull] ISubstitution substitution, Context context)
        {
            if (parameter.IsVarArg)
            {
                AppendText("__arglist", _highlighterIdProvider.Keyword);
                return;
            }

            string modifier = GetParameterModifier(parameter);

            if (!modifier.IsEmpty())
            {
                AppendText(modifier + " ", _highlighterIdProvider.Keyword);
                if (context.PresentedInfo != null && modifier == "this")
                {
                    context.PresentedInfo.IsExtensionMethod = true;
                }
            }

            PresenterOptions options = context.Options;

            AppendAnnotations(parameter, options.ShowParametersAnnotations);

            if (options.ShowParametersType)
            {
                AppendElementType(parameter, substitution, QualifierDisplays.Parameters, null, options.ShowParametersName ? " " : null, context);
            }

            if (options.ShowParametersName)
            {
                AppendText(FormatShortName(parameter.ShortName), _highlighterIdProvider.Parameter);
            }

            if (options.ShowDefaultValues)
            {
                AppendDefaultValue(parameter, substitution, context);
            }
        }
		public PresentedInfo AppendDeclaredElement(IDeclaredElement element, ISubstitution substitution, PresenterOptions options) {
			var context = new Context(options, new PresentedInfo());

			if (!IsClrPresentableElement(element))
				return context.PresentedInfo;

			if (options.ShowElementKind)
				AppendElementKindStylized(element);

			if (options.ShowAccessRights)
				AppendAccessRights(element, true);
			if (options.ShowModifiers)
				AppendModifiers(element);

			var attributesSet = element as IAttributesSet;
			if (attributesSet != null)
				AppendAnnotations(attributesSet, options.ShowElementAnnotations);

			if (options.ShowElementType == ElementTypeDisplay.Before)
				AppendElementType(element, substitution, QualifierDisplays.ElementType, null, " ", context);

			if (options.ShowName)
				AppendNameWithContainer(element, substitution, context);
			if (options.ShowParametersType || options.ShowParametersName)
				AppendParameters(element, substitution, true, context);

			if (options.ShowElementType == ElementTypeDisplay.After)
				AppendElementType(element, substitution, QualifierDisplays.ElementType, ":", null, context);

			if (options.ShowConstantValue) {
				var constantValueOwner = element as IConstantValueOwner;
				if (constantValueOwner != null)
					AppendConstantValue(constantValueOwner);
			}

			return context.PresentedInfo;
		}
Example #14
0
        public PresentedInfo AppendDeclaredElement(IDeclaredElement element, ISubstitution substitution, PresenterOptions options)
        {
            var context = new Context(options, new PresentedInfo());

            if (!IsClrPresentableElement(element))
            {
                return(context.PresentedInfo);
            }

            if (options.ShowElementKind != ElementKindDisplay.None)
            {
                AppendElementKind(element, context, options.ShowElementKind == ElementKindDisplay.Stylized);
            }

            if (options.ShowAccessRights)
            {
                AppendAccessRights(element, true);
            }
            if (options.ShowModifiers)
            {
                AppendModifiers(element);
            }

            var attributesSet = element as IAttributesSet;

            if (attributesSet != null)
            {
                AppendAnnotations(attributesSet, options.ShowElementAnnotations);
            }

            if (options.ShowElementType == ElementTypeDisplay.Before)
            {
                AppendElementType(element, substitution, QualifierDisplays.ElementType, null, " ", context);
            }

            if (options.ShowName)
            {
                AppendNameWithContainer(element, substitution, context);
            }
            if (options.ShowParametersType || options.ShowParametersName)
            {
                AppendParameters(element, substitution, true, context);
            }

            if (options.ShowElementType == ElementTypeDisplay.After)
            {
                AppendElementType(element, substitution, QualifierDisplays.ElementType, ":", null, context);
            }

            if (options.ShowConstantValue)
            {
                var constantValueOwner = element as IConstantValueOwner;
                if (constantValueOwner != null)
                {
                    AppendConstantValue(constantValueOwner, true);
                }
            }

            return(context.PresentedInfo);
        }
Example #15
0
 public Context([NotNull] PresenterOptions options, [CanBeNull] PresentedInfo presentedInfo)
 {
     Options       = options;
     PresentedInfo = presentedInfo;
 }
Example #16
0
        public void AppendExpressionType([CanBeNull] IExpressionType expressionType, bool appendModuleName, [NotNull] PresenterOptions options)
        {
            if (expressionType == null)
            {
                return;
            }

            IType itype = expressionType.ToIType();

            if (itype != null)
            {
                AppendTypeWithoutModule(itype, QualifierDisplays.Everywhere, new Context(options, null));
                if (appendModuleName)
                {
                    AppendModuleName(itype);
                }
                return;
            }

            AppendText(expressionType.GetLongPresentableName(CSharpLanguage.Instance), null);
        }
        public RichText TryPresent([NotNull] DeclaredElementInstance declaredElementInstance, [NotNull] PresenterOptions options,
                                   [NotNull] PsiLanguageType languageType, [CanBeNull] string nameHighlightingAttributeId)
        {
            PresentedInfo presentedInfo;

            return(TryPresent(declaredElementInstance, options, languageType, nameHighlightingAttributeId, out presentedInfo));
        }
        public RichText TryPresent([NotNull] DeclaredElementInstance declaredElementInstance, [NotNull] PresenterOptions options,
                                   [NotNull] PsiLanguageType languageType, [CanBeNull] string nameHighlightingAttributeId, [NotNull] out PresentedInfo presentedInfo)
        {
            var richText = new RichText();

            presentedInfo = new PresentedInfo();
            IColorizer colorizer = TryCreateColorizer(richText, options, languageType, presentedInfo);

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

            colorizer.AppendDeclaredElement(declaredElementInstance.Element, declaredElementInstance.Substitution, nameHighlightingAttributeId);
            return(richText);
        }
Example #19
0
        public RichText TryPresent([NotNull] DeclaredElementInstance declaredElementInstance, [NotNull] PresenterOptions options,
                                   [NotNull] PsiLanguageType languageType, bool useReSharperColors, [NotNull] out PresentedInfo presentedInfo)
        {
            var        richText  = new RichText();
            IColorizer colorizer = TryCreateColorizer(richText, languageType, useReSharperColors);

            if (colorizer == null)
            {
                presentedInfo = new PresentedInfo();
                return(null);
            }

            presentedInfo = colorizer.AppendDeclaredElement(declaredElementInstance.Element, declaredElementInstance.Substitution, options);
            return(richText);
        }
Example #20
0
        public RichText TryPresent([NotNull] DeclaredElementInstance declaredElementInstance, [NotNull] PresenterOptions options,
                                   [NotNull] PsiLanguageType languageType, bool useReSharperColors)
        {
            PresentedInfo presentedInfo;

            return(TryPresent(declaredElementInstance, options, languageType, useReSharperColors, out presentedInfo));
        }
			public Context([NotNull] PresenterOptions options, [CanBeNull] PresentedInfo presentedInfo) {
				Options = options;
				PresentedInfo = presentedInfo;
			}