コード例 #1
0
        private static ITooltipContent TryGetTooltipContent([NotNull] IHighlighter highlighter, [NotNull] IDocumentMarkup documentMarkup)
        {
            if (highlighter.Attributes.Effect.Type == EffectType.GUTTER_MARK)
            {
                return(null);
            }

            var highlighting = highlighter.UserData as IHighlighting;

            if (highlighting != null)
            {
                IDocument document = documentMarkup.Document;
                IContextBoundSettingsStore settings = document.GetSettings();

                Severity            severity     = HighlightingSettingsManager.Instance.GetSeverity(highlighting, document);
                IssueTooltipContent issueContent = TryCreateIssueContent(highlighter.RichTextToolTip, severity, settings);
                if (issueContent != null)
                {
                    return(issueContent);
                }

                PsiLanguageType languageType = TryGetIdentifierLanguage(highlighting);
                if (languageType != null)
                {
                    ISolution solution = TryGetCurrentSolution();
                    if (solution != null)
                    {
                        IdentifierTooltipContent identifierContent = TryGetIdentifierTooltipContent(highlighter, languageType, solution, settings);
                        if (identifierContent != null)
                        {
                            return(identifierContent);
                        }
                    }
                }
            }

            return(TryCreateMiscContent(highlighter.RichTextToolTip));
        }
        private void AddSuperTypes(
            [NotNull] IdentifierTooltipContent identifierContent,
            [NotNull] ITypeElement typeElement,
            bool showBaseType,
            bool showImplementedInterfaces,
            [NotNull] PsiLanguageType languageType,
            [NotNull] HighlighterIdProvider highlighterIdProvider)
        {
            DeclaredElementInstance         baseType;
            IList <DeclaredElementInstance> implementedInterfaces;

            GetSuperTypes(typeElement, showBaseType, showImplementedInterfaces, out baseType, out implementedInterfaces);

            if (baseType != null)
            {
                identifierContent.BaseType = _colorizerPresenter.TryPresent(baseType, PresenterOptions.QualifiedMember, languageType, highlighterIdProvider);
            }

            if (implementedInterfaces.Count == 0)
            {
                return;
            }

            var sortedPresentedInterfaces = new SortedDictionary <string, RichText>(StringComparer.Ordinal);

            foreach (DeclaredElementInstance implementedInterface in implementedInterfaces)
            {
                RichText richText = _colorizerPresenter.TryPresent(implementedInterface, PresenterOptions.QualifiedMember, languageType, highlighterIdProvider);
                if (richText != null)
                {
                    sortedPresentedInterfaces[richText.ToString(false)] = richText;
                }
            }
            foreach (RichText richText in sortedPresentedInterfaces.Values)
            {
                identifierContent.ImplementedInterfaces.Add(richText);
            }
        }
        private IdentifierContentGroup GetIdentifierContentGroupCore(
            DocumentRange documentRange, [NotNull] IContextBoundSettingsStore settings, [CanBeNull] IHighlighter highlighter)
        {
            DeclaredElementInfo info = FindDeclaredElement(documentRange);

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

            IdentifierTooltipContent standardContent = TryPresentColorized(info, settings)
                                                       ?? TryPresentNonColorized(highlighter, info.DeclaredElement, settings);

            bool replacesStandardContent;
            IdentifierTooltipContent additionalContent = TryGetAdditionalIdentifierContent(info, settings, out replacesStandardContent);

            if (replacesStandardContent)
            {
                standardContent   = additionalContent;
                additionalContent = null;
            }

            var result = new IdentifierContentGroup();

            if (standardContent != null)
            {
                result.Identifiers.Add(standardContent);
            }
            if (additionalContent != null)
            {
                result.Identifiers.Add(additionalContent);
            }

            result.ArgumentRole = TryGetArgumentRoleContent(info.TreeNode, settings);

            return(result);
        }
        private IdentifierTooltipContent TryPresentNonColorized([CanBeNull] IHighlighter highlighter, [CanBeNull] IDeclaredElement element, [NotNull] IContextBoundSettingsStore settings)
        {
            RichTextBlock richTextToolTip = highlighter?.RichTextToolTip;

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

            RichText richText = richTextToolTip.RichText;

            if (richText.IsNullOrEmpty())
            {
                return(null);
            }

            var identifierContent = new IdentifierTooltipContent(richText, highlighter.Range);

            if (element != null && settings.GetValue((IdentifierTooltipSettings s) => s.ShowIcon))
            {
                identifierContent.Icon = TryGetIcon(element);
            }
            return(identifierContent);
        }
コード例 #5
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);
        }
コード例 #6
0
 public void AddIdentifierTooltipContent([NotNull] IdentifierTooltipContent content)
 => _identifierContents.Add(content);
        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);
        }