public static PresenterOptions ForParameterInfo(IContextBoundSettingsStore settings, AttributesDisplayKind attributesDisplayKind)
 => new PresenterOptions
 {
     AttributesFormattingMode         = AttributesFormattingMode.AllOnCurrentLine,
     ExternalCodeNamespaceDisplayKind = ExternalCodeNamespaceDisplayKind.Never,
     FormatDelegatesAsLambdas         = settings.GetValue((ParameterInfoSettingsKey key) => key.DelegatesAsLambdas),
     ParametersFormattingMode         = ParametersFormattingMode.AllOnCurrentLine,
     ShowAccessors                  = false,
     ShowAccessRights               = false,
     ShowConstantValue              = false,
     ShowDefaultValues              = true,
     ShowElementAttributes          = AttributesDisplayKind.Never,
     ShowElementAttributesArguments = false,
     ShowElementKind                = ElementKindDisplay.None,
     ShowElementType                = ElementTypeDisplay.After,
     ShowEmptyParametersText        = settings.GetValue((ParameterInfoSettings s) => s.ShowEmptyParametersText),
     ShowExplicitInterface          = false,
     ShowModifiers                  = false,
     ShowName = false,
     ShowParametersAttributes          = attributesDisplayKind,
     ShowParametersAttributesArguments = false,
     ShowParametersName               = true,
     ShowParametersType               = true,
     ShowQualifiers                   = QualifierDisplays.None,
     ShowTypeParameters               = false,
     ShowTypeParametersVariance       = false,
     SolutionCodeNamespaceDisplayKind = SolutionCodeNamespaceDisplayKind.Never,
     UseAttributeClassKind            = false,
     UseClassModifiersInKind          = false,
     UseExtensionMethodKind           = false,
     UseMethodModifiersInKind         = false,
     UseShortNullableForm             = true,
     UseStructModifiersInKind         = false,
     UseTypeKeywords                  = settings.GetValue((ParameterInfoSettings s) => s.UseTypeKeywords)
 };
예제 #2
0
        private static IssueTooltipContent TryCreateIssueContent([NotNull] IHighlighting highlighting, TextRange trackingRange,
                                                                 [CanBeNull] RichTextBlock textBlock, Severity severity, [NotNull] IContextBoundSettingsStore settings, [CanBeNull] ISolution solution)
        {
            if (textBlock == null || !severity.IsIssue())
            {
                return(null);
            }

            RichText text = textBlock.RichText;

            if (text.IsEmpty)
            {
                return(null);
            }

            if (settings.GetValue((IssueTooltipSettings s) => s.ColorizeElementsInErrors))
            {
                RichText enhancedText = TryEnhanceHighlighting(highlighting, settings, solution);
                if (!enhancedText.IsNullOrEmpty())
                {
                    text = enhancedText;
                }
            }

            var issueContent = new IssueTooltipContent(text, trackingRange);

            if (settings.GetValue((IssueTooltipSettings s) => s.ShowIcon))
            {
                issueContent.Icon = severity.TryGetIcon();
            }
            return(issueContent);
        }
예제 #3
0
        public void CollectRunMarkers(
            [NotNull] IFile file,
            [NotNull] IContextBoundSettingsStore settings,
            [NotNull] IHighlightingConsumer consumer
            )
        {
            bool showMarkerOnStaticMethods = settings.GetValue((RunMarkerSettings s) => s.ShowMarkerOnStaticMethods);
            bool showMarkerOnEntryPoint    = settings.GetValue((RunMarkerSettings s) => s.ShowMarkerOnEntryPoint);

            if (!showMarkerOnStaticMethods && !showMarkerOnEntryPoint)
            {
                return;
            }
            if (!(file is IT4File t4File))
            {
                return;
            }
            if (t4File.PhysicalPsiSourceFile.ToProjectFile() == null)
            {
                return;
            }
            var directive = t4File.BlocksEnumerable.OfType <IT4TemplateDirective>().FirstOrDefault();

            if (directive == null)
            {
                return;
            }
            consumer.AddHighlighting(new T4RunMarkerHighlighting(directive));
        }
예제 #4
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);
        }
        public static bool HasHotIcon(this IDeclaredElement element, SolutionAnalysisService swa,
                                      CallGraphSwaExtensionProvider callGraphSwaExtensionProvider, IContextBoundSettingsStore settingsStore,
                                      PerformanceCriticalCodeCallGraphAnalyzer analyzer, DaemonProcessKind kind)
        {
            if (!settingsStore.GetValue((UnitySettings key) => key.EnableIconsForPerformanceCriticalCode))
            {
                return(false);
            }

            if (!settingsStore.GetValue((UnitySettings key) => key.EnablePerformanceCriticalCodeHighlighting))
            {
                return(false);
            }

            var usageChecker = swa.UsageChecker;

            if (usageChecker == null)
            {
                return(false);
            }

            var id = swa.GetElementId(element, true);

            if (!id.HasValue)
            {
                return(false);
            }

            return(callGraphSwaExtensionProvider.IsMarkedByCallGraphAnalyzer(analyzer.Id, id.Value,
                                                                             kind == DaemonProcessKind.GLOBAL_WARNINGS));
        }
        public EnterSearchStringDialog(IContextBoundSettingsStore settingsStore)
        {
            mySettingsStore = settingsStore;
            InitializeComponent();

            // Gettings previously saved state or default values from settings
            string searchString = mySettingsStore.GetValue((FindTextSettings s) => s.LastUsedText) ?? string.Empty;

            var searchFlags = mySettingsStore.GetValue((FindTextSettings s) => s.LastUsedFlags);

            if (searchFlags == 0)
            {
                searchFlags = FindTextSearchFlags.All;
            }

            txtSearchString.Text = searchString;
            txtSearchString.SelectAll();

            if ((searchFlags & FindTextSearchFlags.StringLiterals) != FindTextSearchFlags.None)
            {
                cbSearchStrings.Checked = true;
            }
            if ((searchFlags & FindTextSearchFlags.Comments) != FindTextSearchFlags.None)
            {
                cbSearchComments.Checked = true;
            }
            if ((searchFlags & FindTextSearchFlags.Other) != FindTextSearchFlags.None)
            {
                cbSearchOther.Checked = true;
            }
        }
예제 #7
0
 public static PresenterOptions ForParameterInfo([NotNull] IContextBoundSettingsStore settings, AnnotationsDisplayKind showAnnotations)
 {
     return(new PresenterOptions {
         FormatDelegatesAsLambdas = settings.GetValue((ParameterInfoSettingsKey key) => key.DelegatesAsLambdas),
         ShowAccessRights = false,
         ShowConstantValue = false,
         ShowDefaultValues = true,
         ShowElementKind = ElementKindDisplay.None,
         ShowElementAnnotations = AnnotationsDisplayKind.None,
         ShowElementType = ElementTypeDisplay.After,
         ShowEmptyParametersText = settings.GetValue((ParameterInfoSettings s) => s.ShowEmptyParametersText),
         ShowExplicitInterface = false,
         ShowModifiers = false,
         ShowName = false,
         ShowParametersName = true,
         ShowParametersAnnotations = showAnnotations,
         ShowParametersType = true,
         ShowQualifiers = QualifierDisplays.None,
         UseAttributeClassKind = false,
         UseClassModifiersInKind = false,
         UseExtensionMethodKind = false,
         UseMethodModifiersInKind = false,
         UseTypeKeywords = settings.GetValue((ParameterInfoSettings s) => s.UseTypeKeywords)
     });
 }
 public static PresenterOptions ForBaseTypeOrImplementedInterfaceTooltip(IContextBoundSettingsStore settings)
 => new PresenterOptions
 {
     AttributesFormattingMode         = AttributesFormattingMode.AllOnCurrentLine,
     ExternalCodeNamespaceDisplayKind = settings.GetValue((IdentifierTooltipSettings s) => s.ExternalCodeNamespaceDisplayKind),
     FormatDelegatesAsLambdas         = false,
     ParametersFormattingMode         = ParametersFormattingMode.AllOnCurrentLine,
     ShowAccessors                  = false,
     ShowAccessRights               = false,
     ShowConstantValue              = false,
     ShowDefaultValues              = true,
     ShowElementAttributes          = AttributesDisplayKind.Never,
     ShowElementAttributesArguments = false,
     ShowElementKind                = ElementKindDisplay.None,
     ShowElementType                = ElementTypeDisplay.Before,
     ShowEmptyParametersText        = false,
     ShowExplicitInterface          = false,
     ShowModifiers                  = false,
     ShowName = true,
     ShowParametersAttributes          = AttributesDisplayKind.Never,
     ShowParametersAttributesArguments = false,
     ShowParametersName               = false,
     ShowParametersType               = true,
     ShowQualifiers                   = QualifierDisplays.Member,
     ShowTypeParameters               = true,
     ShowTypeParametersVariance       = false,
     SolutionCodeNamespaceDisplayKind = settings.GetValue((IdentifierTooltipSettings s) => s.SolutionCodeNamespaceDisplayKind),
     UseAttributeClassKind            = false,
     UseClassModifiersInKind          = false,
     UseExtensionMethodKind           = false,
     UseMethodModifiersInKind         = false,
     UseShortNullableForm             = true,
     UseStructModifiersInKind         = false,
     UseTypeKeywords                  = true
 };
예제 #9
0
        /// <summary>
        /// This method provides a <see cref="IDaemonStageProcess"/> instance which is assigned to highlighting a single document.
        /// </summary>
        /// <param name="process">
        /// Current Daemon Process.
        /// </param>
        /// <param name="settingsStore">
        /// The settingsStore store to use.
        /// </param>
        /// <param name="processKind">
        /// The process kind.
        /// </param>
        /// <param name="file">
        /// The file to analyze.
        /// </param>
        /// ///
        /// <returns>
        /// The current <see cref="IDaemonStageProcess"/>.
        /// </returns>
        protected override IDaemonStageProcess CreateProcess(
            IDaemonProcess process, IContextBoundSettingsStore settingsStore, DaemonProcessKind processKind, ICSharpFile file)
        {
            StyleCopTrace.In(process, settingsStore, processKind, file);

            if (process == null)
            {
                throw new ArgumentNullException("process");
            }

            try
            {
                if (processKind == DaemonProcessKind.OTHER)
                {
                    StyleCopTrace.Info("ProcessKind Other.");
                    StyleCopTrace.Out();
                    return(null);
                }

                if (!settingsStore.GetValue <StyleCopOptionsSettingsKey, bool>(key => key.AnalysisEnabled))
                {
                    StyleCopTrace.Info("Analysis disabled.");
                    StyleCopTrace.Out();
                    return(null);
                }

                if (!this.IsSupported(process.SourceFile))
                {
                    StyleCopTrace.Info("File type not supported.");
                    StyleCopTrace.Out();
                    return(null);
                }

                if (!this.FileIsValid(file))
                {
                    StyleCopTrace.Info("Source file not valid.");
                    StyleCopTrace.Out();
                    return(null);
                }

                if (!settingsStore.GetValue <StyleCopOptionsSettingsKey, bool>(key => key.AnalyzeReadOnlyFiles))
                {
                    if (process.SourceFile.Properties.IsNonUserFile)
                    {
                        StyleCopTrace.Info("Not analysing non user files.");
                        StyleCopTrace.Out();
                        return(null);
                    }
                }

                return(StyleCopTrace.Out(new StyleCopStageProcess(process, settingsStore, file)));
            }
            catch (JB::JetBrains.Application.Progress.ProcessCancelledException)
            {
                return(null);
            }
        }
예제 #10
0
 public static PresenterOptions ForIdentifierToolTip([NotNull] IContextBoundSettingsStore settings)
 {
     return(new PresenterOptions {
         FormatDelegatesAsLambdas = settings.GetValue((ParameterInfoSettingsKey s) => s.DelegatesAsLambdas),
         ShowAccessRights = false,
         ShowConstantValue = true,
         ShowDefaultValues = true,
         ShowElementKind = settings.GetValue((IdentifierTooltipSettings s) => s.ShowKind) ? ElementKindDisplay.Stylized : ElementKindDisplay.None,
         ShowElementAnnotations = settings.GetValue((IdentifierTooltipSettings s) => s.ShowIdentifierAnnotations),
         ShowElementType = ElementTypeDisplay.Before,
         ShowEmptyParametersText = false,
         ShowExplicitInterface = false,
         ShowModifiers = false,
         ShowName = true,
         ShowParametersName = true,
         ShowParametersAnnotations = settings.GetValue((IdentifierTooltipSettings s) => s.ShowParametersAnnotations),
         ShowParametersType = true,
         ShowQualifiers = QualifierDisplays.Member,
         UseAttributeClassKind = settings.GetValue((IdentifierTooltipSettings s) => s.UseAttributeClassKind),
         UseClassModifiersInKind = settings.GetValue((IdentifierTooltipSettings s) => s.UseClassModifiersInKind),
         UseExtensionMethodKind = settings.GetValue((IdentifierTooltipSettings s) => s.UseExtensionMethodKind),
         UseMethodModifiersInKind = settings.GetValue((IdentifierTooltipSettings s) => s.UseMethodModifiersInKind),
         UseTypeKeywords = settings.GetValue((IdentifierTooltipSettings s) => s.UseTypeKeywords)
     });
 }
예제 #11
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);
        }
        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);
        }
예제 #13
0
        /// <summary>
        /// Update dash header and footer.
        /// </summary>
        private void UpdateDashHeaderAndFooter()
        {
            if (this.headerXml == null)
            {
                return;
            }

            IContextBoundSettingsStore settingsStore = PsiSourceFileExtensions.GetSettingsStore(null, this.File.GetSolution());
            int    dashCount = settingsStore.GetValue((StyleCopOptionsSettingsKey key) => key.DashesCountInFileHeader);
            string dashes    = new string('-', dashCount);

            XmlText xmlTextTop = this.headerXml.CreateTextNode(string.Format("// {0}{1}// ", dashes, Environment.NewLine));

            if (this.headerXml.DocumentElement.FirstChild.NodeType == XmlNodeType.Text)
            {
                this.headerXml.DocumentElement.ReplaceChild(xmlTextTop, this.headerXml.DocumentElement.FirstChild);
            }
            else
            {
                this.headerXml.DocumentElement.InsertBefore(xmlTextTop, this.headerXml.DocumentElement.FirstChild);
            }

            XmlText xmlTextBottom = this.headerXml.CreateTextNode(string.Format("{0}// {1}", Environment.NewLine, dashes));

            if (this.headerXml.DocumentElement.LastChild.NodeType == XmlNodeType.Text)
            {
                this.headerXml.DocumentElement.ReplaceChild(xmlTextBottom, this.headerXml.DocumentElement.LastChild);
            }
            else
            {
                this.headerXml.DocumentElement.InsertAfter(xmlTextBottom, this.headerXml.DocumentElement.LastChild);
            }
        }
예제 #14
0
 public static PresenterOptions ForArgumentRoleParametersOwnerToolTip([NotNull] IContextBoundSettingsStore settings)
 {
     return(new PresenterOptions {
         FormatDelegatesAsLambdas = false,
         ShowAccessRights = false,
         ShowConstantValue = false,
         ShowDefaultValues = false,
         ShowElementKind = ElementKindDisplay.Standard,
         ShowElementAnnotations = AnnotationsDisplayKind.None,
         ShowElementType = ElementTypeDisplay.None,
         ShowEmptyParametersText = false,
         ShowExplicitInterface = false,
         ShowModifiers = false,
         ShowName = true,
         ShowParametersName = false,
         ShowParametersAnnotations = AnnotationsDisplayKind.None,
         ShowParametersType = false,
         ShowQualifiers = QualifierDisplays.None,
         UseAttributeClassKind = false,
         UseClassModifiersInKind = false,
         UseExtensionMethodKind = false,
         UseMethodModifiersInKind = false,
         UseTypeKeywords = settings.GetValue((IdentifierTooltipSettings s) => s.UseTypeKeywords)
     });
 }
예제 #15
0
        private IdentifierTooltipContent TryGetAdditionalIdentifierContent(
            [CanBeNull] DeclaredElementInfo info,
            [NotNull] IContextBoundSettingsStore settings,
            out bool replacesStandardContent)
        {
            replacesStandardContent = false;

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

            var          constructor = info.DeclaredElement as IConstructor;
            ITypeElement typeElement = constructor?.GetContainingType();

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

            ConstructorReferenceDisplay display = settings.GetValue(GetConstructorSettingsKey(typeElement.IsAttribute()));

            switch (display)
            {
            case ConstructorReferenceDisplay.TypeOnly:
                replacesStandardContent = true;
                return(TryGetTypeIdentifierContentFromConstructor(constructor, info, settings));

            case ConstructorReferenceDisplay.Both:
                return(TryGetTypeIdentifierContentFromConstructor(constructor, info, settings));

            default:
                return(null);
            }
        }
예제 #16
0
        /// <summary>
        /// The execute inner.
        /// </summary>
        /// <param name="solution">
        /// The solution.
        /// </param>
        /// <param name="textControl">
        /// The text control.
        /// </param>
        public override void ExecuteTransactionInner(ISolution solution, ITextControl textControl)
        {
            IAttributesOwnerDeclaration declaration = Utils.GetTypeClosestToTextControl <IAttributesOwnerDeclaration>(solution, textControl);

            if (declaration != null)
            {
                string rulesNamespace = this.Rule.Namespace;

                string ruleText = string.Format("{0}:{1}", this.Rule.CheckId, this.Rule.Name);

                IContextBoundSettingsStore settingsStore = PsiSourceFileExtensions.GetSettingsStore(null, solution);

                string justificationText = settingsStore.GetValue((StyleCopOptionsSettingsKey key) => key.SuppressStyleCopAttributeJustificationText);

                CSharpElementFactory factory = CSharpElementFactory.GetInstance(declaration.GetPsiModule());

                ITypeElement typeElement = Utils.GetTypeElement(declaration, "System.Diagnostics.CodeAnalysis.SuppressMessageAttribute");

                IAttribute attribute = factory.CreateAttribute(typeElement);

                ICSharpArgument newArg1 = attribute.AddArgumentAfter(Utils.CreateConstructorArgumentValueExpression(declaration.GetPsiModule(), rulesNamespace), null);

                ICSharpArgument newArg2 = attribute.AddArgumentAfter(Utils.CreateConstructorArgumentValueExpression(declaration.GetPsiModule(), ruleText), newArg1);

                IPropertyAssignment propertyAssignment = factory.CreatePropertyAssignment(
                    "Justification",
                    factory.CreateExpression("\"$0\"", justificationText));
                attribute.AddPropertyAssignmentAfter(propertyAssignment, null);

                declaration.AddAttributeAfter(attribute, null);
            }
        }
예제 #17
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);
        }
예제 #18
0
        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);
        }
        /// <summary>
        /// This method provides a <see cref="IDaemonStageProcess"/> instance which is assigned to highlighting a single document
        /// </summary>
        public IDaemonStageProcess CreateProcess(IDaemonProcess process, IContextBoundSettingsStore settings, DaemonProcessKind kind)
        {
            if (process == null)
            throw new ArgumentNullException("process");

              return new InjectionHappyDetectorDaemonStageProcess(process, settings.GetValue((InjectionHappyDetectorSettings s) => s.MaximumParameters));
        }
예제 #20
0
        /// <summary>
        /// Creates a new DeclarationHeader for the declaration and assigns it to the declaration.
        /// </summary>
        /// <param name="declaration">
        /// The declaration to create the header for.
        /// </param>
        /// <param name="docConfig">
        /// Provides the configuration for the current ProjectFile.
        /// </param>
        /// <returns>
        /// A DeclarationHeader for the declaration passed in.
        /// </returns>
        public static DeclarationHeader CreateNewHeader(IDeclaration declaration, DocumentationRulesConfiguration docConfig)
        {
            IFile file = declaration.GetContainingFile();

            using (WriteLockCookie.Create(file.IsPhysical()))
            {
                IDeclaration declarationTreeNode = declaration;

                IContextBoundSettingsStore settingsStore = PsiSourceFileExtensions.GetSettingsStore(null, declaration.GetSolution());
                bool   useSingleLineDeclarationComments  = settingsStore.GetValue((StyleCopOptionsSettingsKey key) => key.UseSingleLineDeclarationComments);
                string middleText = useSingleLineDeclarationComments ? string.Empty : Environment.NewLine;

                string emptyDocHeader = string.Format("<summary>{0}</summary>", middleText);

                if (!(declarationTreeNode is IMultipleDeclarationMember))
                {
                    emptyDocHeader = CreateDocumentationForElement((IDocCommentBlockOwnerNode)declaration, docConfig);
                    emptyDocHeader = emptyDocHeader.Substring(0, emptyDocHeader.Length - Environment.NewLine.Length);
                }

                string header = LayoutDocumentationHeader(emptyDocHeader, declaration);

                IDocCommentBlockNode newDocCommentNode = Utils.CreateDocCommentBlockNode(file, header);

                IDocCommentBlockOwnerNode docCommentBlockOwnerNode = Utils.GetDocCommentBlockOwnerNodeForDeclaration(declaration);

                if (docCommentBlockOwnerNode != null)
                {
                    docCommentBlockOwnerNode.SetDocCommentBlockNode(newDocCommentNode);
                }

                return(new DeclarationHeader(declaration));
            }
        }
예제 #21
0
        private static Style CreateItemContainerStyle([CanBeNull] IContextBoundSettingsStore settings)
        {
            var itemContainerStyle = new Style(typeof(ListBoxItem), UIResources.Instance.QuickInfoItemStyle);

            if (Shell.HasInstance)
            {
                var tooltipFormattingProvider = Shell.Instance.TryGetComponent <TooltipFormattingProvider>();
                if (tooltipFormattingProvider != null)
                {
                    var colorSource = settings?.GetValue((DisplaySettings s) => s.TooltipColorSource) ?? TooltipColorSource.TextEditorSettings;

                    var background = tooltipFormattingProvider.TryGetBackground(colorSource);
                    if (background != null)
                    {
                        itemContainerStyle.Setters.Add(new Setter(ItemTemplateBackgroundProperty, background));
                    }

                    var borderBrush = tooltipFormattingProvider.TryGetBorderBrush();
                    if (borderBrush != null)
                    {
                        itemContainerStyle.Setters.Add(new Setter(ItemTemplateBorderBrushProperty, borderBrush));
                    }

                    var foreground = tooltipFormattingProvider.TryGetForeground(colorSource);
                    if (foreground != null)
                    {
                        itemContainerStyle.Setters.Add(new Setter(TextElement.ForegroundProperty, foreground));
                    }
                }
            }

            itemContainerStyle.Seal();
            return(itemContainerStyle);
        }
        private static unsafe double ComputeListBoxMaxWidth([NotNull] ItemsControl listBox, [CanBeNull] IContextBoundSettingsStore settings)
        {
            if (settings == null ||
                !settings.GetValue((DisplaySettings s) => s.LimitTooltipWidth) ||
                !(PresentationSource.FromVisual(listBox) is HwndSource hwndSource))
            {
                return(Double.PositiveInfinity);
            }

            int    limitPercent = settings.GetValue((DisplaySettings s) => s.ScreenWidthLimitPercent).Clamp(10, 100);
            IntPtr handle       = hwndSource.Handle;
            // ReSharper disable once AssignNullToNotNullAttribute
            double dpiFactor    = DpiUtil.GetWindowScreenDpiCurrent((void *)handle).DpiX / DpiResolution.DeviceIndependent96DpiValue;
            var    screenBounds = ScreenUtil.GetBounds(handle);

            return(screenBounds.Width * (limitPercent / 100.0) / dpiFactor);
        }
예제 #23
0
        /// <summary>
        /// The skip analysis for document.
        /// </summary>
        /// <param name="projectFile">
        /// The project file.
        /// </param>
        /// <returns>
        /// True if analysis should be skipped.
        /// </returns>
        public bool SkipAnalysisForDocument(IProjectFile projectFile)
        {
            StyleCopTrace.In(projectFile);

            string cacheKey = string.Format("{0}::{1}", "SkipAnalysisForDocument", projectFile.Location.FullPath.ToLowerInvariant());

            bool result;

            if (BoolCache.TryGetValue(cacheKey, out result))
            {
                StyleCopTrace.Out();
                return(result);
            }

            if (projectFile.Name.EndsWith(".cs"))
            {
                IContextBoundSettingsStore settingsStore = projectFile.ToSourceFile().GetSettingsStore();
                if (!settingsStore.GetValue((StyleCopOptionsSettingsKey key) => key.UseExcludeFromStyleCopSetting) || !projectFile.ProjectFileIsExcludedFromStyleCop())
                {
                    bool analyzeDesignerFiles  = true;
                    bool analyzeGeneratedFiles = false;

                    BooleanProperty analyzeDesignerFilesSetting = this.GetParserSetting(projectFile, "AnalyzeDesignerFiles") as BooleanProperty;

                    if (analyzeDesignerFilesSetting != null)
                    {
                        analyzeDesignerFiles = analyzeDesignerFilesSetting.Value;
                    }

                    if (analyzeDesignerFiles || !projectFile.Name.EndsWith(".Designer.cs", StringComparison.OrdinalIgnoreCase))
                    {
                        BooleanProperty analyzeGeneratedFilesSetting = this.GetParserSetting(projectFile, "AnalyzeGeneratedFiles") as BooleanProperty;

                        if (analyzeGeneratedFilesSetting != null)
                        {
                            analyzeGeneratedFiles = analyzeGeneratedFilesSetting.Value;
                        }

                        if (analyzeGeneratedFiles ||
                            (!projectFile.Name.EndsWith(".g.cs", StringComparison.OrdinalIgnoreCase) &&
                             !projectFile.Name.EndsWith(".generated.cs", StringComparison.OrdinalIgnoreCase)))
                        {
                            BoolCache[cacheKey] = false;

                            StyleCopTrace.Out();

                            return(false);
                        }
                    }
                }
            }

            BoolCache[cacheKey] = true;

            StyleCopTrace.Out();

            return(true);
        }
예제 #24
0
        public IdentifierTooltipContent[] GetIdentifierContents(DocumentRange documentRange, [NotNull] IContextBoundSettingsStore settings)
        {
            if (!settings.GetValue((IdentifierTooltipSettings s) => s.Enabled))
            {
                return(EmptyArray <IdentifierTooltipContent> .Instance);
            }

            return(GetIdentifierContentsCore(documentRange, settings, null));
        }
예제 #25
0
        public IdentifierContentGroup GetIdentifierContentGroup(DocumentRange documentRange, [NotNull] IContextBoundSettingsStore settings)
        {
            if (!settings.GetValue((IdentifierTooltipSettings s) => s.Enabled))
            {
                return(null);
            }

            return(GetIdentifierContentGroupCore(documentRange, settings, null));
        }
예제 #26
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);
        }
        public IEnumerable<IDaemonStageProcess> CreateProcess(IDaemonProcess process, IContextBoundSettingsStore settings, DaemonProcessKind processKind)
        {
            if (process == null)
                throw new ArgumentNullException("process");

            return new[]
               {
                 new MockMetricsDaemonStageProcess(process, settings.GetValue((MockMetricsSettings s) => s.ArrangeAmount))
               };
        }
예제 #28
0
        private static double ComputeListBoxMaxWidth([NotNull] ListBox listBox, [CanBeNull] IContextBoundSettingsStore settings)
        {
            if (settings == null || !settings.GetValue((DisplaySettings s) => s.LimitTooltipWidth))
            {
                return(Double.PositiveInfinity);
            }

            var hwndSource = PresentationSource.FromVisual(listBox) as HwndSource;

            if (hwndSource == null)
            {
                return(Double.PositiveInfinity);
            }

            int    limitPercent = settings.GetValue((DisplaySettings s) => s.ScreenWidthLimitPercent).Clamp(10, 100);
            Screen screen       = Screen.FromHandle(hwndSource.Handle);

            return(screen.Bounds.Width * (limitPercent / 100.0) / DpiUtil.DpiHorizontalFactor);
        }
 protected override IDaemonStageProcess CreateProcess(IDaemonProcess process, IContextBoundSettingsStore settings,
     DaemonProcessKind processKind, ICSharpFile file)
 {
     if (processKind == DaemonProcessKind.VISIBLE_DOCUMENT &&
         settings.GetValue(HighlightingSettingsAccessor.ColorUsageHighlightingEnabled))
     {
         return new UnityColorHighlighterProcess(process, settings, file);
     }
     return null;
 }
 protected override IDaemonStageProcess CreateProcess(IDaemonProcess process, IContextBoundSettingsStore settings,
                                                      DaemonProcessKind processKind, ICSharpFile file)
 {
     if (processKind == DaemonProcessKind.VISIBLE_DOCUMENT &&
         settings.GetValue(HighlightingSettingsAccessor.ColorUsageHighlightingEnabled))
     {
         return(new UnityColorHighlighterProcess(process, settings, file));
     }
     return(null);
 }
    /// <summary>
    /// This method provides a <see cref="IDaemonStageProcess"/> instance which is assigned to highlighting a single document
    /// </summary>
    public IEnumerable<IDaemonStageProcess> CreateProcess(IDaemonProcess process, IContextBoundSettingsStore settings, DaemonProcessKind kind)
    {
      if (process == null)
        throw new ArgumentNullException("process");

      return new[]
               {
                 new ComplexityAnalysisDaemonStageProcess(
                   process, settings.GetValue((ComplexityAnalysisSettings s) => s.Threshold))
               };
    }
예제 #32
0
        public IReadOnlyCollection <TodoItemsCountDefinition> ReadData(Lifetime _, IContextBoundSettingsStore store)
        {
            var isEnabled = store.GetValue((TodoItemsCountSettings s) => s.IsEnabled);

            if (!isEnabled)
            {
                return(null);
            }

            var definitionsText = store.GetValue((TodoItemsCountSettings s) => s.Definitions);

            var matches = Regex.Matches(definitionsText, @"^\s*(?<Name>.+?)\s*(\[(?<Condition>.*)\]\s*)?$", RegexOptions.Multiline);

            var result = from Match match in matches
                         let title = match.Groups["Name"].Value
                                     let condition = match.Groups["Condition"]
                                                     select new TodoItemsCountDefinition(title, condition.Success ? condition.Value : null);

            return(result.ToList());
        }
예제 #33
0
 private static void MigrateValue(
     [NotNull] IContextBoundSettingsStore store,
     [NotNull] Expression <Func <IdentifierTooltipSettings, AnnotationsDisplayKind> > oldSettingExpr,
     [NotNull] Expression <Func <IdentifierTooltipSettings, AttributesDisplayKind> > newSettingExpr)
 {
     if (!store.IsEntryEqualToDefault(oldSettingExpr) && store.IsEntryEqualToDefault(newSettingExpr))
     {
         AnnotationsDisplayKind annotationsDisplayKind = store.GetValue(oldSettingExpr);
         store.SetValue(newSettingExpr, annotationsDisplayKind.ToAttributesDisplayKind());
     }
 }
예제 #34
0
        private static IParameterInfoContext Enhance([CanBeNull] IParameterInfoContext context, [NotNull] ISolution solution, [NotNull] IContextBoundSettingsStore settings)
        {
            if (!settings.GetValue((ParameterInfoSettings s) => s.Enabled))
            {
                return(context);
            }

            return(context == null
                                ? null
                                : new EnhancedParameterInfoContext(context, solution.GetComponent <ColorizerPresenter>(), settings));
        }
 public IEnumerable<IDaemonStageProcess> CreateProcess(IDaemonProcess process,
     IContextBoundSettingsStore settings, DaemonProcessKind processKind)
 {
     if (process == null)
         throw new ArgumentNullException("process");
     return new[]
     {
         new DisposableFunctionDaemonStageProcess(process,
             settings.GetValue((DisposePluginSettings s) => s.MaxLevel))
     };
 }
    public EnterSearchStringDialog(IContextBoundSettingsStore settingsStore)
    {
      mySettingsStore = settingsStore;
      InitializeComponent();
      
      // Gettings previously saved state or default values from settings
      string searchString = mySettingsStore.GetValue((FindTextSettings s) => s.LastUsedText) ?? string.Empty;

      var searchFlags = mySettingsStore.GetValue((FindTextSettings s) => s.LastUsedFlags);
      if (searchFlags == 0)
        searchFlags = FindTextSearchFlags.All;

      txtSearchString.Text = searchString;
      txtSearchString.SelectAll();

      if ((searchFlags & FindTextSearchFlags.StringLiterals) != FindTextSearchFlags.None)
        cbSearchStrings.Checked = true;
      if ((searchFlags & FindTextSearchFlags.Comments) != FindTextSearchFlags.None)
        cbSearchComments.Checked = true;
      if ((searchFlags & FindTextSearchFlags.Other) != FindTextSearchFlags.None)
        cbSearchOther.Checked = true;
    }
        /// <summary>
        /// This method provides a <see cref="IDaemonStageProcess"/> instance which is assigned to highlighting a single document.
        /// </summary>
        /// <param name="process">
        /// Current Daemon Process.
        /// </param>
        /// <param name="settingsStore">
        /// The settingsStore store to use.
        /// </param>
        /// <param name="processKind">
        /// The process kind.
        /// </param>
        /// <returns>
        /// The current <see cref="IDaemonStageProcess"/>.
        /// </returns>
        public override IDaemonStageProcess CreateProcess(IDaemonProcess process, IContextBoundSettingsStore settingsStore, DaemonProcessKind processKind)
        {
            StyleCopTrace.In(process, settingsStore, processKind);

            if (process == null)
            {
                throw new ArgumentNullException("process");
            }

            if (processKind == DaemonProcessKind.OTHER)
            {
                StyleCopTrace.Info("ProcessKind Other.");
                StyleCopTrace.Out();
                return null;
            }

            if (!settingsStore.GetValue<StyleCopOptionsSettingsKey, bool>(key => key.AnalysisEnabled))
            {
                StyleCopTrace.Info("Analysis disabled.");
                StyleCopTrace.Out();
                return null;
            }

            if (!this.IsSupported(process.SourceFile))
            {
                StyleCopTrace.Info("File type not supported.");
                StyleCopTrace.Out();
                return null;
            }

            if (!this.FileIsValid(process.SourceFile))
            {
                StyleCopTrace.Info("Source file not valid.");
                StyleCopTrace.Out();
                return null;
            }

            return StyleCopTrace.Out(new StyleCopStageProcess(process, settingsStore));
        }
예제 #38
0
        /// <summary>
        /// This method provides a <see cref="IDaemonStageProcess"/> instance which is assigned to highlighting a single document.
        /// </summary>
        /// <param name="process">
        /// Current Daemon Process.
        /// </param>
        /// <param name="settingsStore">
        /// The settingsStore store to use.
        /// </param>
        /// <param name="processKind">
        /// The process kind.
        /// </param>
        /// <param name="file">
        /// The file to analyze.
        /// </param>
        /// /// 
        /// <returns>
        /// The current <see cref="IDaemonStageProcess"/>.
        /// </returns>
        protected override IDaemonStageProcess CreateProcess(
            IDaemonProcess process, IContextBoundSettingsStore settingsStore, DaemonProcessKind processKind, ICSharpFile file)
        {
            StyleCopTrace.In(process, settingsStore, processKind, file);

            if (process == null)
            {
                throw new ArgumentNullException("process");
            }

            try
            {
                if (processKind == DaemonProcessKind.OTHER)
                {
                    StyleCopTrace.Info("ProcessKind Other.");
                    StyleCopTrace.Out();
                    return null;
                }

                if (!settingsStore.GetValue<StyleCopOptionsSettingsKey, bool>(key => key.AnalysisEnabled))
                {
                    StyleCopTrace.Info("Analysis disabled.");
                    StyleCopTrace.Out();
                    return null;
                }

                if (!this.IsSupported(process.SourceFile))
                {
                    StyleCopTrace.Info("File type not supported.");
                    StyleCopTrace.Out();
                    return null;
                }

                if (!this.FileIsValid(file))
                {
                    StyleCopTrace.Info("Source file not valid.");
                    StyleCopTrace.Out();
                    return null;
                }

                if (!settingsStore.GetValue<StyleCopOptionsSettingsKey, bool>(key => key.AnalyzeReadOnlyFiles))
                {
                    if (process.SourceFile.Properties.IsNonUserFile)
                    {
                        StyleCopTrace.Info("Not analysing non user files.");
                        StyleCopTrace.Out();
                        return null;
                    }
                }

                return StyleCopTrace.Out(new StyleCopStageProcess(process, settingsStore, file));
            }
            catch (JetBrains.Application.Progress.ProcessCancelledException)
            {
                return null;
            }
        }
 protected override bool GetIntellisenseEnabledSpecific(IContextBoundSettingsStore boundSettingsStore)
 {
   return boundSettingsStore.GetValue((IntellisenseEnabledSettingPsi setting) => setting.IntellisenseEnabled);
 }
예제 #40
0
 public AutopopupType IsEnabledInSettings(IContextBoundSettingsStore settingsStore, ITextControl textControl)
 {
     return (AutopopupType) settingsStore.GetValue(_settingsEntry, null);
 }