public void RunInspection(ITreeNode node, IHighlightingConsumer consumer, IReadOnlyCallGraphContext context) { if (node is T t && IsApplicable(context)) { Analyze(t, consumer, context); } }
protected override void AddMonoBehaviourHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration element, string text, string tooltip, IReadOnlyCallGraphContext context) { if (!myAssetSerializationMode.IsForceText || !SettingsStore.BoundSettingsStore.GetValue((UnitySettings key) => key.EnableInspectorPropertiesEditor) || !SettingsStore.BoundSettingsStore.GetValue((UnitySettings key) => key.IsAssetIndexingEnabled)) { AddHighlighting(consumer, element, text, tooltip, context); return; } if (RiderIconProviderUtil.IsCodeVisionEnabled(SettingsStore.BoundSettingsStore, myFieldUsageProvider.ProviderId, () => { base.AddHighlighting(consumer, element, text, tooltip, context); }, out var useFallback)) { if (!useFallback) { consumer.AddImplicitConfigurableHighlighting(element); } var isProcessing = myDeferredCacheController.IsProcessingFiles(); myFieldUsageProvider.AddInspectorHighlighting(consumer, element, element.DeclaredElement, text, tooltip, isProcessing ? "Inspector values are not available during asset indexing" : text, isProcessing ? myIconHost.Transform(CodeInsightsThemedIcons.InsightWait.Id) : myIconHost.Transform(InsightUnityIcons.InsightUnity.Id), GetActions(element), RiderIconProviderUtil.GetExtraActions(mySolutionTracker, myBackendUnityHost)); } }
protected override bool CheckCallGraph(IMethodDeclaration methodDeclaration, IReadOnlyCallGraphContext context) { var declaredElement = methodDeclaration.DeclaredElement; return(!myExpensiveContextProvider.IsMarkedStage(declaredElement, context) && base.CheckCallGraph(methodDeclaration, context)); }
public static bool HasHotIcon(this ICSharpDeclaration element, PerformanceCriticalContextProvider contextProvider, IContextBoundSettingsStore settingsStore, IReadOnlyCallGraphContext context) { var declaredElement = element.DeclaredElement; return(declaredElement.HasHotIcon(contextProvider, settingsStore, context)); }
private void AddAnimationEventAndEventHandlerHighlighting([NotNull] ITreeNode treeNode, [NotNull] IHighlightingConsumer consumer, IReadOnlyCallGraphContext context) { AddHighlighting(consumer, treeNode as ICSharpDeclaration, "Animation event and event handler", "Unity animation event and Unity animation event", context); }
protected override void Analyze(IReferenceExpression referenceExpression, IHighlightingConsumer consumer, IReadOnlyCallGraphContext context) { if (PerformanceCriticalCodeStageUtil.IsCameraMainUsage(referenceExpression)) { consumer.AddHighlighting(new UnityPerformanceCameraMainWarning(referenceExpression)); } }
protected override void Analyze(IFunctionDeclaration t, IHighlightingConsumer consumer, IReadOnlyCallGraphContext context) { if (LineMarkerStatus.Value == PerformanceHighlightingMode.Always) { consumer.AddHighlighting(new UnityPerformanceCriticalCodeLineMarker(t.GetNameDocumentRange())); } }
protected override void Analyze(IEqualityExpression equalityExpression, IHighlightingConsumer consumer, IReadOnlyCallGraphContext context) { if (PerformanceCriticalCodeStageUtil.IsNullComparisonWithUnityObject(equalityExpression, out var name)) { consumer.AddHighlighting(new UnityPerformanceNullComparisonWarning(equalityExpression, name, equalityExpression.Reference.NotNull("eqaulityReference != null"))); } }
protected override bool CheckCallGraph(IMethodDeclaration methodDeclaration, IReadOnlyCallGraphContext context) { if (!UnityCallGraphUtil.IsCallGraphReady(myConfiguration)) { return(false); } return(base.CheckCallGraph(methodDeclaration, context)); }
protected override void Analyze(IMultiplicativeExpression expression, IHighlightingConsumer consumer, IReadOnlyCallGraphContext context) { if (IsStartPoint(expression)) { var count = 0; bool hasMatrix = false; var enumerator = expression.ThisAndDescendants <ICSharpExpression>(); var scalars = new List <ICSharpExpression>(); var matrices = new List <ICSharpExpression>(); while (enumerator.MoveNext()) { var element = enumerator.Current; var mul = GetMulOperation(element.GetOperandThroughParenthesis()); if (mul == null) { var type = IsMatrixTypeInner(element); if (type == MatrixTypeState.Unknown) { return; } if (type == MatrixTypeState.Scalar) { count++; scalars.Add(element); } else { hasMatrix = true; matrices.Add(element); } enumerator.SkipThisNode(); } else { // merge scalar mul if (IsMatrixTypeInner(mul) == MatrixTypeState.Scalar) { scalars.Add(mul); count++; enumerator.SkipThisNode(); } } } if (hasMatrix & count > 1) { consumer.AddHighlighting(new InefficientMultiplicationOrderWarning(expression, scalars, matrices)); } } }
protected override bool CheckAndAnalyze(IObjectCreationExpression objectCreationExpression, IHighlightingConsumer consumer, IReadOnlyCallGraphContext context) { if (!IsBurstPermittedType(objectCreationExpression.Type())) { consumer?.AddHighlighting(new BurstCreatingManagedTypeWarning(objectCreationExpression, (objectCreationExpression.ConstructorReference.Resolve().DeclaredElement as IConstructor)?.GetContainingType()?.ShortName)); return(true); } return(false); }
private void TryAddAnimationEventHighlightingForPropertyGetter(ITreeNode treeNode, IHighlightingConsumer consumer, IReadOnlyCallGraphContext context, IProperty property) { var getter = property.Getter; if (getter != null && myAnimationEventUsagesContainer.GetEventUsagesCountFor(getter, out _) > 0) { AddAnimationEventHighlighting(treeNode, consumer, context); } }
protected override void AddHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration element, string text, string tooltip, IReadOnlyCallGraphContext context) { consumer.AddImplicitConfigurableHighlighting(element); var isIconHot = element.HasHotIcon(ContextProvider, SettingsStore.BoundSettingsStore, context); var highlighting = isIconHot ? new UnityHotGutterMarkInfo(GetActions(element), element, tooltip) : (IHighlighting) new UnityGutterMarkInfo(GetActions(element), element, tooltip); consumer.AddHighlighting(highlighting); }
private bool TryAddAnimationEventHighlightingForAccessorMethod(ITreeNode treeNode, IHighlightingConsumer consumer, IReadOnlyCallGraphContext context, IDeclaredElement method) { var isAnimationEvent = myAnimationEventUsagesContainer.GetEventUsagesCountFor(method, out _) > 0; if (isAnimationEvent) { AddAnimationEventHighlighting(treeNode, consumer, context); } return(isAnimationEvent); }
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)); }
private bool ShouldAddCodeVision( IMethodDeclaration methodDeclaration, IHighlightingConsumer consumer, IReadOnlyCallGraphContext context) { var isBurstIconsEnabled = base.IsGutterMarkEnabled; var boundStore = mySettingsStore.BoundSettingsStore; var providerId = myBurstCodeInsightProvider.ProviderId; void Fallback() => base.Analyze(methodDeclaration, consumer, context); return(isBurstIconsEnabled && RiderIconProviderUtil.IsCodeVisionEnabled(boundStore, providerId, Fallback, out _)); }
public static bool HasHotIcon(this IDeclaredElement element, PerformanceCriticalContextProvider contextProvider, IContextBoundSettingsStore settingsStore, IReadOnlyCallGraphContext context) { if (element == null) { return(false); } if (!settingsStore.GetValue((UnitySettings key) => key.EnableIconsForPerformanceCriticalCode)) { return(false); } return(contextProvider.IsMarkedStage(element, context)); }
protected override bool CheckAndAnalyze(IStringLiteralOwner stringLiteralOwner, IHighlightingConsumer consumer, IReadOnlyCallGraphContext context) { bool isString; if (stringLiteralOwner is ICSharpLiteralExpression cSharpLiteralExpression) { isString = cSharpLiteralExpression.Literal.GetTokenType().IsStringLiteral; } else { isString = true; } return(isString && CheckAndAnalyze(stringLiteralOwner, new BurstManagedStringWarning(stringLiteralOwner), consumer)); }
protected override void AddHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration element, string text, string tooltip, IReadOnlyCallGraphContext context) { if (RiderIconProviderUtil.IsCodeVisionEnabled(SettingsStore.BoundSettingsStore, myFieldUsageProvider.ProviderId, () => { base.AddHighlighting(consumer, element, text, tooltip, context); }, out var useFallback)) { if (!useFallback) { consumer.AddImplicitConfigurableHighlighting(element); } myFieldUsageProvider.AddHighlighting(consumer, element, element.DeclaredElement, text, tooltip, text, myIconHost.Transform(InsightUnityIcons.InsightUnity.Id), GetActions(element), RiderIconProviderUtil.GetExtraActions(mySolutionTracker, myBackendUnityHost)); } }
protected override void Analyze(IInvocationExpression invocationExpression, IHighlightingConsumer consumer, IReadOnlyCallGraphContext context) { var invokedMethod = invocationExpression.Reference.Resolve().DeclaredElement as IMethod; if (!BurstCodeAnalysisUtil.IsSharedStaticCreateMethod(invokedMethod)) { return; } var substitution = invocationExpression.Reference.Resolve().Substitution; var domain = substitution.Domain; var sharedStaticDomain = domain.Where(parameter => parameter.OwnerType is IStruct @struct && @struct.GetClrName().Equals(KnownTypes.SharedStatic)) .ToList(); Assertion.Assert(sharedStaticDomain.Count == 1, "SharedStatic should have 1 substitution"); if (sharedStaticDomain.Count != 1) { return; } var typeParameter = sharedStaticDomain[0]; // it means Burst finally supported type parameter unmanaged constraint Assertion.Assert(!typeParameter.IsUnmanagedType, "SharedStatic doesn't have unmanaged constraint"); if (!typeParameter.IsValid() || typeParameter.IsUnmanagedType) { return; } var substitutedType = substitution.Apply(typeParameter); if (substitutedType.IsUnmanagedType(invocationExpression.GetLanguageVersion())) { return; } var typeParameterName = substitutedType.GetTypeElement()?.ShortName; if (typeParameterName != null) { consumer.AddHighlighting(new SharedStaticUnmanagedTypeWarning(invocationExpression, typeParameterName)); } }
public override bool AddDeclarationHighlighting(IDeclaration treeNode, IHighlightingConsumer consumer, IReadOnlyCallGraphContext context) { var declaredElement = treeNode.DeclaredElement; var method = declaredElement as IMethod; if (method is IAccessor) { return(TryAddAnimationEventHighlightingForAccessorMethod(treeNode, consumer, context, method)); } if (declaredElement is IProperty property) { TryAddAnimationEventHighlightingForPropertyGetter(treeNode, consumer, context, property); method = property.Setter; } return(method != null && TryAddMethodHighlighting(treeNode, consumer, context, method)); }
public override void AddEventFunctionHighlighting(IHighlightingConsumer consumer, IMethod method, UnityEventFunction eventFunction, string text, IReadOnlyCallGraphContext context) { var boundStore = SettingsStore.BoundSettingsStore; var providerId = myCodeInsightProvider.ProviderId; void Fallback() => base.AddEventFunctionHighlighting(consumer, method, eventFunction, text, context); // here is order of IsCodeVisionEnabled and hasHotIcon matters // hasHotIcon differs if hot icon or event function icon, it depends on multiple settings if (!RiderIconProviderUtil.IsCodeVisionEnabled(boundStore, providerId, Fallback, out var useFallback)) { return; } var iconId = method.HasHotIcon(PerformanceContextProvider, boundStore, context) ? InsightUnityIcons.InsightHot.Id : InsightUnityIcons.InsightUnity.Id; var iconModel = myIconHost.Transform(iconId); var extraActions = RiderIconProviderUtil.GetExtraActions(mySolutionTracker, myBackendUnityHost); foreach (var declaration in method.GetDeclarations()) { if (!(declaration is ICSharpDeclaration cSharpDeclaration)) { continue; } if (!useFallback) { consumer.AddImplicitConfigurableHighlighting(cSharpDeclaration); } var actions = GetEventFunctionActions(cSharpDeclaration, context); myCodeInsightProvider.AddHighlighting(consumer, cSharpDeclaration, method, text, eventFunction.Description ?? string.Empty, text, iconModel, actions, extraActions); } }
public static void AddHotHighlighting(this IHighlightingConsumer consumer, PerformanceCriticalContextProvider contextProvider, ICSharpDeclaration element, IContextBoundSettingsStore settings, string text, string tooltip, IReadOnlyCallGraphContext context, IEnumerable <BulbMenuItem> items, bool onlyHot = false) { var isIconHot = element.HasHotIcon(contextProvider, settings, context); if (onlyHot && !isIconHot) { return; } var highlighting = isIconHot ? new UnityHotGutterMarkInfo(items, element, tooltip) : (IHighlighting) new UnityGutterMarkInfo(items, element, tooltip); consumer.AddHighlighting(highlighting); }
protected override void Analyze(IMethodDeclaration methodDeclaration, IHighlightingConsumer consumer, IReadOnlyCallGraphContext context) { if (!ShouldAddCodeVision(methodDeclaration, consumer, context)) { return; } var declaredElement = methodDeclaration.DeclaredElement; var iconModel = myIconHost.Transform(InsightUnityIcons.InsightUnity.Id); var actions = myCodeInsights.GetBurstActions(methodDeclaration, context); myBurstCodeInsightProvider.AddHighlighting(consumer, methodDeclaration, declaredElement, BurstCodeAnalysisUtil.BURST_DISPLAY_NAME, BurstCodeAnalysisUtil.BURST_TOOLTIP, BurstCodeAnalysisUtil.BURST_DISPLAY_NAME, iconModel, actions, extraActions: null); }
protected override void AddHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration element, string text, string tooltip, IReadOnlyCallGraphContext context) { var iconId = element.HasHotIcon(ContextProvider, SettingsStore.BoundSettingsStore, context) ? InsightUnityIcons.InsightHot.Id : InsightUnityIcons.InsightUnity.Id; if (RiderIconProviderUtil.IsCodeVisionEnabled(SettingsStore.BoundSettingsStore, myCodeInsightProvider.ProviderId, () => { base.AddHighlighting(consumer, element, text, tooltip, context); }, out var useFallback)) { if (!useFallback) { consumer.AddImplicitConfigurableHighlighting(element); } IconModel iconModel = myIconHost.Transform(iconId); if (myAssetIndexingSupport.IsEnabled.Value && myAssetSerializationMode.IsForceText) { if (myDeferredCacheController.IsProcessingFiles()) { iconModel = myIconHost.Transform(CodeInsightsThemedIcons.InsightWait.Id); } if (!myDeferredCacheController.CompletedOnce.Value) { tooltip = "Usages in assets are not available during asset indexing"; } } if (!myAssetIndexingSupport.IsEnabled.Value || !myDeferredCacheController.CompletedOnce.Value || !myAssetSerializationMode.IsForceText) { myCodeInsightProvider.AddHighlighting(consumer, element, element.DeclaredElement, text, tooltip, text, iconModel, GetActions(element), RiderIconProviderUtil.GetExtraActions(mySolutionTracker, myBackendUnityHost)); } else { AddEventsHighlighting(consumer, element, iconModel); } } }
public static bool IsMarkedStage( [CanBeNull] this ICallGraphContextProvider contextProvider, [CanBeNull] IDeclaredElement declaredElement, [CanBeNull] IReadOnlyCallGraphContext context) { if (contextProvider == null || declaredElement == null || context == null) { return(false); } switch (context.Kind) { case DaemonProcessKind.VISIBLE_DOCUMENT: return(contextProvider.IsMarkedLocal(declaredElement, context.DataElement)); case DaemonProcessKind.GLOBAL_WARNINGS: return(contextProvider.IsMarkedGlobal(declaredElement)); default: return(false); } }
protected abstract bool CheckCallGraph([NotNull] IMethodDeclaration methodDeclaration, [NotNull] IReadOnlyCallGraphContext context);
public IEnumerable <BulbMenuItem> GetMenuItems(IMethodDeclaration methodDeclaration, ITextControl textControl, IReadOnlyCallGraphContext context) { methodDeclaration.GetPsiServices().Locks.AssertReadAccessAllowed(); if (!CheckCallGraph(methodDeclaration, context)) { return(EmptyList <BulbMenuItem> .Enumerable); } var result = GetActions(methodDeclaration, textControl); return(result); }
public IEnumerable <BulbMenuItem> GetBurstActions([NotNull] IMethodDeclaration methodDeclaration, IReadOnlyCallGraphContext context) { var result = new CompactList <BulbMenuItem>(); var textControl = myTextControlManager.LastFocusedTextControl.Value; foreach (var bulbProvider in myBulbProviders) { var menuItems = bulbProvider.GetMenuItems(methodDeclaration, textControl, context); foreach (var item in menuItems) { result.Add(item); } } return(result); }
public override void AddFrequentlyCalledMethodHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration cSharpDeclaration, string text, string tooltip, IReadOnlyCallGraphContext context) { var boundStore = SettingsStore.BoundSettingsStore; // here is order of IsCodeVisionEnabled and hasHotIcon matters also // hasHotIcon and IsCodeVisionEnabled checks if hot icon should be enabled. if it shouldn't - nothing would be displayed if (!cSharpDeclaration.HasHotIcon(PerformanceContextProvider, boundStore, context)) { return; } void Fallback() => base.AddFrequentlyCalledMethodHighlighting(consumer, cSharpDeclaration, text, tooltip, context); var providerId = myCodeInsightProvider.ProviderId; if (!RiderIconProviderUtil.IsCodeVisionEnabled(boundStore, providerId, Fallback, out _)) { return; } // code vision var actions = GetActions(cSharpDeclaration, context); var extraActions = RiderIconProviderUtil.GetExtraActions(mySolutionTracker, myBackendUnityHost); var iconModel = myIconHost.Transform(InsightUnityIcons.InsightHot.Id); myCodeInsightProvider.AddHighlighting(consumer, cSharpDeclaration, cSharpDeclaration.DeclaredElement, text, tooltip, text, iconModel, actions, extraActions); }