Esempio n. 1
0
        private IdentifierTooltipContent TryPresentColorized(PresentableNode presentableNode, [NotNull] IContextBoundSettingsStore settings)
        {
            ITreeNode node = presentableNode.Node;

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

            HighlighterIdProvider highlighterIdProvider = _highlighterIdProviderFactory.CreateProvider(settings);

            RichText identifierText = _colorizerPresenter.TryPresent(
                node,
                PresenterOptions.ForIdentifierToolTip(settings, true),
                node.Language,
                highlighterIdProvider);

            if (identifierText == null || identifierText.IsEmpty)
            {
                return(null);
            }

            var identifierContent = new IdentifierTooltipContent(identifierText, node.GetDocumentRange().TextRange);

            if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowIcon))
            {
                identifierContent.Icon = presentableNode.Icon;
            }

            return(identifierContent);
        }
Esempio n. 2
0
        private IdentifierTooltipContent TryPresentColorized([CanBeNull] DeclaredElementInfo info, [NotNull] IContextBoundSettingsStore settings)
        {
            if (info == null)
            {
                return(null);
            }

            PsiLanguageType  languageType = info.TreeNode.Language;
            IDeclaredElement element      = info.DeclaredElement;
            IPsiModule       psiModule    = info.TreeNode.GetPsiModule();

            HighlighterIdProvider highlighterIdProvider = _highlighterIdProviderFactory.CreateProvider(settings);

            RichText identifierText;

            if (info.DeclaredElement is ICppDeclaredElement cppDeclaredElement)
            {
                identifierText = _solution.TryGetComponent <CppDeclaredElementTooltipProvider>()?.GetTooltip(cppDeclaredElement)?.RichText;
            }
            else
            {
                identifierText = _colorizerPresenter.TryPresent(
                    new DeclaredElementInstance(element, info.Substitution),
                    PresenterOptions.ForIdentifierToolTip(settings, !element.IsEnumMember()),
                    languageType,
                    highlighterIdProvider,
                    info.TreeNode,
                    out _);
            }

            if (identifierText == null || identifierText.IsEmpty)
            {
                return(null);
            }

            var identifierContent = new IdentifierTooltipContent(identifierText, info.SourceRange);

            if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowIcon))
            {
                identifierContent.Icon = TryGetIcon(element);
            }

            if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowDocumentation))
            {
                XmlNode xmlDoc = element.GetXMLDoc(true);
                identifierContent.Description = TryGetDescription(element, xmlDoc, psiModule, languageType);

                if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowObsolete))
                {
                    identifierContent.Obsolete = TryRemoveObsoletePrefix(TryGetObsolete(element, psiModule, languageType));
                }

                if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowReturn))
                {
                    identifierContent.Return = TryPresentDocNode(xmlDoc, "returns", languageType, psiModule);
                }

                if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowValue))
                {
                    identifierContent.Value = TryPresentDocNode(xmlDoc, "value", languageType, psiModule);
                }

                if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowRemarks))
                {
                    identifierContent.Remarks = TryPresentDocNode(xmlDoc, "remarks", languageType, psiModule);
                }

                if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowExceptions))
                {
                    identifierContent.Exceptions.AddRange(GetExceptions(xmlDoc, languageType, psiModule));
                }
            }

            if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowOverloadCount))
            {
                identifierContent.OverloadCount = TryGetOverloadCount(element as IFunction, info.Reference, languageType);
            }

            if (info.DeclaredElement is ITypeElement typeElement)
            {
                var baseTypeDisplayKind = settings.GetValue((IdentifierTooltipSettings s) => s.BaseTypeDisplayKind);
                var implementedInterfacesDisplayKind = settings.GetValue((IdentifierTooltipSettings s) => s.ImplementedInterfacesDisplayKind);
                if (baseTypeDisplayKind != BaseTypeDisplayKind.Never ||
                    implementedInterfacesDisplayKind != ImplementedInterfacesDisplayKind.Never)
                {
                    AddSuperTypes(identifierContent, typeElement, baseTypeDisplayKind, implementedInterfacesDisplayKind, languageType, info.TreeNode, highlighterIdProvider, settings);
                }

                if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowAttributesUsage) && typeElement.IsAttribute())
                {
                    identifierContent.AttributeUsage = GetAttributeUsage((IClass)info.DeclaredElement);
                }
            }

            return(identifierContent);
        }
        private IdentifierTooltipContent TryPresentColorized([NotNull] DeclaredElementInfo info, [NotNull] IContextBoundSettingsStore settings)
        {
            PsiLanguageType  languageType = info.TreeNode.Language;
            IDeclaredElement element      = info.DeclaredElement;
            IPsiModule       psiModule    = info.TreeNode.GetPsiModule();

            HighlighterIdProvider highlighterIdProvider = _highlighterIdProviderFactory.CreateProvider(settings);

            RichText identifierText = _colorizerPresenter.TryPresent(
                new DeclaredElementInstance(element, info.Substitution),
                PresenterOptions.ForIdentifierToolTip(settings),
                languageType,
                highlighterIdProvider);

            if (identifierText == null || identifierText.IsEmpty)
            {
                return(null);
            }

            var identifierContent = new IdentifierTooltipContent(identifierText, info.SourceRange)
            {
                Description = TryGetDescription(element, psiModule, languageType, DeclaredElementDescriptionStyle.NO_OBSOLETE_SUMMARY_STYLE),
            };

            if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowIcon))
            {
                identifierContent.Icon = TryGetIcon(element);
            }

            if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowObsolete))
            {
                identifierContent.Obsolete = TryRemoveObsoletePrefix(TryGetDescription(element, psiModule, languageType, DeclaredElementDescriptionStyle.OBSOLETE_DESCRIPTION));
            }

            if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowExceptions))
            {
                identifierContent.Exceptions.AddRange(GetExceptions(element, languageType, psiModule));
            }

            if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowOverloadCount))
            {
                identifierContent.OverloadCount = TryGetOverloadCountCount(element as IFunction, info.Reference, languageType);
            }

            var typeElement = info.DeclaredElement as ITypeElement;

            if (typeElement != null)
            {
                bool showBaseType = settings.GetValue((IdentifierTooltipSettings s) => s.ShowBaseType);
                bool showImplementedInterfaces = settings.GetValue((IdentifierTooltipSettings s) => s.ShowImplementedInterfaces);
                if (showBaseType || showImplementedInterfaces)
                {
                    AddSuperTypes(identifierContent, typeElement, showBaseType, showImplementedInterfaces, languageType, highlighterIdProvider);
                }

                if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowAttributesUsage) && typeElement.IsAttribute())
                {
                    identifierContent.AttributeUsage = GetAttributeUsage((IClass)info.DeclaredElement);
                }
            }

            return(identifierContent);
        }