public override string ToString() { using (ReadLockCookie.Create()) { using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) { var de = DeclaredElementPointer.FindDeclaredElement(); if (de == null) { return("INVALID"); } if (IsRelatedToScriptableObject()) { var value = InspectorVariableUsage.Value.GetFullPresentation(GetSolution(), DeclaredElementPointer.FindDeclaredElement(), true); return($"{de.ShortName} = {value}"); } else { var value = InspectorVariableUsage.Value.GetPresentation(GetSolution(), DeclaredElementPointer.FindDeclaredElement(), true); return($"{de.ShortName} = {value}"); } } } }
public override RdUsageGroup CreateModel(IOccurrence occurrence, IOccurrenceBrowserDescriptor descriptor) { using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) { if (occurrence is UnityAssetOccurrence assetOccurrence && !assetOccurrence.SourceFile.GetLocation().IsAsset()) { using (ReadLockCookie.Create()) { var solution = occurrence.GetSolution(); var processor = solution.GetComponent <AssetHierarchyProcessor>(); var consumer = new UnityScenePathGameObjectConsumer(); processor.ProcessSceneHierarchyFromComponentToRoot(assetOccurrence.OwningElementLocation, consumer, true, true); string name = "..."; if (consumer.NameParts.Count > 0) { name = string.Join("\\", consumer.NameParts); } return(CreateModel(name)); } } } return(EmptyModel()); }
public override RdUsageGroup CreateModel(IOccurrence occurrence, IOccurrenceBrowserDescriptor descriptor) { using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) { if (occurrence is ReferenceOccurrence referenceOccurrence && referenceOccurrence.PrimaryReference is IUnityYamlReference reference) { var document = reference.ComponentDocument; var sourceFile = document.GetSourceFile(); if (sourceFile == null || !sourceFile.IsValid()) { return(EmptyModel()); } var anchor = UnitySceneDataUtil.GetAnchorFromBuffer(document.GetTextAsBuffer()); if (anchor == null) { return(EmptyModel()); } return(CreateModel(UnityObjectPsiUtil.GetGameObjectPathFromComponent(myUnitySceneDataLocalCache, sourceFile, anchor))); } } return(EmptyModel()); }
public ITypeElement GetTypeElement([NotNull] IPsiModule module) { using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) { var type = TypeFactory.CreateTypeByCLRName(myTypeName, module); return(type.GetTypeElement()); } }
private IEnumerable <UnityType> GetBaseUnityTypes(UnityTypes types, ITypeElement type, Version normalisedVersion) { return(types.Types.Where(t => { using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) return t.SupportsVersion(normalisedVersion) && type.IsDescendantOf(t.GetTypeElement(type.Module)); })); }
public ITypeElement GetTypeElement(KnownTypesCache knownTypesCache, [NotNull] IPsiModule module) { using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) { var type = knownTypesCache.GetByClrTypeName(myTypeName, module); return(type.GetTypeElement()); } }
private static ITypeElement GetTypeElement(IClrTypeName typeName, KnownTypesCache knownTypesCache, IPsiModule module) { using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) { var type = knownTypesCache.GetByClrTypeName(typeName, module); return(type.GetTypeElement()); } }
public override string ToString() { using (ReadLockCookie.Create()) { using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) { var value = InspectorVariableUsage.Value.GetPresentation(GetSolution(), DeclaredElementPointer.FindDeclaredElement(), true); return($"{InspectorVariableUsage.Name} = {value}"); } } }
private void OnChanged(IReadOnlyCollection <ITypeElement> changedTypes) { using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) { var linkedTypes = changedTypes.SelectMany(LinkedTypesUtil.GetLinkedTypes).ToList(); var relevantTests = linkedTypes.Select(x => _unitTestElementStuff.GetElement(x)).WhereNotNull(); foreach (var relevantTest in relevantTests) { _unitTestResultManager.MarkOutdated(relevantTest); } } }
public override RdUsageGroup CreateModel(IOccurrence occurrence, IOccurrenceBrowserDescriptor descriptor) { using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) { if (occurrence is ReferenceOccurrence referenceOccurrence && referenceOccurrence.PrimaryReference is IUnityYamlReference reference) { return(CreateModel(UnityObjectPsiUtil.GetComponentName(reference.ComponentDocument))); } } return(EmptyModel()); }
// NOTE: This method assumes that the type is not a descendant of UnityEngine.Object! private bool IsSerializableType([CanBeNull] ITypeElement type, [NotNull] IProject project, bool isTypeUsage, bool hasSerializeReference = false) { if (!(type is IStruct || type is IClass)) { return(false); } if (isTypeUsage) { // Type usage (e.g. field declaration) is stricter. Means it must be a concrete type with no type // parameters, unless the type usage is for [SerializeReference], which allows abstract types if (type is IModifiersOwner modifiersOwner && modifiersOwner.IsAbstract && !hasSerializeReference) { return(false); } // Unity 2020.1 allows fields to have generic types. It's currently undocumented, but there are no // limitations on the number of type parameters, or even nested type parameters. The base type needs to // be serializable, but type parameters don't (if a non-serializable type parameter is used as a field, // it just isn't serialised). // https://blogs.unity3d.com/2020/03/17/unity-2020-1-beta-is-now-available-for-feedback/ var unityVersion = myUnityVersion.GetActualVersion(project); if (unityVersion < new Version(2020, 1) && type is ITypeParametersOwner typeParametersOwner && typeParametersOwner.TypeParameters.Count > 0) { return(false); } } if (type is IClass @class && @class.IsStaticClass()) { return(false); } // System.Dictionary is special cased and excluded. We can see this in UnitySerializationLogic.cs in the // reference source repo. It also excludes anything with a full name beginning "System.", which includes // "System.Version" (which is marked [Serializable]). However, it doesn't exclude string, int, etc. // TODO: Rewrite this whole section to properly mimic UnitySerializationLogic.cs var name = type.GetClrName(); if (Equals(name, KnownTypes.SystemVersion) || Equals(name, PredefinedType.GENERIC_DICTIONARY_FQN)) { return(false); } using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) return(type.HasAttributeInstance(PredefinedType.SERIALIZABLE_ATTRIBUTE_CLASS, true)); }
public override string ToString() { using (ReadLockCookie.Create()) { using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) { var declaredElement = DeclaredElementPointer.FindDeclaredElement(); if (declaredElement == null) { return("Invalid"); } return(DeclaredElementMenuItemFormatter.FormatText(declaredElement, declaredElement.PresentationLanguage, out _).Text); } } }
public override RdUsageGroup CreateModel(IOccurrence occurrence, IOccurrenceBrowserDescriptor descriptor) { using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) { if (occurrence is UnityAssetOccurrence assetOccurrence) { var hierarchyContainer = assetOccurrence.GetSolution()?.GetComponent <AssetDocumentHierarchyElementContainer>(); var element = hierarchyContainer?.GetHierarchyElement(assetOccurrence.OwningElementLocation, true); if (element is IComponentHierarchy componentHierarchyElement) { return(CreateModel(AssetUtils.GetComponentName(myMetaFileGuidCache, componentHierarchyElement))); } } } return(EmptyModel()); }
public override string ToString() { var pointer = DeclaredElementPointer; if (pointer is null) { return("Invalid"); } using (ReadLockCookie.Create()) { using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) { var element = pointer.FindDeclaredElement(); if (element == null) { return("Invalid"); } var language = element.PresentationLanguage; return(DeclaredElementMenuItemFormatter.FormatText(element, language, out _)?.Text ?? "Invalid"); } } }
public override IEnumerable <BulbMenuItem> GetBulbMenuItems(IHighlighter highlighter) { var solution = Shell.Instance.GetComponent <SolutionsManager>().Solution; if (solution == null) { return(EmptyList <BulbMenuItem> .InstanceList); } var unityImplicitUsageHighlightingContributor = solution.GetComponent <UnityHighlightingContributor>(); var daemon = solution.GetComponent <IDaemon>(); if (daemon.GetHighlighting(highlighter) is UnityGutterMarkInfo highlighting) { using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) return(unityImplicitUsageHighlightingContributor.CreateBulbItemsForUnityDeclaration(highlighting .Declaration)); } return(EmptyList <BulbMenuItem> .InstanceList); }
public override IEnumerable <BulbMenuItem> GetBulbMenuItems(IHighlighter highlighter) { var solution = Shell.Instance.GetComponent <SolutionsManager>().Solution; if (solution == null) { return(EmptyList <BulbMenuItem> .InstanceList); } var textControlManager = solution.GetComponent <ITextControlManager>(); var textControl = textControlManager.FocusedTextControl.Value; var daemon = solution.GetComponent <IDaemon>(); if (daemon.GetHighlighting(highlighter) is NukeMarkOnGutter highlighting) { using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) return(highlighting.GetBulbMenuItems(solution, textControl, (InvisibleAnchor)Anchor.NotNull())); } return(EmptyList <BulbMenuItem> .InstanceList); }
public override void OnClick(CodeInsightsHighlighting highlighting, ISolution solution) { if (highlighting is UnityInspectorCodeInsightsHighlighting unityInspectorCodeInsightsHighlighting) { Shell.Instance.GetComponent <JetPopupMenus>().Show(solution.GetLifetime(), JetPopupMenu.ShowWhen.NoItemsBannerIfNoItems, (lifetime, menu) => { var presentationType = unityInspectorCodeInsightsHighlighting.UnityPresentationType; var initValue = unityInspectorCodeInsightsHighlighting.ConstantValue; var declaredElement = (highlighting.DeclaredElement as IClrDeclaredElement).NotNull("declaredElement != null"); if (!declaredElement.IsValid()) { return; } var result = GetAssetGuidAndPropertyName(solution, declaredElement); if (!result.HasValue) { return; } var valuesCache = solution.GetComponent <UnitySceneDataLocalCache>(); var values = valuesCache.GetPropertyValues(result.Value.guid, result.Value.propertyName); menu.Caption.Value = WindowlessControlAutomation.Create("Inspector values"); menu.KeyboardAcceleration.Value = KeyboardAccelerationFlags.QuickSearch; var valuesToShow = values.Where(t => !IsSameWithInitializer(t.Value, presentationType, initValue)).Take(POP_UP_MAX_COUNT); foreach (var valueWithLocation in valuesToShow) { var value = valueWithLocation.Value; if (ShouldShowUnknownPresentation(presentationType)) { menu.ItemKeys.Add(valueWithLocation); } else { menu.ItemKeys.Add(valueWithLocation); } } menu.DescribeItem.Advise(lifetime, e => { var value = (e.Key as MonoBehaviourPropertyValueWithLocation).NotNull("value != null"); string shortPresentation; if (ShouldShowUnknownPresentation(presentationType)) { shortPresentation = "..."; } else { if (!declaredElement.IsValid()) { return; } using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet()) { var type = declaredElement.Type(); shortPresentation = GetPresentation(value, presentationType, type, solution, declaredElement.Module, true); } } e.Descriptor.Text = shortPresentation; OccurrencePresentationUtil.AppendRelatedFile(e.Descriptor, value.File.DisplayName.Replace("\\", "/")); e.Descriptor.Icon = UnityFileTypeThemedIcons.FileUnity.Id; e.Descriptor.Style = MenuItemStyle.Enabled; }); menu.ItemClicked.Advise(lifetime, key => { if (!myConnectionTracker.IsConnectionEstablished()) { ShowNotification(); return; } var value = (key as MonoBehaviourPropertyValueWithLocation).NotNull("value != null"); UnityEditorFindUsageResultCreator.CreateRequestAndShow(myUnityHost, solution.SolutionDirectory, myUnitySceneDataLocalCache, value.Value.MonoBehaviour, value.File); }); }); } }