Exemplo n.º 1
0
        private IEnumerable <BulbMenuItem> GetRunMethodItems(ISolution solution, UnityRunMarkerHighlighting runMarker)
        {
            var backendUnityHost   = solution.GetComponent <BackendUnityHost>();
            var notificationsModel = solution.GetComponent <NotificationsModel>();

            var methodFqn = DeclaredElementPresenter.Format(runMarker.Method.PresentationLanguage,
                                                            DeclaredElementPresenter.QUALIFIED_NAME_PRESENTER, runMarker.Method).Text;

            var iconId = RunMarkersThemedIcons.RunThis.Id;

            yield return(new BulbMenuItem(new ExecutableItem(() =>
            {
                var model = backendUnityHost.BackendUnityModel.Value;
                if (model == null)
                {
                    var notification = new NotificationModel("No connection to Unity", "Make sure Unity is running.",
                                                             true, RdNotificationEntryType.WARN, new List <NotificationHyperlink>());
                    notificationsModel.Notification(notification);
                    return;
                }

                var data = new RunMethodData(
                    runMarker.Project.GetOutputFilePath(runMarker.TargetFrameworkId).NameWithoutExtension,
                    runMarker.Method.GetContainingType().GetClrName().FullName,
                    runMarker.Method.ShortName);
                model.RunMethodInUnity.Start(data);
            }),
                                          new RichText($"Run '{methodFqn}'"),
                                          iconId,
                                          BulbMenuAnchors.PermanentBackgroundItems));
        }
        public void CollectRunMarkers(IFile file, IContextBoundSettingsStore settings, IHighlightingConsumer consumer)
        {
            if (!file.GetSolution().GetComponent <UnitySolutionTracker>().IsUnityProjectFolder.HasTrueValue())
            {
                return;
            }
            if (!(file is ICSharpFile csharpFile))
            {
                return;
            }

            foreach (var declaration in CachedDeclarationsCollector.Run <IMethodDeclaration>(csharpFile))
            {
                if (!(declaration.DeclaredElement is IMethod method))
                {
                    continue;
                }

                if (UnityRunMarkerUtil.IsSuitableStaticMethod(method))
                {
                    var range        = declaration.GetNameDocumentRange();
                    var highlighting = new UnityRunMarkerHighlighting(
                        declaration, UnityRunMarkerAttributeIds.RUN_METHOD_MARKER_ID, range,
                        file.GetPsiModule().TargetFrameworkId);
                    consumer.AddHighlighting(highlighting, range);
                }
            }
        }