Пример #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);
        }
Пример #2
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);
        }
Пример #3
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);
        }
        private ArgumentRoleTooltipContent TryGetArgumentRoleContent([NotNull] ITreeNode node, [NotNull] IContextBoundSettingsStore settings)
        {
            if (!settings.GetValue((IdentifierTooltipSettings s) => s.ShowArgumentsRole))
            {
                return(null);
            }

            var argument = node.GetContainingNode <IArgument>();
            DeclaredElementInstance <IParameter> parameterInstance = argument?.MatchingParameter;

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

            IParameter       parameter       = parameterInstance.Element;
            IParametersOwner parametersOwner = parameter.ContainingParametersOwner;

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

            HighlighterIdProvider highlighterIdProvider = _highlighterIdProviderFactory.CreateProvider(settings);

            RichText final = new RichText("Argument of ", TextStyle.Default);

            final.Append(_colorizerPresenter.TryPresent(
                             new DeclaredElementInstance(parametersOwner, parameterInstance.Substitution),
                             PresenterOptions.ForArgumentRoleParametersOwnerToolTip(settings),
                             argument.Language,
                             highlighterIdProvider));
            final.Append(": ", TextStyle.Default);
            final.Append(_colorizerPresenter.TryPresent(
                             parameterInstance,
                             PresenterOptions.ForArgumentRoleParameterToolTip(settings),
                             argument.Language,
                             highlighterIdProvider));

            var content = new ArgumentRoleTooltipContent(final, argument.GetDocumentRange().TextRange)
            {
                Description = TryGetDescription(parameter, parameter.Module, argument.Language, DeclaredElementDescriptionStyle.NO_OBSOLETE_SUMMARY_STYLE)
            };

            if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowIcon))
            {
                content.Icon = PsiSymbolsThemedIcons.Parameter.Id;
            }

            return(content);
        }
Пример #5
0
        private void AddSuperTypes(
            [NotNull] IdentifierTooltipContent identifierContent,
            [NotNull] ITypeElement typeElement,
            BaseTypeDisplayKind baseTypeDisplayKind,
            ImplementedInterfacesDisplayKind implementedInterfacesDisplayKind,
            [NotNull] PsiLanguageType languageType,
            [NotNull] ITreeNode contextualNode,
            [NotNull] HighlighterIdProvider highlighterIdProvider,
            [NotNull] IContextBoundSettingsStore settings)
        {
            GetSuperTypes(
                typeElement,
                baseTypeDisplayKind,
                implementedInterfacesDisplayKind,
                out DeclaredElementInstance baseType,
                out IList <DeclaredElementInstance> implementedInterfaces);

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

            PresenterOptions presenterOptions = PresenterOptions.ForBaseTypeOrImplementedInterfaceTooltip(settings);

            if (baseType != null)
            {
                identifierContent.BaseType = _colorizerPresenter.TryPresent(baseType, presenterOptions, languageType, highlighterIdProvider, contextualNode, out _);
            }

            if (implementedInterfaces.Count > 0)
            {
                var sortedPresentedInterfaces = new SortedDictionary <string, RichText>(StringComparer.Ordinal);
                foreach (DeclaredElementInstance implementedInterface in implementedInterfaces)
                {
                    RichText richText = _colorizerPresenter.TryPresent(implementedInterface, presenterOptions, languageType, highlighterIdProvider, contextualNode, out _);
                    if (richText != null)
                    {
                        sortedPresentedInterfaces[richText.ToString(false)] = richText;
                    }
                }
                foreach (RichText richText in sortedPresentedInterfaces.Values)
                {
                    identifierContent.ImplementedInterfaces.Add(richText);
                }
            }
        }
Пример #6
0
        private IdentifierTooltipContent TryPresentColorized([NotNull] DeclaredElementInfo info, [NotNull] IContextBoundSettingsStore settings)
        {
            PsiLanguageType  languageType = info.File.Language;
            IDeclaredElement element      = info.DeclaredElement;
            IPsiModule       psiModule    = info.File.GetPsiModule();

            RichText identifierText = _colorizerPresenter.TryPresent(
                new DeclaredElementInstance(element, info.Substitution),
                PresenterOptions.ForToolTip(settings),
                languageType,
                settings.GetValue(HighlightingSettingsAccessor.IdentifierHighlightingEnabled));

            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, info.File.GetResolveContext()));
            }

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

            return(identifierContent);
        }
Пример #7
0
        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;

            ITypeParametersOwner typeElement = UnderlyingCandidate.TypeElement;
            var      elementInstance         = new DeclaredElementInstance(typeElement, typeElement.IdSubstitution);
            RichText richText = _colorizerPresenter.TryPresent(elementInstance, options, UnderlyingCandidate.Language, highlighterIdProvider, null, out PresentedInfo presentedInfo);

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

            parameterRanges = presentedInfo.TypeParameters.ToArray();
            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);
        }
Пример #9
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);
        }
 protected override PresenterOptions GetPresenterOptions(IContextBoundSettingsStore settings, AnnotationsDisplayKind showAnnotations)
 => PresenterOptions.ForParameterInfo(settings, showAnnotations.ToAttributesDisplayKind());
Пример #11
0
        private IdentifierTooltipContent TryPresentColorized([NotNull] DeclaredElementInstance elementInstance, [NotNull] PsiLanguageType languageType,
                                                             [NotNull] IPsiSourceFile psiSourceFile, [NotNull] IContextBoundSettingsStore settings, [CanBeNull] string highlighterAttributeId)
        {
            RichText identifierText = _colorizerPresenter.TryPresent(elementInstance, PresenterOptions.ForToolTip(settings), languageType, highlighterAttributeId);

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

            IDeclaredElement element   = elementInstance.Element;
            IPsiModule       psiModule = psiSourceFile.PsiModule;

            var identifierContent = new IdentifierTooltipContent {
                Text        = identifierText,
                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, psiSourceFile.ResolveContext));
            }
            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);
        }