private static IReadOnlyCollection <IIssue> RunInspections(ISolution solution, ICollection <IPsiSourceFile> sourceFiles)
        {
            var issues = new List <IIssue>();

#if RESHARPER92 || RESHARPER100
            Assert.IsTrue(
                CollectInspectionResults.Do(
                    solution,
                    sourceFiles,
                    SimpleTaskExecutor.Instance,
                    x =>
            {
                lock (issues)
                    issues.Add(x);
            }));
#else
            using (var lifetime = Lifetimes.Define(solution.GetLifetime()))
            {
                var collectInspectionResults = new CollectInspectionResults(solution, lifetime, A.Dummy <IProgressIndicator>());

                collectInspectionResults.RunLocalInspections(new Stack <IPsiSourceFile>(sourceFiles),
                                                             issuePointers => issues.AddRange(issuePointers));
            }
#endif

            return(issues);
        }
Beispiel #2
0
        public void Execute(IDataContext context, DelegateExecute nextExecute)
        {
            ISolution   solution = context.GetData(ProjectModelDataConstants.SOLUTION);
            IShellLocks locks    = context.GetComponent <IShellLocks>();
            PopupWindowContextSource popupWindowContextSource = context.GetData(UIDataConstants.PopupWindowContextSource);

            Debug.Assert(popupWindowContextSource != null, "popupWindowContextSource != null");
            Debug.Assert(solution != null, "solution != null");

            void Atomic(LifetimeDefinition lifetimeDefinition, Lifetime lifetime)
            {
                var controller = new GotoGeneratorController(
                    lifetime,
                    solution,
                    locks,
                    context,
                    Shell.Instance.GetComponent <IMainWindowPopupWindowContext>(),
                    false /* enableMulticore */
                    );

                GotoByNameMenu menu = new GotoByNameMenu(
                    context.GetComponent <GotoByNameMenuComponent>(),
                    lifetimeDefinition,
                    controller.Model,
                    context.GetComponent <UIApplication>().MainWindow.TryGetActiveWindow(),
                    solution.GetComponent <GotoByNameModelManager>().GetSearchTextData(context, controller),
                    popupWindowContextSource.Create(lifetime)
                    );

                MakeBusyIconVisibleOnEmptyFilter(menu, controller.Model, lifetime);
            }

            Lifetimes.Define(solution.GetLifetime(), null /* id */, Atomic);
        }
Beispiel #3
0
        private static IReadOnlyCollection <IIssue> RunInspections(ISolution solution, IEnumerable <IPsiSourceFile> sourceFiles)
        {
            var issues = new List <IIssue>();

#if RS20183
            using (var lifetime = JetBrains.DataFlow.Lifetimes.Define(solution.GetLifetime()))
#else
            using (var lifetime = Lifetime.Define(solution.GetLifetime()))
#endif
                using (var nullProgressIndicator = NullProgressIndicator.Create())
                {
                    var collectInspectionResults = new CollectInspectionResults(solution, lifetime, nullProgressIndicator);

                    collectInspectionResults.RunLocalInspections(
                        new Stack <IPsiSourceFile>(sourceFiles),
                        issuePointers => issues.AddRange(issuePointers));
                }

            return(issues);
        }
        protected override Action <ITextControl> ExecutePsiTransaction(
            [NotNull] ISolution solution,
            [NotNull] IProgressIndicator progress)
        {
            // Fetch settings
            var lifetime      = solution.GetLifetime();
            var settings      = solution.GetSettingsStore().SettingsStore.BindToContextLive(lifetime, ContextRange.Smart(solution.ToDataContext()));
            var stylerOptions = StylerOptionsFactory.FromSettings(
                settings,
                solution,
                _dataProvider.Project,
                _actionAppliesTo == ActionAppliesTo.File
                    ? _dataProvider.SourceFile as IPsiSourceFileWithLocation // Traverse config chain from file path
                    : null                                                   // Traverse config chain from project path
                );

            // Bail out early if needed
            if (stylerOptions.SuppressProcessing)
            {
                return(null);
            }

            // Perform styling
            var styler = new StylerService(stylerOptions, new XamlLanguageOptions
            {
                IsFormatable = true
            });

            var psiSourceFiles =
                _actionAppliesTo == ActionAppliesTo.File ? _dataProvider.Document.GetPsiSourceFiles(solution).AsIReadOnlyList()
                    : _actionAppliesTo == ActionAppliesTo.Project ? _dataProvider.Project.GetAllProjectFiles(it => it.LanguageType.Is <XamlProjectFileType>()).SelectMany(file => file.ToSourceFiles().AsIReadOnlyList())
                        : _dataProvider.Solution.GetAllProjects().SelectMany(project => project.GetAllProjectFiles(it => it.LanguageType.Is <XamlProjectFileType>()).SelectMany(file => file.ToSourceFiles().AsIReadOnlyList()));

            foreach (var prjItem in psiSourceFiles)
            {
                foreach (var file in prjItem.GetPsiFiles <XamlLanguage>())
                {
                    var sourceFile = file.GetSourceFile();
                    if (sourceFile?.Document != null)
                    {
                        var oldText = sourceFile.Document.GetText();
                        var newText = styler.StyleDocument(oldText).Replace("\r\n", "\n");
                        file.ReParse(new TreeTextRange(new TreeOffset(0), new TreeOffset(oldText.Length)), newText);
                    }
                }
            }

            return(null);
        }
Beispiel #5
0
        /// <summary>
        /// Performs the QuickFix, inserts the configured modifier into the location specified by the violation.
        /// </summary>
        /// <param name="solution">
        /// Current Solution.
        /// </param>
        /// <param name="textControl">
        /// Current Text Control to modify.
        /// </param>
        public void Execute(ISolution solution, ITextControl textControl)
        {
            LifetimeDefinition definition = Lifetime.Define(solution.GetLifetime());
            Lifetime           lifetime   = definition.Lifetime;

            try
            {
                unsafe
                {
                    ChangeInspectionSeverityDialog dialog = new ChangeInspectionSeverityDialog(lifetime);
                    IContextBoundSettingsStore     contextBoundSettingsStore =
                        this.settingsStore.BindToContextTransient(ContextRange.Smart(textControl.Document.ToDataContext()));
                    ConfigurableSeverityItem item = this.highlightingSettingsManager.GetSeverityItem(this.HighlightID);

                    dialog.Severity = this.highlightingSettingsManager.GetConfigurableSeverity(
                        this.HighlightID,
                        sourceFile: null,
                        storeBoundToSourceFile: contextBoundSettingsStore);
                    dialog.SeverityOptionsTitle = string.Format(item.FullTitle + ":");
                    dialog.CanBeError           = !item.SolutionAnalysisRequired;

                    if (dialog.ShowDialog() == true)
                    {
                        IContextBoundSettingsStore store = contextBoundSettingsStore;
                        if (dialog.SelectedSettingsLayer != null)
                        {
                            store = dialog.SelectedSettingsLayer.Model.SettingsStoreContext;
                        }

                        store.SetIndexedValue(HighlightingSettingsAccessor.InspectionSeverities, this.HighlightID, dialog.Severity);
                    }
                }
            }
            finally
            {
                definition.Terminate();
            }
        }
        /// <summary>
        /// Arranges the BulbItems in the correct section.
        /// </summary>
        /// <param name="menu">
        /// The BulbMenu to add the items too. 
        /// </param>
        ////public void CreateBulbItems(BulbMenu menu)
        ////{
        ////    menu.ArrangeContextActions(this.Items);
        ////}

        /// <summary>
        /// Performs the QuickFix, inserts the configured modifier into the location specified by the violation.
        /// </summary>
        /// <param name="solution">
        /// Current Solution. 
        /// </param>
        /// <param name="textControl">
        /// Current Text Control to modify. 
        /// </param>
        public void Execute(ISolution solution, ITextControl textControl)
        {
            JetBrains.DataFlow.LifetimeDefinition definition = JetBrains.DataFlow.Lifetimes.Define(solution.GetLifetime());
            JetBrains.DataFlow.Lifetime lifetime = definition.Lifetime;
            try
            {
                unsafe
                {
                    ChangeInspectionSeverityDialog dialog = new ChangeInspectionSeverityDialog(lifetime, this.commonIconsComponent);
                    IContextBoundSettingsStore contextBoundSettingsStore =
                        this.settingsStore.BindToContextTransient(ContextRange.Smart(textControl.Document.ToDataContext()));
                    HighlightingSettingsManager.ConfigurableSeverityItem item = this.highlightingSettingsManager.GetSeverityItem(this.HighlightID);

                    dialog.Severity = this.highlightingSettingsManager.GetConfigurableSeverity(this.HighlightID, contextBoundSettingsStore);
                    dialog.SeverityOptionsTitle = string.Format(item.FullTitle + ":");
                    dialog.CanBeError = !item.SolutionAnalysisRequired;

                    if (dialog.ShowDialog(User32Dll.GetForegroundWindow()) == true)
                    {
                        IContextBoundSettingsStore store = contextBoundSettingsStore;
                        if (dialog.SelectedSettingsLayer != null)
                        {
                            store = dialog.SelectedSettingsLayer.Model.SettingsStoreContext;
                        }

                        store.SetIndexedValue(HighlightingSettingsAccessor.InspectionSeverities, this.HighlightID, dialog.Severity);
                    }
                }
            }
            finally
            {
                definition.Terminate();
            }
        }
Beispiel #7
0
        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);
                    });
                });
            }
        }
        protected override Action<ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            var unitTestSessionManager = solution.GetComponent<IUnitTestSessionManager>();

              var element = solution.GetComponent<MethodRunnerProvider>().CreateElement(myClassDeclaration.GetSourceFile().GetProject(), new ClrTypeName(myClassDeclaration.CLRName), myMethodDeclaration.DeclaredName, myClassDeclaration.IsStatic, myMethodDeclaration.IsStatic);

              var unitTestElementManager = solution.GetComponent<IUnitTestElementManager>();
              unitTestElementManager.AddElement(element);

              var sessionView = unitTestSessionManager.GetSession(SessionID) ?? unitTestSessionManager.CreateSession(id: SessionID);
              sessionView.Title.Value = "Run Method " + myMethodDeclaration.DeclaredName;
              sessionView.Session.AddElement(element);

              var launchLifetime = Lifetimes.Define(solution.GetLifetime(), "MethodRunner");
              launchLifetime.Lifetime.AddAction(() =>
              {
            unitTestElementManager.RemoveElements(new[] {element});
            unitTestSessionManager.CloseSession(sessionView);
              });

              var unitTestResultManager = solution.GetComponent<IUnitTestResultManager>();

              EventHandler<UnitTestResultEventArgs> onUnitTestResultUpdated = (sender, args) =>
              {
            if (args.Element == element && args.Result.RunStatus == UnitTestRunStatus.Completed)
            {
              var exceptions = string.Empty;
              var resultData = unitTestResultManager.GetResultData(args.Element);
              if (resultData.Exceptions.Any())
            exceptions = resultData.Exceptions.First().StackTrace;
              MessageBox.ShowInfo(args.Result.Message + " " + resultData.Output + " " + exceptions);

              // cleanup
              launchLifetime.Terminate();
            }
              };

              unitTestResultManager.UnitTestResultUpdated += onUnitTestResultUpdated;
              launchLifetime.Lifetime.AddAction(() => unitTestResultManager.UnitTestResultUpdated -= onUnitTestResultUpdated);

              sessionView.Run(new UnitTestElements(new[] {element}), solution.GetComponent<ProcessHostProvider>());

              Assembly.LoadFile(typeof(RunMethodTask).Assembly.Location);

              return null;
        }