public UnityEventFunctionQuickDocPresenter(UnityEventFunction eventFunction, IClrDeclaredElement element, QuickDocTypeMemberProvider quickDocTypeMemberProvider, XmlDocHtmlPresenter xmlDocHtmlPresenter, HelpSystem helpSystem) : this(eventFunction, null, element, quickDocTypeMemberProvider, xmlDocHtmlPresenter, helpSystem) { myQuickDocTypeMemberProvider = quickDocTypeMemberProvider; }
private static void AddMethodSignatureInspections(IHighlightingConsumer consumer, IMethod method, UnityEventFunction function, EventFunctionMatch match) { if (match == EventFunctionMatch.NoMatch || match == EventFunctionMatch.ExactMatch) { return; } var methodSignature = function.AsMethodSignature(method.Module); foreach (var declaration in method.GetDeclarations()) { if (declaration is IMethodDeclaration methodDeclaration) { if ((match & EventFunctionMatch.MatchingStaticModifier) != EventFunctionMatch.MatchingStaticModifier) { consumer.AddHighlighting(new InvalidStaticModifierWarning(methodDeclaration, methodSignature)); } if ((match & EventFunctionMatch.MatchingReturnType) != EventFunctionMatch.MatchingReturnType) { consumer.AddHighlighting(new InvalidReturnTypeWarning(methodDeclaration, methodSignature)); } if ((match & EventFunctionMatch.MatchingSignature) != EventFunctionMatch.MatchingSignature) { consumer.AddHighlighting(new InvalidSignatureWarning(methodDeclaration, methodSignature)); } if ((match & EventFunctionMatch.MatchingTypeParameters) != EventFunctionMatch.MatchingTypeParameters) { consumer.AddHighlighting(new InvalidTypeParametersWarning(methodDeclaration, methodSignature)); } } } }
private void AddGutterMark(IHighlightingConsumer consumer, IMethod method, UnityEventFunction function) { foreach (var declaration in method.GetDeclarations()) { AddGutterMark(declaration, function, consumer); } }
public UnityEventFunctionBehavior(UnityEventFunctionTextualInfo info, UnityEventFunction eventFunction, AccessRights accessRights) : base(info) { myEventFunction = eventFunction; myAccessRights = accessRights; }
public UnityEventFunctionQuickDocPresenter(UnityEventFunction eventFunction, IClrDeclaredElement element, QuickDocTypeMemberProvider quickDocTypeMemberProvider, ITheming theming, HelpSystem helpSystem) : this(eventFunction, null, element, quickDocTypeMemberProvider, theming, helpSystem) { myQuickDocTypeMemberProvider = quickDocTypeMemberProvider; }
public UnityEventFunctionQuickDocPresenter(UnityEventFunction eventFunction, IClrDeclaredElement element, QuickDocTypeMemberProvider quickDocTypeMemberProvider, ITheming theming, HelpSystem helpSystem) : this(eventFunction, null, element, quickDocTypeMemberProvider, theming, helpSystem) { myQuickDocTypeMemberProvider = quickDocTypeMemberProvider; }
public UnityEventFunctionBehavior(IShellLocks shellLocks, DeclaredElementInfo info, UnityEventFunction eventFunction, AccessRights accessRights) : base(info) { myShellLocks = shellLocks; myEventFunction = eventFunction; myAccessRights = accessRights; }
private bool HasOptionalParameter(UnityEventFunction function) { foreach (var parameter in function.Parameters) { if (parameter.IsOptional) { return(true); } } return(false); }
public InvalidSignatureFix(InvalidSignatureWarning warning) { myEventFunction = warning.Function; myMethodDeclaration = warning.MethodDeclaration; var parameters = string.Join(", ", myEventFunction.Parameters.Select(p => string.Format("{0} {1}", CreateParameterType(p).GetPresentableName(myMethodDeclaration.Language), p.Name))); Text = $"Change parameters to '({parameters})'"; }
public UnityEventFunctionQuickDocPresenter(UnityEventFunction eventFunction, string parameterName, IClrDeclaredElement element, QuickDocTypeMemberProvider quickDocTypeMemberProvider, ITheming theming, HelpSystem helpSystem) { myEventFunction = eventFunction; myParameterName = parameterName; myQuickDocTypeMemberProvider = quickDocTypeMemberProvider; myTheming = theming; myHelpSystem = helpSystem; myEnvoy = new DeclaredElementEnvoy <IClrDeclaredElement>(element); }
public UnityEventFunctionQuickDocPresenter(UnityEventFunction eventFunction, string parameterName, IClrDeclaredElement element, QuickDocTypeMemberProvider quickDocTypeMemberProvider, ITheming theming, HelpSystem helpSystem) { myEventFunction = eventFunction; myParameterName = parameterName; myQuickDocTypeMemberProvider = quickDocTypeMemberProvider; myTheming = theming; myHelpSystem = helpSystem; myEnvoy = new DeclaredElementEnvoy<IClrDeclaredElement>(element); }
private bool HasAnyExactMatchInheritedMethods(IEnumerable <TypeMemberInstance <IMethod> > inheritedMethods, UnityEventFunction function) { foreach (var existingMethod in inheritedMethods) { if (function.Match(existingMethod.Member) == MethodSignatureMatch.ExactMatch) { return(true); } } return(false); }
// ReSharper disable once UnusedParameter.Local private ILookupItem SetLexicographicalSortPriority(ILookupItem item, UnityEventFunction function) { // When items are sorted lexicographically, first sort key is Location, then Rank, then OrderString. // NOTE: Don't use item.PlaceBottom(), because it resets item.Placement, resetting any relevance values // Don't do any sorting here. If the user really wants lexicographical sorting, they won't appreciate us // messing around with the sorting. // I'm willing to be convinced otherwise here. Let's see if anyone shouts (I don't know if anyone even uses // lexicographical sorting instead of the default relevance sorting). If we want to change things, push // everything to the top, with the undocumented items at the bottom of this group // item.Placement.Location = PlacementLocation.Top; // item.Placement.Rank = (byte) (function.Undocumented ? 1 : 0); return(item); }
public virtual void AddEventFunctionHighlighting(IHighlightingConsumer consumer, IMethod method, UnityEventFunction eventFunction, string text, DaemonProcessKind kind) { foreach (var declaration in method.GetDeclarations()) { if (declaration is ICSharpDeclaration cSharpDeclaration) { consumer.AddImplicitConfigurableHighlighting(cSharpDeclaration); consumer.AddHotHighlighting(Swa, CallGraphSwaExtensionProvider, cSharpDeclaration, Analyzer, Settings, text, GetEventFunctionTooltip(eventFunction), kind, GetEventFunctionActions(cSharpDeclaration)); } } }
public virtual void AddUnityImplicitHighlightingForEventFunction(IHighlightingConsumer consumer, IMethod method, UnityEventFunction eventFunction, DaemonProcessKind kind) { var message = GetMessageForUnityEventFunction(eventFunction); foreach (var declaration in method.GetDeclarations()) { if (declaration is ICSharpDeclaration cSharpDeclaration) { AddHighlightingWithConfigurableHighlighter(consumer, cSharpDeclaration, message, "Event function", kind); } } }
private bool HasAnyPartiallyMatchingExistingMethods(IEnumerable <IMethod> existingMethods, UnityEventFunction function) { // Don't use Any() - it's surprisingly expensive when called for each function we're adding to the lookup list foreach (var existingMethod in existingMethods) { if (function.Match(existingMethod) != MethodSignatureMatch.NoMatch) { return(true); } } return(false); }
public virtual void AddEventFunctionHighlighting(IHighlightingConsumer consumer, IMethod method, UnityEventFunction eventFunction, string text, IReadOnlyCallGraphContext context) { var tooltip = GetEventFunctionTooltip(eventFunction); foreach (var declaration in method.GetDeclarations()) { if (declaration is ICSharpDeclaration cSharpDeclaration) { consumer.AddImplicitConfigurableHighlighting(cSharpDeclaration); consumer.AddHotHighlighting(PerformanceContextProvider, cSharpDeclaration, SettingsStore.BoundSettingsStore, text, tooltip, context, GetEventFunctionActions(cSharpDeclaration, context)); } } }
protected virtual string GetEventFunctionTooltip(UnityEventFunction eventFunction) { var tooltip = "Unity event function"; if (!string.IsNullOrEmpty(eventFunction.Description)) { tooltip += Environment.NewLine + Environment.NewLine + eventFunction.Description; } if (eventFunction.CanBeCoroutine) { tooltip += Environment.NewLine + "This function can be a coroutine."; } return(tooltip); }
public virtual string GetMessageForUnityEventFunction(UnityEventFunction eventFunction) { var tooltip = "Unity event function"; if (!string.IsNullOrEmpty(eventFunction.Description)) { tooltip += Environment.NewLine + Environment.NewLine + eventFunction.Description; } if (eventFunction.Coroutine) { tooltip += Environment.NewLine + "This function can be a coroutine."; } return(tooltip); }
private void AddGutterMark(IDeclaration declaration, UnityEventFunction eventFunction, IHighlightingConsumer consumer) { var tooltip = "Unity event function"; if (!string.IsNullOrEmpty(eventFunction.Description)) { tooltip += Environment.NewLine + Environment.NewLine + eventFunction.Description; } if (eventFunction.Coroutine) { tooltip += Environment.NewLine + "This function can be a coroutine."; } var highlighting = new UnityGutterMarkInfo(declaration, tooltip); consumer.AddHighlighting(highlighting); }
private void AddMethodSignatureInspections(IHighlightingConsumer consumer, IMethod method, UnityEventFunction function, MethodSignatureMatch match) { if (match == MethodSignatureMatch.NoMatch || match == MethodSignatureMatch.ExactMatch) { return; } var methodSignature = function.AsMethodSignature(method.Module); foreach (var declaration in method.GetDeclarations()) { if (declaration is IMethodDeclaration methodDeclaration) { AddMethodSignatureInspections(consumer, methodDeclaration, methodSignature, match); } } }
private void AddGutterMark(IDeclaration declaration, UnityEventFunction eventFunction, IHighlightingConsumer consumer) { var documentRange = declaration.GetNameDocumentRange(); var tooltip = "Unity event function"; if (!string.IsNullOrEmpty(eventFunction.Description)) { tooltip += Environment.NewLine + Environment.NewLine + eventFunction.Description; } if (eventFunction.Coroutine) { tooltip += Environment.NewLine + "This function can be a coroutine."; } var highlighting = new UnityMarkOnGutter(Api, declaration, documentRange, tooltip); consumer.AddHighlighting(highlighting, documentRange); }
private static bool HasDifferentParameterLists( [NotNull] UnityEventFunction function, [NotNull] CSharpCodeCompletionContext context, [NotNull] KnownTypesCache knownTypesCache) { var unterminatedContext = context.UnterminatedContext; var methodDeclaration = unterminatedContext.TreeNode?.GetContainingNode <IMethodDeclaration>(); if (methodDeclaration == null) { return(false); } var functionParameters = function.Parameters; var currentMethodParameters = methodDeclaration.Params; if (currentMethodParameters == null) { return(false); } if (functionParameters.Length != currentMethodParameters.ParameterDeclarations.Count) { return(true); } var typeConversionRule = currentMethodParameters.GetTypeConversionRule(); var module = methodDeclaration.GetPsiModule(); for (var paramIndex = 0; paramIndex < functionParameters.Length; paramIndex++) { var functionParameter = functionParameters[paramIndex]; var currentMethodParameter = currentMethodParameters.ParameterDeclarations[paramIndex]; var conversion = typeConversionRule.ClassifyImplicitConversion(currentMethodParameter.Type, functionParameter.TypeSpec.AsIType(knownTypesCache, module)); if (conversion.Kind != ConversionKind.Identity) { return(true); } } return(false); }
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); } }
private ILookupItem SetRelevanceSortPriority(ILookupItem item, UnityEventFunction function) { // When items are sorted by relevance, highest value wins. It can be tricky to know if the item is going to // be positioned correctly, but essentially, the more flags you have, the higher up in the list you'll be. // Language specific flags have the most boost power, so the type of declared element helps a lot (methods // are higher than types, but not as high as local variables). Environmental flags will still boost the // relevance, but not by as much. So text matching will boost above other items of the same declared element // type, but won't boost a method name over a local variable name. The evaluation mode can also give a small // but significant boost - Light has higher relevance than Full. Many of these flags are set automatically // by looking at the declared element type, or evaluation mode, etc. But we can set some values explicitly, // which can give a meaningful boost and get our items to the top of the list // Secondary sort order is OrderString, which is usually display text, but can be overridden. // Generated items get a boost over normal declared element items item.Placement.Relevance |= (long)CLRLookupItemRelevance.GenerateItems; // Set high selection priority to push us further up, unless it's undocumented, in which case, give it a // smaller selection boost item = !function.Undocumented ? item.WithHighSelectionPriority() : item.WithLowSelectionPriority(); return(item); }
private static void AddMethodSignatureInspections(IHighlightingConsumer consumer, IMethod method, UnityEventFunction function, EventFunctionMatch match) { if ((match & EventFunctionMatch.MatchingStaticModifier) != EventFunctionMatch.MatchingStaticModifier) { foreach (var declaration in method.GetDeclarations()) { var methodDeclaration = declaration as IMethodDeclaration; if (methodDeclaration != null) { consumer.AddHighlighting(new InvalidStaticModifierWarning(methodDeclaration, function)); } } } if ((match & EventFunctionMatch.MatchingReturnType) != EventFunctionMatch.MatchingReturnType) { foreach (var declaration in method.GetDeclarations()) { var methodDeclaration = declaration as IMethodDeclaration; if (methodDeclaration != null) { consumer.AddHighlighting(new InvalidReturnTypeWarning(methodDeclaration, function)); } } } if ((match & EventFunctionMatch.MatchingSignature) != EventFunctionMatch.MatchingSignature) { foreach (var declaration in method.GetDeclarations()) { var methodDeclaration = declaration as IMethodDeclaration; if (methodDeclaration != null) { consumer.AddHighlighting(new InvalidSignatureWarning(methodDeclaration, function)); } } } }
private ILookupItem CreateMethodItem(CSharpCodeCompletionContext context, UnityEventFunction eventFunction, IClassLikeDeclaration declaration, bool hasReturnType, AccessRights accessRights, MemberGenerationContext generationContext) { if (CSharpLanguage.Instance == null) { return(null); } // Only show the modifier in the list text if it's not already specified and there isn't a return type, in // which case we default to `private`. E.g. if someone types `OnAnim`, then show `private void OnAnimate...` // but if they type `void OnAnim`, they don't want a modifier, and if they type `public void OnAnim` then // they want to use `public` var showModifier = false; if (!hasReturnType && accessRights == AccessRights.NONE) { showModifier = true; accessRights = AccessRights.PRIVATE; } // Note that we can't keep this declaration - it will become invalid as the user types to narrow down the // search and modifies the PSI file. This only affects ReSharper, Rider has different code completion // mechanism var factory = CSharpElementFactory.GetInstance(declaration, false); var methodDeclaration = eventFunction.CreateDeclaration(factory, declaration, accessRights); if (methodDeclaration.DeclaredElement == null) { return(null); } // This is effectively the same as GenerateMemberPresentation, but without the overhead that comes // with the flexibility of formatting any time of declared element. We just hard code the format var predefinedType = context.PsiModule.GetPredefinedType(); var parameters = string.Empty; if (eventFunction.Parameters.Length > 0) { var sb = new StringBuilder(); for (var i = 0; i < eventFunction.Parameters.Length; i++) { if (i > 0) { sb.Append(", "); } var parameter = eventFunction.Parameters[i]; var type = predefinedType.TryGetType(parameter.ClrTypeName, NullableAnnotation.Unknown); var typeName = type?.GetPresentableName(CSharpLanguage.Instance) ?? parameter.ClrTypeName.ShortName; sb.AppendFormat("{0}{1}{2}", parameter.IsByRef ? "out" : string.Empty, typeName, parameter.IsArray ? "[]" : string.Empty); } parameters = sb.ToString(); } var text = $"{eventFunction.Name}({parameters})"; var parameterOffset = eventFunction.Name.Length; var modifier = showModifier ? CSharpDeclaredElementPresenter.Instance.Format(accessRights) + " " : string.Empty; var psiIconManager = context.BasicContext.LookupItemsOwner.Services.PsiIconManager; // Note that because this is a text based lookup item, then it won't be included if the normal C# method // filter is applied. We can't make it a method based lookup item because the DeclaredElement isn't valid in // this situation - it's not a real method, and a DeclaredElementInfo would try to store a pointer to it, // and be unable to recreate it when it's needed. var textualInfo = new UnityEventFunctionTextualInfo(generationContext.MemberReplaceRanges, text, text) { Ranges = context.CompletionRanges }; var lookupItem = LookupItemFactory.CreateLookupItem(textualInfo) .WithPresentation(item => { var displayName = new RichText($"{modifier}{text} {{ ... }}"); // GenerateMemberPresentation marks everything as bold, and the parameters + block syntax as not important var parameterStartOffset = modifier.Length + parameterOffset; LookupUtil.MarkAsNotImportant(displayName, TextRange.FromLength(parameterStartOffset, displayName.Length - parameterStartOffset)); LookupUtil.AddEmphasize(displayName, new TextRange(modifier.Length, displayName.Length)); var image = psiIconManager.GetImage(CLRDeclaredElementType.METHOD); psiIconManager.AttachExtensions(image, GetAccessExtensions(accessRights)); var marker = item.Info.Ranges.CreateVisualReplaceRangeMarker(); return(new SimplePresentation(displayName, image, marker)); }) .WithBehavior(_ => new UnityEventFunctionBehavior(textualInfo, eventFunction, accessRights)) .WithMatcher(_ => new ShiftedDeclaredElementMatcher(eventFunction.Name, modifier.Length, textualInfo)); var description = GetDescription(context, methodDeclaration); return(new WrappedLookupItem(lookupItem, description)); }
public override string GetMessageForUnityEventFunction(UnityEventFunction eventFunction) { return(eventFunction.Description ?? "Unity event function"); }
public UnityEventFunctionBehavior(DeclaredElementInfo info, UnityEventFunction eventFunction) : base(info) { myEventFunction = eventFunction; }
public InvalidSignatureWarning(IMethodDeclaration methodDeclaration, UnityEventFunction function) { MethodDeclaration = methodDeclaration; Function = function; }
public override void AddEventFunctionHighlighting(IHighlightingConsumer consumer, IMethod method, UnityEventFunction eventFunction, string text, DaemonProcessKind kind) { var iconId = method.HasHotIcon(ContextProvider, SettingsStore.BoundSettingsStore, kind) ? InsightUnityIcons.InsightHot.Id : InsightUnityIcons.InsightUnity.Id; if (RiderIconProviderUtil.IsCodeVisionEnabled(SettingsStore.BoundSettingsStore, myCodeInsightProvider.ProviderId, () => { base.AddEventFunctionHighlighting(consumer, method, eventFunction, text, kind); }, out var useFallback)) { foreach (var declaration in method.GetDeclarations()) { if (declaration is ICSharpDeclaration cSharpDeclaration) { if (!useFallback) { consumer.AddImplicitConfigurableHighlighting(cSharpDeclaration); } myCodeInsightProvider.AddHighlighting(consumer, cSharpDeclaration, method, text, eventFunction.Description ?? string.Empty, text, myIconHost.Transform(iconId), GetEventFunctionActions(cSharpDeclaration), RiderIconProviderUtil.GetExtraActions(mySolutionTracker, myBackendUnityHost)); } } } }
private static ILookupItem CreateMethodItem(CSharpCodeCompletionContext context, UnityEventFunction eventFunction, IClassLikeDeclaration declaration) { if (CSharpLanguage.Instance == null) { return(null); } var method = eventFunction.CreateDeclaration(CSharpElementFactory.GetInstance(declaration), declaration); if (method.DeclaredElement == null) { return(null); } var instance = new DeclaredElementInstance(method.DeclaredElement); var declaredElementInfo = new DeclaredElementInfo(method.DeclaredName, instance, CSharpLanguage.Instance, context.BasicContext.LookupItemsOwner, context) { Ranges = context.CompletionRanges }; var withMatcher = LookupItemFactory.CreateLookupItem(declaredElementInfo). WithPresentation(_ => new GenerateMemberPresentation(declaredElementInfo, PresenterStyles.DefaultPresenterStyle)). WithBehavior(_ => new UnityEventFunctionBehavior(declaredElementInfo, eventFunction)). WithMatcher(_ => new DeclaredElementMatcher(declaredElementInfo, context.BasicContext.IdentifierMatchingStyle)); return(withMatcher); }