Exemplo n.º 1
0
        public override void AddFrequentlyCalledMethodHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration declaration, string text,
                                                                   string tooltip, DaemonProcessKind kind)
        {
            var isHot = declaration.HasHotIcon(CallGraphSwaExtensionProvider, SettingsStore.BoundSettingsStore, MarksProvider, kind, myProvider);

            if (!isHot)
            {
                return;
            }

            if (RiderIconProviderUtil.IsCodeVisionEnabled(SettingsStore.BoundSettingsStore, myCodeInsightProvider.ProviderId,
                                                          () => { base.AddFrequentlyCalledMethodHighlighting(consumer, declaration, text, tooltip, kind); }, out var useFallback))
            {
                IEnumerable <BulbMenuItem> actions;
                if (declaration.DeclaredElement is IMethod method && UnityApi.IsEventFunction(method))
                {
                    actions = GetEventFunctionActions(declaration);
                }
                else
                {
                    actions = EmptyList <BulbMenuItem> .Instance;
                }

                myCodeInsightProvider.AddHighlighting(consumer, declaration, declaration.DeclaredElement, text, tooltip, text,
                                                      myIconHost.Transform(InsightUnityIcons.InsightHot.Id), actions, RiderIconProviderUtil.GetExtraActions(mySolutionTracker, myBackendUnityHost));
            }
Exemplo n.º 2
0
        private void AddHighlighting(IHighlightingConsumer consumer,
                                     AbstractUnityCodeInsightProvider codeInsightsProvider, ICSharpDeclaration element, string tooltip,
                                     string displayName, DaemonProcessKind kind, bool addOnlyHotIcon = false)
        {
            if (SettingsStore.GetIndexedValue((CodeInsightsSettings key) => key.DisabledProviders,
                                              codeInsightsProvider.ProviderId))
            {
                base.AddHighlighting(consumer, element, tooltip, displayName, kind, addOnlyHotIcon);
                return;
            }

            if (SettingsStore.GetValue((UnitySettings key) => key.GutterIconMode) == GutterIconMode.Always)
            {
                base.AddHighlighting(consumer, element, tooltip, displayName, kind, addOnlyHotIcon);
            }

            var isIconHot = IsHotIcon(element, kind);

            if (addOnlyHotIcon && !isIconHot)
            {
                return;
            }

            displayName = displayName ?? codeInsightsProvider.DisplayName;
            var declaredElement = element.DeclaredElement;

            if (declaredElement == null || !declaredElement.IsValid())
            {
                return;
            }

            // Since 19.2, Rider will show new code vision for scripts which will show
            // asset usages
            if (myUnityApi.IsDescendantOfMonoBehaviour(declaredElement as ITypeElement) ||
                declaredElement is IMethod method && !myUnityApi.IsEventFunction(method) &&
                myHandlerReferenceCache.IsEventHandler(method))
            {
                return;
            }


            var extraActions = new List <CodeLensEntryExtraActionModel>();

            if (mySolutionTracker.IsUnityProject.HasTrueValue() && !myConnectionTracker.IsConnectionEstablished())
            {
                extraActions.Add(new CodeLensEntryExtraActionModel("Unity is not running", null));
                extraActions.Add(new CodeLensEntryExtraActionModel("Start Unity Editor",
                                                                   AbstractUnityCodeInsightProvider.StartUnityActionId));
            }

            var iconId = isIconHot ? InsightUnityIcons.InsightHot.Id : InsightUnityIcons.InsightUnity.Id;

            consumer.AddHighlighting(new UnityCodeInsightsHighlighting(element.GetNameDocumentRange(),
                                                                       displayName, tooltip, displayName, codeInsightsProvider, declaredElement,
                                                                       myIconHost.Transform(iconId), CreateBulbItemsForUnityDeclaration(element), extraActions));
        }
        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));
            }
        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 IEnumerable <BulbMenuItem> GetEventFunctionActions(ICSharpDeclaration declaration)
        {
            var result = new List <BulbMenuItem>();

            if (declaration is IMethodDeclaration methodDeclaration)
            {
                var declaredElement = methodDeclaration.DeclaredElement;
                var textControl     = Solution.GetComponent <ITextControlManager>().LastFocusedTextControl.Value;

                if (textControl != null && declaredElement != null)
                {
                    var isCoroutine = IsCoroutine(methodDeclaration, UnityApi);
                    if (isCoroutine.HasValue)
                    {
                        IBulbAction bulbAction;
                        if (isCoroutine.Value)
                        {
                            bulbAction = new ConvertFromCoroutineBulbAction(methodDeclaration);
                        }
                        else
                        {
                            bulbAction = new ConvertToCoroutineBulbAction(methodDeclaration);
                        }

                        result.Add(new BulbMenuItem(
                                       new IntentionAction.MyExecutableProxi(bulbAction, Solution, textControl),
                                       bulbAction.Text, BulbThemedIcons.ContextAction.Id,
                                       BulbMenuAnchors.FirstClassContextItems));
                    }

                    if (UnityApi.IsEventFunction(declaredElement))
                    {
                        var documentationNavigationAction = new DocumentationNavigationAction(
                            Solution.GetComponent <ShowUnityHelp>(), declaredElement, UnityApi);
                        result.Add(new BulbMenuItem(
                                       new IntentionAction.MyExecutableProxi(documentationNavigationAction, Solution,
                                                                             textControl), documentationNavigationAction.Text, CommonThemedIcons.Question.Id,
                                       BulbMenuAnchors.FirstClassContextItems));
                    }
                }
            }

            return(result);
        }
Exemplo n.º 6
0
        private bool CanHaveAnyUsagesInUnity(IDeclaredElement declaredElement, UnityApi api)
        {
            if (declaredElement == null)
            {
                return(false);
            }
            if (declaredElement is IMethod method && !api.IsEventFunction(method) &&
                !api.IsUnityECSType(method.GetContainingType()))
            {
                return(true);
            }

            if (declaredElement is IClass type && !api.IsUnityECSType(type))
            {
                return(true);
            }

            return(false);
        }
        public override IEnumerable <BulbMenuItem> CreateAdditionalMenuItem(IDeclaration declaration, UnityApi api, ITextControl textControl)
        {
            var declaredElement = declaration.DeclaredElement;

            if (declaredElement != null && (declaredElement is IMethod method && !api.IsEventFunction(method) ||
                                            declaration is IClassDeclaration))
            {
                var action = new UnityFindUsagesNavigationAction(declaredElement,
                                                                 declaration.GetSolution().GetComponent <UnityEditorFindUsageResultCreator>(), myConnectionTracker);
                return(new[]
                {
                    new BulbMenuItem(
                        new IntentionAction.MyExecutableProxi(action, Solution, textControl),
                        action.Text, BulbThemedIcons.ContextAction.Id,
                        BulbMenuAnchors.FirstClassContextItems)
                });
            }


            return(EmptyList <BulbMenuItem> .Instance);
        }