Esempio n. 1
0
        protected override IEnumerable <BulbMenuItem> GetActions(IMethodDeclaration methodDeclaration, ITextControl textControl)
        {
            var bulb         = new AddPerformanceAnalysisDisableCommentBulbAction(methodDeclaration);
            var bulbMenuItem = UnityCallGraphUtil.BulbActionToMenuItem(bulb, textControl, Solution, BulbThemedIcons.ContextAction.Id);

            return(new[] { bulbMenuItem });
        }
        protected override IEnumerable <BulbMenuItem> GetActions(IMethodDeclaration methodDeclaration, ITextControl textControl)
        {
            var bulb         = new AddDiscardAttributeBulbAction(methodDeclaration);
            var bulbMenuItem = UnityCallGraphUtil.BulbActionToMenuItem(bulb, textControl, Solution, BulbThemedIcons.ContextAction.Id);

            return(new[] { bulbMenuItem });
        }
        public IEnumerable <IntentionAction> CreateBulbItems()
        {
            var identifier        = myDataProvider.GetSelectedElement <ITreeNode>() as ICSharpIdentifier;
            var methodDeclaration = MethodDeclarationNavigator.GetByNameIdentifier(identifier);

            if (methodDeclaration == null)
            {
                return(EmptyList <IntentionAction> .Instance);
            }

            if (!UnityCallGraphUtil.IsSweaCompleted(mySwa))
            {
                return(EmptyList <IntentionAction> .Instance);
            }

            var processKind = UnityCallGraphUtil.GetProcessKindForGraph(mySwa);

            if (myExpensiveContextProvider.HasContext(methodDeclaration, processKind))
            {
                return(EmptyList <IntentionAction> .Instance);
            }

            var isPerformanceContext = myPerformanceContextProvider.HasContext(methodDeclaration, processKind);

            if (!isPerformanceContext)
            {
                return(EmptyList <IntentionAction> .Instance);
            }

            var bulbAction = new AddExpensiveCommentBulbAction(methodDeclaration);

            return(bulbAction.ToContextActionIntentions());
        }
Esempio n. 4
0
        public override LocalList <IDeclaredElement> GetRootMarksFromNode(ITreeNode currentNode,
                                                                          IDeclaredElement containingFunction)
        {
            var result = base.GetRootMarksFromNode(currentNode, containingFunction);

            // it means we are in functional type member like methodDeclaration
            if (containingFunction == null)
            {
                return(result);
            }

            var declaration     = currentNode as IDeclaration;
            var declaredElement = declaration?.DeclaredElement;

            if (declaredElement == null || !UnityCallGraphUtil.IsFunctionNode(declaration))
            {
                return(result);
            }

            using (var processor = new ExpensiveCodeProcessor(declaration))
            {
                declaration.ProcessThisAndDescendants(processor);

                if (processor.ProcessingIsFinished)
                {
                    result.Add(declaredElement);
                }
            }

            return(result);
        }
        public override LocalList <IDeclaredElement> GetRootMarksFromNode(ITreeNode currentNode,
                                                                          IDeclaredElement containingFunction)
        {
            var result            = new LocalList <IDeclaredElement>();
            var coroutineOrInvoke = ExtractCoroutineOrInvokeRepeating(currentNode);

            if (coroutineOrInvoke != null)
            {
                result.Add(coroutineOrInvoke);
            }

            // it means we are in functional type member like methodDeclaration
            if (containingFunction == null)
            {
                return(result);
            }

            var functionDeclaration = currentNode as IFunctionDeclaration;
            var hasComment          = UnityCallGraphUtil.HasAnalysisComment(functionDeclaration, MarkId, ReSharperControlConstruct.Kind.Restore);

            if (hasComment)
            {
                result.Add(functionDeclaration.DeclaredElement);
            }

            var declaration = currentNode as ITypeMemberDeclaration;
            var typeMember  = declaration?.DeclaredElement;

            if (PerformanceCriticalCodeStageUtil.IsPerformanceCriticalRootMethod(typeMember))
            {
                result.Add(typeMember);
            }

            return(result);
        }
        public override bool HasContext(IDeclaration declaration, DaemonProcessKind processKind)
        {
            var functionDeclaration = declaration as IFunctionDeclaration;
            var hasComment          = UnityCallGraphUtil.HasAnalysisComment(functionDeclaration,
                                                                            MarkId, ReSharperControlConstruct.Kind.Restore);

            return(hasComment || base.HasContext(declaration, processKind));
        }
        protected override bool CheckCallGraph(IMethodDeclaration methodDeclaration, IReadOnlyCallGraphContext context)
        {
            if (!UnityCallGraphUtil.IsCallGraphReady(myConfiguration))
            {
                return(false);
            }

            return(base.CheckCallGraph(methodDeclaration, context));
        }
        public override void AddFrequentlyCalledMethodHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration declaration, string text,
                                                                   string tooltip, DaemonProcessKind kind)
        {
            var isHot = declaration.HasHotIcon(ContextProvider, SettingsStore.BoundSettingsStore, kind);

            if (!isHot)
            {
                return;
            }

            if (RiderIconProviderUtil.IsCodeVisionEnabled(SettingsStore.BoundSettingsStore, myCodeInsightProvider.ProviderId,
                                                          () => { base.AddFrequentlyCalledMethodHighlighting(consumer, declaration, text, tooltip, kind); }, out _))
            {
                IEnumerable <BulbMenuItem> actions;
                if (declaration.DeclaredElement is IMethod method && UnityApi.IsEventFunction(method))
                {
                    actions = GetEventFunctionActions(declaration);
                }
                else
                {
                    if (declaration is IMethodDeclaration methodDeclaration)
                    {
                        var textControl = myTextControlManager.LastFocusedTextControl.Value;
                        var compactList = new CompactList <BulbMenuItem>();
                        var performanceDisableAction =
                            new PerformanceAnalysisDisableByCommentBulbAction(methodDeclaration);
                        var performanceDisableBulbItem = new BulbMenuItem(
                            new IntentionAction.MyExecutableProxi(performanceDisableAction, mySolution, textControl),
                            performanceDisableAction.Text,
                            BulbThemedIcons.ContextAction.Id, BulbMenuAnchors.FirstClassContextItems);
                        compactList.Add(performanceDisableBulbItem);

                        if (!UnityCallGraphUtil.HasAnalysisComment(methodDeclaration, ExpensiveCodeMarksProvider.MarkId,
                                                                   ReSharperControlConstruct.Kind.Restore))
                        {
                            var expensiveBulbAction = new AddExpensiveCommentBulbAction(methodDeclaration);
                            var expensiveBulbItem   = new BulbMenuItem(
                                new IntentionAction.MyExecutableProxi(expensiveBulbAction, mySolution, textControl),
                                expensiveBulbAction.Text,
                                BulbThemedIcons.ContextAction.Id, BulbMenuAnchors.FirstClassContextItems);

                            compactList.Add(expensiveBulbItem);
                        }

                        actions = compactList;
                    }
                    else
                    {
                        actions = EmptyList <BulbMenuItem> .Instance;
                    }
                }

                myCodeInsightProvider.AddHighlighting(consumer, declaration, declaration.DeclaredElement, text, tooltip, text,
                                                      myIconHost.Transform(InsightUnityIcons.InsightHot.Id), actions, RiderIconProviderUtil.GetExtraActions(mySolutionTracker, myBackendUnityHost));
            }
            public override bool InteriorShouldBeProcessed(ITreeNode element)
            {
                SeldomInterruptChecker.CheckForInterrupt();

                if (element == StartTreeNode)
                {
                    return(true);
                }

                return(!UnityCallGraphUtil.IsFunctionNode(element) && !IsBurstProhibitedNode(element));
            }
Esempio n. 10
0
        public virtual bool InteriorShouldBeProcessed(ITreeNode element)
        {
            SeldomInterruptChecker.CheckForInterrupt();

            if (element == StartTreeNode)
            {
                return(true);
            }

            return(!UnityCallGraphUtil.IsFunctionNode(element));
        }
        protected override bool CheckCallGraph(IMethodDeclaration methodDeclaration, IReadOnlyCallGraphContext context)
        {
            var callGraphReady = UnityCallGraphUtil.IsCallGraphReady(myConfiguration);

            if (!callGraphReady)
            {
                return(false);
            }

            var declaredElement = methodDeclaration.DeclaredElement;

            return(myExpensiveContextProvider.IsMarkedStage(declaredElement, context));
        }
Esempio n. 12
0
        public static bool IsMarkedSweaDependent(
            [CanBeNull] this ICallGraphContextProvider contextProvider,
            [CanBeNull] IDeclaredElement declaredElement,
            [CanBeNull] SolutionAnalysisConfiguration configuration)
        {
            if (contextProvider == null || declaredElement == null || configuration == null)
            {
                return(false);
            }

            return(UnityCallGraphUtil.IsCallGraphReady(configuration)
                ? contextProvider.IsMarkedGlobal(declaredElement)
                : contextProvider.IsMarkedLocal(declaredElement));
        }
        public override LocalList <IDeclaredElement> GetRootMarksFromNode(ITreeNode currentNode,
                                                                          IDeclaredElement containingFunction)
        {
            var result = new LocalList <IDeclaredElement>();

            switch (currentNode)
            {
            case IFunctionDeclaration functionDeclaration when containingFunction != null:
            {
                if (UnityCallGraphUtil.HasAnalysisComment(functionDeclaration,
                                                          MarkId, ReSharperControlConstruct.Kind.Restore))
                {
                    result.Add(functionDeclaration.DeclaredElement);
                }

                break;
            }

            case IClassLikeDeclaration classLikeDeclaration:
            {
                var typeElement = classLikeDeclaration.DeclaredElement;

                if (typeElement == null ||
                    !typeElement.HasAttributeInstance(KnownTypes.BurstCompileAttribute, AttributesSource.Self))
                {
                    break;
                }

                if (typeElement is IStruct @struct)
                {
                    result = GetMarksFromStruct(@struct);
                }

                foreach (var method in typeElement.Methods)
                {
                    if (method.IsStatic &&
                        method.HasAttributeInstance(KnownTypes.BurstCompileAttribute, AttributesSource.Self))
                    {
                        result.Add(method);
                    }
                }

                break;
            }
            }

            return(result);
        }
Esempio n. 14
0
        public override LocalList <IDeclaredElement> GetRootMarksFromNode(ITreeNode currentNode,
                                                                          IDeclaredElement containingFunction)
        {
            var result = new LocalList <IDeclaredElement>();

            // it means we are in functional type member like methodDeclaration
            if (containingFunction == null)
            {
                return(result);
            }

            var declaration     = currentNode as IDeclaration;
            var declaredElement = declaration?.DeclaredElement;

            if (declaredElement == null || !UnityCallGraphUtil.IsFunctionNode(declaration))
            {
                return(result);
            }

            var hasComment = false;

            if (declaration is IFunctionDeclaration functionDeclaration)
            {
                hasComment = UnityCallGraphUtil.HasAnalysisComment(functionDeclaration, MarkId, ReSharperControlConstruct.Kind.Restore);
            }

            if (hasComment)
            {
                result.Add(declaredElement);
            }
            else
            {
                using (var processor = new ExpensiveCodeProcessor(declaration))
                {
                    declaration.ProcessThisAndDescendants(processor);

                    if (processor.ProcessingIsFinished)
                    {
                        result.Add(declaredElement);
                    }
                }
            }

            return(result);
        }
        public BurstProblemSubAnalyzerStatus CheckAndAnalyze(IInvocationExpression invocationExpression, IHighlightingConsumer consumer)
        {
            var invokedMethod = invocationExpression.Reference.Resolve().DeclaredElement as IMethod;

            if (invokedMethod == null || UnityCallGraphUtil.IsQualifierOpenType(invocationExpression))
            {
                return(BurstProblemSubAnalyzerStatus.NO_WARNING_STOP);
            }

            if (!IsBurstProhibitedObjectMethod(invokedMethod))
            {
                return(BurstProblemSubAnalyzerStatus.NO_WARNING_CONTINUE);
            }

            consumer?.AddHighlighting(new BurstAccessingManagedMethodWarning(invocationExpression,
                                                                             invokedMethod.ShortName, invokedMethod.GetContainingType()?.ShortName));

            return(BurstProblemSubAnalyzerStatus.WARNING_PLACED_STOP);
        }
        public override LocalList <IDeclaredElement> GetBanMarksFromNode(ITreeNode currentNode,
                                                                         IDeclaredElement containingFunction)
        {
            var result = new LocalList <IDeclaredElement>();

            // it means we are in functional type member like methodDeclaration
            if (containingFunction == null)
            {
                return(result);
            }

            var functionDeclaration = currentNode as IFunctionDeclaration;
            var element             = UnityCallGraphUtil.HasAnalysisComment(functionDeclaration, UnityCallGraphUtil.PerformanceExpensiveComment, ReSharperControlConstruct.Kind.Disable);

            if (element)
            {
                result.Add(functionDeclaration.DeclaredElement);
            }

            return(result);
        }
        protected IReadOnlyList <BulbMenuItem> GetEventFunctionActions(ICSharpDeclaration declaration, IReadOnlyCallGraphContext context)
        {
            if (!(declaration is IMethodDeclaration methodDeclaration))
            {
                return(EmptyList <BulbMenuItem> .Instance);
            }

            var declaredElement = methodDeclaration.DeclaredElement;
            var textControl     = mySolution.GetComponent <ITextControlManager>().LastFocusedTextControl.Value;

            if (textControl == null || declaredElement == null)
            {
                return(EmptyList <BulbMenuItem> .Instance);
            }

            var isCoroutine = IsCoroutine(methodDeclaration, UnityApi);
            var result      = GetBulbMenuItems(declaration, context) as List <BulbMenuItem> ?? new List <BulbMenuItem>();

            if (isCoroutine.HasValue)
            {
                var bulbAction = isCoroutine.Value
                    ? (IBulbAction) new ConvertFromCoroutineBulbAction(methodDeclaration)
                    : new ConvertToCoroutineBulbAction(methodDeclaration);

                var menuITem = UnityCallGraphUtil.BulbActionToMenuItem(bulbAction, textControl, mySolution, BulbThemedIcons.ContextAction.Id);

                result.Add(menuITem);
            }

            if (UnityApi.IsEventFunction(declaredElement))
            {
                var showUnityHelp = mySolution.GetComponent <ShowUnityHelp>();
                var documentationNavigationAction = new DocumentationNavigationAction(showUnityHelp, declaredElement, UnityApi);
                var menuItem = UnityCallGraphUtil.BulbActionToMenuItem(documentationNavigationAction, textControl, mySolution, CommonThemedIcons.Question.Id);

                result.Add(menuItem);
            }

            return(result);
        }
        protected override void CollectHighlightings(IPsiDocumentRangeView psiDocumentRangeView, HighlightingsConsumer consumer)
        {
            var view = psiDocumentRangeView.View <CSharpLanguage>();
            var node = view.GetSelectedTreeNode <IFunctionDeclaration>();

            if (node == null)
            {
                return;
            }

            var solution = psiDocumentRangeView.Solution;
            var swa      = solution.GetComponent <SolutionAnalysisService>();

            if (!UnityCallGraphUtil.IsSweaCompleted(swa))
            {
                return;
            }

            var contextProvider = solution.GetComponent <PerformanceCriticalContextProvider>();
            var settingsStore   = psiDocumentRangeView.GetSettingsStore();

            if (contextProvider.IsContextAvailable == false)
            {
                return;
            }

            if (settingsStore.GetValue((UnitySettings key) => key.PerformanceHighlightingMode) !=
                PerformanceHighlightingMode.CurrentMethod)
            {
                return;
            }

            var kind = UnityCallGraphUtil.GetProcessKindForGraph(swa);

            if (contextProvider.HasContext(node, kind))
            {
                consumer.ConsumeHighlighting(new UnityPerformanceContextHighlightInfo(node.GetDocumentRange()));
            }
        }
        public override bool HasContext(IDeclaration declaration, DaemonProcessKind processKind)
        {
            if (IsContextAvailable == false)
            {
                return(false);
            }

            if (declaration == null || IsBurstProhibitedNode(declaration))
            {
                return(false);
            }

            var functionDeclaration = declaration as IFunctionDeclaration;

            if (UnityCallGraphUtil.HasAnalysisComment(functionDeclaration,
                                                      BurstMarksProvider.MarkId, ReSharperControlConstruct.Kind.Restore))
            {
                return(true);
            }

            return(base.HasContext(declaration, processKind));
        }
        public void Execute(ISolution solution, ITextControl textControl)
        {
            solution.Locks.AssertReadAccessAllowed();

            var text = Text;

            if (!UnityCallGraphUtil.IsCallGraphReady(solution))
            {
                BulbActionUtils.ShowTooltip(text + TooltipSuffix, textControl);
                return;
            }

            if (!solution.GetPsiServices().Caches.WaitForCaches(text))
            {
                return;
            }

            var manager  = CallHierarchyExplorerViewManager.GetInstance(solution);
            var filter   = GetFilter(solution);
            var start    = GetStartElement();
            var callType = CallsType;

            ShowCalls(manager, filter, start, callType);
        }
Esempio n. 21
0
        public bool HasMarkComment(ITreeNode node, out bool isMarked)
        {
            var commentToFind = myNameToFind;

            return(UnityCallGraphUtil.HasAnalysisComment(commentToFind, node, out isMarked));
        }
Esempio n. 22
0
 public virtual bool IsContextChangingNode(ITreeNode node) => UnityCallGraphUtil.IsFunctionNode(node);
 public static IEnumerable <BulbMenuItem> ToMenuItems(this IEnumerable <ShowCallsBulbActionBase> bulbs, ITextControl textControl,
                                                      ISolution solution)
 {
     return(bulbs.Select(bulb => UnityCallGraphUtil.BulbActionToMenuItem(bulb, textControl, solution, bulb.Icon)));
 }
Esempio n. 24
0
 public static bool HasPerformanceBanComment(ITreeNode node)
 {
     return(UnityCallGraphUtil.HasAnalysisComment(UnityCallGraphUtil.PerformanceAnalysisComment, node, out var isMarked) &&
            !isMarked);
 }