private void AddHighlighting(IHighlightingConsumer consumer, AbstractUnityCodeInsightProvider codeInsightsProvider, ICSharpDeclaration element, string tooltip, string displayName)
        {
            if (SettingsStore.GetIndexedValue((CodeInsightsSettings key) => key.DisabledProviders, codeInsightsProvider.ProviderId))
            {
                base.AddHighlighting(consumer, element, tooltip);
                return;
            }

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

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

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


            var extraActions = new List <CodeLensEntryExtraActionModel>();

            if (!myConnectionTracker.IsConnectionEstablished())
            {
                extraActions.Add(new CodeLensEntryExtraActionModel("Unity is off", null));
                extraActions.Add(new CodeLensEntryExtraActionModel("Start Unity", AbstractUnityCodeInsightProvider.StartUnityActionId));
            }

            consumer.AddHighlighting(new UnityCodeInsightsHighlighting(element.GetNameDocumentRange(),
                                                                       displayName, displayName, codeInsightsProvider, declaredElement,
                                                                       myIconHost.Transform(codeInsightsProvider.IconId), CreateBulbItemsForUnityDeclaration(element), extraActions));
        }
예제 #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));
        }