public static bool HasHotIcon(this ICSharpDeclaration element, PerformanceCriticalContextProvider contextProvider, IContextBoundSettingsStore settingsStore, DaemonProcessKind kind) { var declaredElement = element.DeclaredElement; return(declaredElement.HasHotIcon(contextProvider, settingsStore, kind)); }
private static IBlock CreateMethodBody(ICSharpDeclaration declaration, MethodImplementationKind implementationKind) { var factory = CSharpElementFactory.GetInstance(declaration); switch (implementationKind) { case MethodImplementationKind.ThrowNotImplemented: { var predefinedType = declaration.GetPredefinedType(); return(factory.CreateBlock("{throw new $0();}", predefinedType.NotImplementedException)); } case MethodImplementationKind.ReturnDefaultValue: { return(CSharpReturnStatementMemberBodyProvider.CreateBody(declaration)); } case MethodImplementationKind.NotCompiledCode: { if (declaration.DeclaredElement is IMethod method && !method.ReturnType.IsVoid()) { return(factory.CreateBlock("{ return TODO_IMPLEMENT_ME; }")); } return(factory.CreateBlock("{ TODO_IMPLEMENT_ME(); }")); } default: { throw new ArgumentOutOfRangeException(nameof(implementationKind)); } } }
public virtual void AddFrequentlyCalledMethodHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration declaration, string text, string tooltip, DaemonProcessKind kind) { consumer.AddHotHighlighting(CallGraphSwaExtensionProvider, declaration, MarksProvider, Settings, text, tooltip, kind, EnumerableCollection <BulbMenuItem> .Empty, myProvider, true); }
public virtual void AddFrequentlyCalledMethodHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration declaration, string text, string tooltip, DaemonProcessKind kind) { consumer.AddHotHighlighting(ContextProvider, declaration, SettingsStore.BoundSettingsStore, text, tooltip, kind, EnumerableCollection <BulbMenuItem> .Empty, true); }
public static bool HasHotIcon(this ICSharpDeclaration element, PerformanceCriticalContextProvider contextProvider, IContextBoundSettingsStore settingsStore, IReadOnlyCallGraphContext context) { var declaredElement = element.DeclaredElement; return(declaredElement.HasHotIcon(contextProvider, settingsStore, context)); }
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); }
protected IReadOnlyList <BulbMenuItem> GetBulbMenuItems(ICSharpDeclaration declaration, IReadOnlyCallGraphContext context) { if (!(declaration is IMethodDeclaration methodDeclaration)) { return(EmptyList <BulbMenuItem> .Instance); } var iconsEnabled = context.DaemonProcess.ContextBoundSettingsStore.GetValue((UnitySettings key) => key.EnableIconsForPerformanceCriticalCode); if (!iconsEnabled) { return(EmptyList <BulbMenuItem> .Instance); } var textControl = myTextControlManager.LastFocusedTextControl.Value; var result = new List <BulbMenuItem>(); foreach (var provider in myMenuItemProviders) { var menuItems = provider.GetMenuItems(methodDeclaration, textControl, context); foreach (var item in menuItems) { result.Add(item); } } return(result); }
protected virtual void AddHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration element, string text, string tooltip, DaemonProcessKind kind) { consumer.AddImplicitConfigurableHighlighting(element); consumer.AddHotHighlighting(CallGraphSwaExtensionProvider, element, MarksProvider, SettingsStore.BoundSettingsStore, text, tooltip, kind, GetActions(element), ElementIdProvider); }
protected virtual bool IsHotIcon(ICSharpDeclaration element, DaemonProcessKind kind) { if (!SettingsStore.GetValue((UnitySettings key) => key.EnableIconsForPerformanceCriticalCode)) { return(false); } if (!SettingsStore.GetValue((UnitySettings key) => key.EnablePerformanceCriticalCodeHighlighting)) { return(false); } var declaredElement = element.DeclaredElement; if (declaredElement == null) { return(false); } var usageChecker = Swa.UsageChecker; if (usageChecker == null) { return(false); } var id = Swa.GetElementId(declaredElement, true); if (!id.HasValue) { return(false); } return(usageChecker.IsMarkedByCallGraphAnalyzer(PerformanceAnalyzerId, id.Value, kind == DaemonProcessKind.GLOBAL_WARNINGS)); }
public virtual void AddHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration element, IDeclaredElement declaredElement, string displayName, string tooltip, string moreText, IconModel iconModel, IEnumerable <BulbMenuItem> items, List <CodeLensEntryExtraActionModel> extraActions) { consumer.AddHighlighting(new UnityCodeInsightsHighlighting(element.GetNameDocumentRange(), displayName, tooltip, moreText, this, declaredElement, iconModel, items, extraActions)); }
protected IReadOnlyList <BulbMenuItem> GetActions(ICSharpDeclaration declaration, IReadOnlyCallGraphContext context) { if (declaration.DeclaredElement is IMethod method && UnityApi.IsEventFunction(method)) { return(GetEventFunctionActions(declaration, context)); } return(GetBulbMenuItems(declaration, context)); }
public virtual void AddFrequentlyCalledMethodHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration cSharpDeclaration, string text, string tooltip, IReadOnlyCallGraphContext context) { // gutter mark var actions = GetActions(cSharpDeclaration, context); consumer.AddHotHighlighting(PerformanceContextProvider, cSharpDeclaration, SettingsStore.BoundSettingsStore, text, tooltip, context, actions, true); }
public override void AddHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration element, string tooltip, string displayName) { if (element is IFieldDeclaration) { AddHighlighting(consumer, myFieldUsageProvider, element, tooltip, displayName); } else { AddHighlighting(consumer, myCodeInsightProvider, element, tooltip, displayName); } }
public override void AddHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration element, string tooltip, string displayName, DaemonProcessKind kind, bool addOnlyHotIcon = false) { if (element is IFieldDeclaration) { AddHighlighting(consumer, myFieldUsageProvider, element, tooltip, displayName, kind, addOnlyHotIcon); } else { AddHighlighting(consumer, myCodeInsightProvider, element, tooltip, displayName, kind, addOnlyHotIcon); } }
protected override void AddHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration element, string text, string tooltip, DaemonProcessKind kind) { consumer.AddImplicitConfigurableHighlighting(element); var isIconHot = element.HasHotIcon(myCallGraphSwaExtension, Settings, MarksProvider, kind, myProvider); var highlighting = isIconHot ? new UnityHotGutterMarkInfo(GetActions(element), element, tooltip) : (IHighlighting) new UnityGutterMarkInfo(GetActions(element), element, tooltip); consumer.AddHighlighting(highlighting); }
public static bool HasHotIcon(this ICSharpDeclaration element, CallGraphSwaExtensionProvider callGraphSwaExtensionProvider, IContextBoundSettingsStore settingsStore, PerformanceCriticalCodeCallGraphMarksProvider marksProvider, DaemonProcessKind kind, IElementIdProvider provider) { var declaredElement = element.DeclaredElement; if (declaredElement == null) { return(false); } return(declaredElement.HasHotIcon(callGraphSwaExtensionProvider, settingsStore, marksProvider, kind, provider)); }
public static bool HasHotIcon(this ICSharpDeclaration element, SolutionAnalysisService swa, CallGraphSwaExtensionProvider callGraphSwaExtensionProvider, IContextBoundSettingsStore settingsStore, PerformanceCriticalCodeCallGraphAnalyzer analyzer, DaemonProcessKind kind) { var declaredElement = element.DeclaredElement; if (declaredElement == null) { return(false); } return(declaredElement.HasHotIcon(swa, callGraphSwaExtensionProvider, settingsStore, analyzer, kind)); }
public virtual void AddHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration element, string tooltip) { var mode = SettingsStore.GetValue((UnitySettings key) => key.GutterIconMode); if (mode == GutterIconMode.None) { return; } var highlighting = new UnityGutterMarkInfo(element, tooltip); consumer.AddHighlighting(highlighting); }
protected override void AddHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration element, string text, string tooltip, DaemonProcessKind kind) { consumer.AddImplicitConfigurableHighlighting(element); var isIconHot = element.HasHotIcon(ContextProvider, SettingsStore.BoundSettingsStore, kind); var highlighting = isIconHot ? new UnityHotGutterMarkInfo(GetActions(element), element, tooltip) : (IHighlighting) new UnityGutterMarkInfo(GetActions(element), element, tooltip); consumer.AddHighlighting(highlighting); }
protected override void AddHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration element, string text, string tooltip, DaemonProcessKind kind) { if (RiderIconProviderUtil.IsCodeVisionEnabled(SettingsStore.BoundSettingsStore, myCodeInsightProvider.ProviderId, () => { base.AddHighlighting(consumer, element, text, tooltip, kind); }, out var useFallback)) { if (!useFallback) { consumer.AddImplicitConfigurableHighlighting(element); } myCodeInsightProvider.AddHighlighting(consumer, element, element.DeclaredElement, text, tooltip, text, myIconHost.Transform(InsightUnityIcons.InsightUnity.Id), GetActions(element), RiderIconProviderUtil.GetExtraActions(mySolutionTracker, myBackendUnityHost)); } }
protected override IEnumerable <BulbMenuItem> GetActions(ICSharpDeclaration declaration) { var result = new List <BulbMenuItem>(); var textControl = Solution.GetComponent <ITextControlManager>().LastFocusedTextControl.Value; if (declaration is IClassLikeDeclaration classLikeDeclaration && textControl != null && myUnityApi.IsUnityType(classLikeDeclaration.DeclaredElement)) { var fix = new GenerateUnityEventFunctionsFix(classLikeDeclaration); result.Add( new BulbMenuItem(new IntentionAction.MyExecutableProxi(fix, Solution, textControl), "Generate Unity event functions", PsiFeaturesUnsortedThemedIcons.FuncZoneGenerate.Id, BulbMenuAnchors.FirstClassContextItems) ); } 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); }
protected override void AddHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration element, string text, string tooltip, DaemonProcessKind kind) { var iconId = element.HasHotIcon(CallGraphSwaExtensionProvider, SettingsStore.BoundSettingsStore, MarksProvider, kind, ElementIdProvider) ? InsightUnityIcons.InsightHot.Id : InsightUnityIcons.InsightUnity.Id; if (RiderIconProviderUtil.IsCodeVisionEnabled(SettingsStore.BoundSettingsStore, myCodeInsightProvider.ProviderId, () => { base.AddHighlighting(consumer, element, text, tooltip, kind); }, 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 { var count = UnityEventsElementContainer.GetAssetUsagesCount(element.DeclaredElement, out var estimate); myUsagesCodeVisionProvider.AddHighlighting(consumer, element, element.DeclaredElement, count, "Click to view usages in assets", "Assets usages", estimate, iconModel); } } }
protected override void AddHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration element, string text, string tooltip, DaemonProcessKind kind) { var iconId = element.HasHotIcon(Swa, CallGraphSwaExtensionProvider, Settings, Analyzer, kind) ? InsightUnityIcons.InsightHot.Id : InsightUnityIcons.InsightUnity.Id; if (RiderIconProviderUtil.IsCodeVisionEnabled(Settings, myCodeInsightProvider.ProviderId, () => { base.AddHighlighting(consumer, element, text, tooltip, kind); }, out var useFallback)) { if (!useFallback) { consumer.AddImplicitConfigurableHighlighting(element); } myCodeInsightProvider.AddHighlighting(consumer, element, element.DeclaredElement, text, tooltip, text, myIconHost.Transform(iconId), GetActions(element), RiderIconProviderUtil.GetExtraActions(mySolutionTracker, myConnectionTracker)); } }
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, 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(iconId), GetActions(element), RiderIconProviderUtil.GetExtraActions(mySolutionTracker, myBackendUnityHost)); } }
public static void AddHotHighlighting(this IHighlightingConsumer consumer, PerformanceCriticalContextProvider contextProvider, ICSharpDeclaration element, IContextBoundSettingsStore settings, string text, string tooltip, DaemonProcessKind kind, IEnumerable <BulbMenuItem> items, bool onlyHot = false) { var isIconHot = element.HasHotIcon(contextProvider, settings, kind); if (onlyHot && !isIconHot) { return; } var highlighting = isIconHot ? new UnityHotGutterMarkInfo(items, element, tooltip) : (IHighlighting) new UnityGutterMarkInfo(items, element, tooltip); consumer.AddHighlighting(highlighting); }
public override void AddHighlighting(IHighlightingConsumer consumer, ICSharpDeclaration element, string tooltip) { switch (element) { case IFieldDeclaration _: AddHighlighting(consumer, myFieldUsageProvider, element, tooltip, "Set by Unity"); break; case IClassLikeDeclaration _: AddHighlighting(consumer, myCodeInsightProvider, element, tooltip, "Scripting component"); break; case IMethodDeclaration _: AddHighlighting(consumer, myCodeInsightProvider, element, tooltip, "Event function"); break; default: AddHighlighting(consumer, myCodeInsightProvider, element, tooltip, "Implicit usage"); break; } }
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); }
public void Elide(ICSharpDeclaration declarationOrClosure, ICSharpExpression awaitExpression) { var factory = CSharpElementFactory.GetInstance(awaitExpression); var lambdaExpression = declarationOrClosure as ILambdaExpression; if (lambdaExpression == null) { return; } lambdaExpression.SetAsync(false); if (lambdaExpression.BodyBlock != null) { var statement = factory.CreateStatement("return $0;", awaitExpression); awaitExpression.GetContainingStatement()?.ReplaceBy(statement); } else { lambdaExpression.SetBodyExpression(awaitExpression); } }
public void Elide(ICSharpDeclaration declarationOrClosure, ICSharpExpression awaitExpression) { var factory = CSharpElementFactory.GetInstance(awaitExpression); var methodDeclaration = declarationOrClosure as IMethodDeclaration; if (methodDeclaration == null) { return; } methodDeclaration.SetAsync(false); if (methodDeclaration.Body != null) { var statement = factory.CreateStatement("return $0;", awaitExpression); awaitExpression.GetContainingStatement()?.ReplaceBy(statement); } else { methodDeclaration.ArrowClause?.SetExpression(awaitExpression); } }
protected DeclarationBase(ICSharpDeclaration declaration) : base(declaration) { _declaration = declaration; }
public MemberNameApplicableTypeMemberFilter(ICSharpDeclaration ownerDeclaration) { myOwnerDeclaration = ownerDeclaration; }
/// <summary>Gets the qualified name of the class declaration.</summary> /// <param name="classDeclaration">The class declaration.</param> /// <returns>The <see cref="string"/>.</returns> private static string GetQualifiedClassDeclarationName(ICSharpDeclaration classDeclaration) { var ns = classDeclaration.GetContainingNamespaceDeclaration(); if (ns != null) { return ns.QualifiedName + "." + classDeclaration.DeclaredName; } return string.Empty; }
/// <summary> /// Creates new documentation for the ParameterDeclaration or TypeParameterDeclaration. /// </summary> /// <param name="declaration"> /// The declaration to create the docs for. /// </param> /// <returns> /// A string of the parameters docs. /// </returns> public static string CreateDocumentationForParameter(ICSharpDeclaration declaration) { if (declaration is IParameterDeclaration) { string result = "<param name=\"" + declaration.DeclaredName + "\">"; string parameterDescription = string.Empty; IContextBoundSettingsStore settingsStore = PsiSourceFileExtensions.GetSettingsStore(null, declaration.GetSolution()); if (settingsStore.GetValue((StyleCopOptionsSettingsKey key) => key.InsertTextIntoDocumentation)) { parameterDescription = string.Format("The {0}.", ConvertTextToSentence(declaration.DeclaredName).ToLowerInvariant()); } return result + parameterDescription + "</param>"; } if (declaration is ITypeParameterDeclaration) { return CreateDocumentationForTypeParameterDeclaration((ITypeParameterDeclaration)declaration); } return null; }
/// <summary> /// Creates new documentation for the ParameterDeclaration or TypeParameterDeclaration. /// </summary> /// <param name="declaration"> /// The declaration to create the docs for. /// </param> /// <returns> /// A string of the parameters docs. /// </returns> public static string CreateDocumentationForParameter(ICSharpDeclaration declaration) { if (declaration is IParameterDeclaration) { string result = "<param name=\"" + declaration.DeclaredName + "\">"; string parameterDescription = string.Empty; if (StyleCopOptions.Instance.InsertTextIntoDocumentation) { parameterDescription = string.Format("The {0}.", ConvertTextToSentence(declaration.DeclaredName).ToLowerInvariant()); } return result + parameterDescription + "</param>"; } if (declaration is ITypeParameterDeclaration) { return CreateDocumentationForTypeParameterDeclaration((ITypeParameterDeclaration)declaration); } return null; }