示例#1
0
        public BinaryUnityFileCache(Lifetime lifetime, ISolution solution,
                                    IPersistentIndexManager persistentIndexManager, IShellLocks locks,
                                    ChangeManager changeManager)
            : base(lifetime, persistentIndexManager, BinaryFileCacheItem.Marshaller)
        {
            myGroupingEvent = solution.Locks.GroupingEvents.CreateEvent(lifetime, "UnityRefresherOnSaveEvent",
                                                                        TimeSpan.FromMilliseconds(500), Rgc.Guarded, () =>
            {
                var changedFiles = new JetHashSet <IPsiSourceFile>(myChangedFiles);
                myChangedFiles.Clear();

                if (changedFiles.Count > 0)
                {
                    locks.ExecuteWithWriteLock(() => changeManager.ExecuteAfterChange(() =>
                    {
                        var builder = new PsiModuleChangeBuilder();
                        foreach (var file in changedFiles)
                        {
                            if (file.IsValid())
                            {
                                builder.AddFileChange(file, PsiModuleChange.ChangeType.Modified);
                            }
                        }

                        changeManager.OnProviderChanged(solution, builder.Result, SimpleTaskExecutor.Instance);
                    }));
                }
            });
            myChangedFiles = new JetHashSet <IPsiSourceFile>();
        }
        public UnityRefreshTracker(Lifetime lifetime, ISolution solution, UnityRefresher refresher,
                                   ILogger logger,
                                   IFileSystemTracker fileSystemTracker,
                                   UnityHost host,
                                   UnitySolutionTracker unitySolutionTracker)
        {
            myRefresher = refresher;
            myLogger    = logger;
            if (solution.GetData(ProjectModelExtensions.ProtocolSolutionKey) == null)
            {
                return;
            }

            unitySolutionTracker.IsUnityProjectFolder.AdviseOnce(lifetime, args =>
            {
                if (!args)
                {
                    return;
                }

                // Rgc.Guarded - beware RIDER-15577
                myGroupingEvent = solution.Locks.GroupingEvents.CreateEvent(lifetime, "UnityRefresherGroupingEvent",
                                                                            TimeSpan.FromMilliseconds(500),
                                                                            Rgc.Guarded, () =>
                {
                    refresher.Refresh(RefreshType.Normal);
                });

                host.PerformModelAction(rd => rd.Refresh.Advise(lifetime, force =>
                {
                    if (force)
                    {
                        refresher.Refresh(RefreshType.ForceRequestScriptReload);
                    }
                    else
                    {
                        myGroupingEvent.FireIncoming();
                    }
                }));
            });

            unitySolutionTracker.IsUnityProject.AdviseOnce(lifetime, args =>
            {
                if (!args)
                {
                    return;
                }

                var protocolSolution = solution.GetProtocolSolution();
                protocolSolution.Editors.AfterDocumentInEditorSaved.Advise(lifetime, _ =>
                {
                    logger.Verbose("protocolSolution.Editors.AfterDocumentInEditorSaved");
                    myGroupingEvent.FireIncoming();
                });

                fileSystemTracker.RegisterPrioritySink(lifetime, FileSystemChange, HandlingPriority.Other);
            });
        }
        public SaveAnimations(Lifetime lifetime, Agent agent, IThreading threading)
        {
            this.lifetime = lifetime;

            dte = Shell.Instance.GetComponent <DTE>();

            saveEvent = threading.CreateGroupingEvent(lifetime, "Clippy::Save", TimeSpan.FromSeconds(1), () => agent.Play("Save"));

            SubscribeEvents();
        }
            public DaemonData(Lifetime lifetime, IThreading threading, IDaemon daemon, IDocument document)
            {
                this.lastCalledTimestamp = DateTime.MinValue;

                this.groupingEvent = threading.GroupingEvents.CreateEvent(
                    lifetime,
                    "StyleCop::ReHighlight",
                    PauseDuration,
                    Rgc.Guarded,
                    () => ReadLockCookie.Execute(() => daemon.ForceReHighlight(document)));
            }
        private void InitControls()
        {
            using (new LayoutSuspender(this))
            {
                var tablePanel = new TableLayoutPanel
                {
                    AutoSizeMode = AutoSizeMode.GrowAndShrink,
                    Margin       = Padding.Empty,
                    Padding      = Padding.Empty,
                    Size         = ClientSize
                };
                tablePanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100f));
                tablePanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                tablePanel.RowStyles.Add(new RowStyle(SizeType.Percent, 50f));
                Controls.Add(tablePanel);

                GroupingEvent sizeEvent = Environment.Threading.GroupingEvents[Rgc.Invariant].CreateEvent(
                    _lifetime,
                    Pid + ".SizeChanged",
                    TimeSpan.FromMilliseconds(300.0), () =>
                {
                    var clientSize = new Size(ClientSize.Width - _margin, ClientSize.Height - _margin);
                    if (!clientSize.Equals(tablePanel.Size))
                    {
                        using (new LayoutSuspender(this))
                        {
                            tablePanel.Size = clientSize;
                        }
                    }
                });
                EventHandler handler = (sender, args) => sizeEvent.FireIncoming();
                _lifetime.AddBracket(() => SizeChanged += handler, () => SizeChanged -= handler);

                string titleCaption = "Specify external file and directory paths to include in the code inspection. " +
                                      "Relative paths are relative to the directory containing the project. " +
                                      "Exclusions specified in the Generated Code settings apply." +
                                      System.Environment.NewLine +
                                      "NOTE: Changes do not take affect until project is loaded." +
                                      System.Environment.NewLine;
                var titleLabel = new Controls.Label(titleCaption)
                {
                    AutoSize = true, Dock = DockStyle.Top
                };
                tablePanel.Controls.Add(titleLabel);

                string[] externalCodePaths = _settings.EnumIndexedValues(ExternalCodeSettingsAccessor.Paths).ToArray();
                _externalCodePathsCollectionEdit = new StringCollectionEdit(Environment, "External files and directories:", null, _mainWindow, _windowsHookManager, _formValidators)
                {
                    Dock = DockStyle.Fill
                };
                _externalCodePathsCollectionEdit.Items.Value = externalCodePaths;
                tablePanel.Controls.Add(_externalCodePathsCollectionEdit, 0, 1);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ReferencedAnalyzersCache"/> class.
        /// </summary>
        /// <param name="lifetime">The lifetime of the component</param>
        /// <param name="solution">The current solution</param>
        /// <param name="threading">The threading API</param>
        /// <param name="solutionLoadTasksScheduler">Solution load task scheduler</param>
        /// <param name="projectModelSynchronizer">The project model synchronizer</param>
        /// <param name="packageInstallerServices">NuGet installer services API</param>
        /// <param name="packageInstallerEvents">NuGet installer events API</param>
        public ReferencedAnalyzersCache(
            Lifetime lifetime,
            ISolution solution,
            IThreading threading,
            ISolutionLoadTasksScheduler solutionLoadTasksScheduler,
            ProjectModelSynchronizer projectModelSynchronizer,
            Lazy <Optional <IVsPackageInstallerServices> > packageInstallerServices,
            Lazy <Optional <IVsPackageInstallerEvents> > packageInstallerEvents)
        {
            this.solution  = solution;
            this.threading = threading;
            this.projectModelSynchronizer = projectModelSynchronizer;
            this.packageInstallerEvents   = packageInstallerEvents.Value.CanBeNull;
            this.packageInstallerServices = packageInstallerServices.Value.CanBeNull;

            this.syncObject = new object();

            this.referencedAnalyzers = new OneToSetMap <string, string>();

            this.groupingEvent = threading.GroupingEvents.CreateEvent(
                lifetime,
                "StyleCop::AnalyzersCache",
                TimeSpan.FromSeconds(2),
                Rgc.Guarded,
                this.DoResetAnalyzersCache);

            if (!this.IsNuGetAvailable)
            {
                Logger.LogMessage(
                    LoggingLevel.VERBOSE,
                    "[StyleCop::AnalyzersCache] Unable to get NuGet interfaces. No exception thrown");
            }
            else
            {
                lifetime.AddBracket(
                    () =>
                {
                    this.packageInstallerEvents.PackageInstalled   += this.ResetAnalyzersCache;
                    this.packageInstallerEvents.PackageUninstalled += this.ResetAnalyzersCache;
                },
                    () =>
                {
                    this.packageInstallerEvents.PackageInstalled   -= this.ResetAnalyzersCache;
                    this.packageInstallerEvents.PackageUninstalled -= this.ResetAnalyzersCache;
                });
                solutionLoadTasksScheduler.EnqueueTask(new SolutionLoadTask("StyleCop.ReferencedAnalyzersCache", SolutionLoadTaskKinds.AfterDone,
                                                                            () =>
                {
                    this.ResetAnalyzersCache(null);
                }));
            }
        }
        public PackageManager(Lifetime lifetime, ISolution solution, ILogger logger,
                              UnitySolutionTracker unitySolutionTracker,
                              UnityVersion unityVersion,
                              IFileSystemTracker fileSystemTracker)
        {
            myLifetime          = lifetime;
            mySolution          = solution;
            myLogger            = logger;
            myUnityVersion      = unityVersion;
            myFileSystemTracker = fileSystemTracker;

            // Refresh the packages in the guarded context, safe from reentrancy.
            myGroupingEvent = solution.Locks.GroupingEvents.CreateEvent(lifetime, "Unity::PackageManager",
                                                                        TimeSpan.FromMilliseconds(500), Rgc.Guarded, DoRefresh);

            myPackagesById     = new DictionaryEvents <string, PackageData>(lifetime, "Unity::PackageManager");
            myPackageLifetimes = new Dictionary <string, LifetimeDefinition>();

            myPackagesFolder   = mySolution.SolutionDirectory.Combine("Packages");
            myPackagesLockPath = myPackagesFolder.Combine("packages-lock.json");
            myManifestPath     = myPackagesFolder.Combine("manifest.json");

            unitySolutionTracker.IsUnityProject.AdviseUntil(lifetime, value =>
            {
                if (!value)
                {
                    return(false);
                }

                ScheduleRefresh();

                // Track changes to manifest.json and packages-lock.json. Also track changes in the Packages folder, but
                // only top level, not recursively. We only want to update the packages if a new package has been added
                // or removed
                var packagesFolder = mySolution.SolutionDirectory.Combine("Packages");
                fileSystemTracker.AdviseFileChanges(lifetime, packagesFolder.Combine("packages-lock.json"),
                                                    _ => ScheduleRefresh());
                fileSystemTracker.AdviseFileChanges(lifetime, packagesFolder.Combine("manifest.json"),
                                                    _ => ScheduleRefresh());
                fileSystemTracker.AdviseDirectoryChanges(lifetime, packagesFolder, false, _ => ScheduleRefresh());

                // We're all set up, terminate the advise
                return(true);
            });
        }
        public StringListViewModel(
            [NotNull] Lifetime lifetime,
            [NotNull] Property <string> source)
        {
            myLifetime     = lifetime;
            mySource       = source;
            myEntryChanged = new GroupingEventHost(lifetime, false).CreateEvent(lifetime,
                                                                                "StringListViewModel.EntryChangedGrouped",
                                                                                TimeSpan.FromMilliseconds(100),
                                                                                OnEntryChanged);

            var entries = mySource.Value.SplitByNewLine()
                          .Where(entry => !entry.IsEmpty())
                          .Select(entry => new StringListEntry(lifetime, myEntryChanged.Incoming, entry.Trim()))
                          .ToList();

            Entries       = new ListEvents <StringListEntry>(lifetime, "StringListViewModel.Entries", entries, false);
            SelectedEntry = new Property <StringListEntry>(lifetime, "StringListViewModel.SelectedEntry");
        }
        public DeferredCacheController(Lifetime lifetime, ISolution solution, SolutionCaches solutionCaches,
                                       ISolutionLoadTasksScheduler tasksScheduler, IPersistentIndexManager persistentIndexManager, IPsiFiles psiFiles,
                                       SolutionAnalysisConfiguration solutionAnalysisConfiguration, IShellLocks shellLocks,
                                       DeferredHelperCache deferredHelperCache, IEnumerable <IDeferredCache> deferredCaches,
                                       DeferredCacheProgressBar progressBar, ILogger logger)
        {
            myLifetime       = lifetime;
            mySolution       = solution;
            mySolutionCaches = solutionCaches;
            myPsiFiles       = psiFiles;
            mySolutionAnalysisConfiguration = solutionAnalysisConfiguration;
            myShellLocks          = shellLocks;
            myDeferredHelperCache = deferredHelperCache;
            myDeferredCaches      = deferredCaches;
            myProgressBar         = progressBar;
            myLogger = logger;
            var defaultValue = solutionCaches.PersistentProperties.TryGetValue("DeferredCachesCompletedOnce", out var result) && result.Equals("True");

            myCompletedOnce = new ViewableProperty <bool>(defaultValue);

            myGroupingEvent = solution.Locks.GroupingEvents.CreateEvent(lifetime, "DeferredCachesCoreActivity", TimeSpan.FromMilliseconds(500), Rgc.Guarded, RunBackgroundActivity);
        }
        public ChangedTypesProvider(
            Lifetime lifetime,
            IShellLocks shellLocks,
            ChangeManager changeManager,
            DocumentManager documentManager,
            IPsiServices services)
        {
            _myServices        = services;
            _myLifetime        = lifetime;
            _myShellLocks      = shellLocks;
            _myDocumentManager = documentManager;
            _myChangedRanges   = new ConcurrentDictionary <IProjectFile, TextRange>();

            changeManager.Changed2.Advise(lifetime, OnChange);
            _myDocumentChangedEvent = shellLocks.CreateGroupingEvent(
                lifetime,
                "ChangedTypesProvider::DocumentChanged",
                s_updateInterval,
                OnProcessChangesEx);

            TypesChanged = new Signal <IReadOnlyCollection <ITypeElement> >(lifetime, "ChangedTypesProvider");
            _myLifetime.AddDispose(TypesChanged);
        }
示例#11
0
            public DaemonData(Lifetime lifetime, IThreading threading, IDaemon daemon, IDocument document)
            {
                this.lastCalledTimestamp = DateTime.MinValue;

                this.groupingEvent = threading.GroupingEvents.CreateEvent(
                    lifetime,
                    "StyleCop::ReHighlight",
                    PauseDuration,
                    Rgc.Guarded,
                    () => ReadLockCookie.Execute(() => daemon.ForceReHighlight(document)));
            }
示例#12
0
        private void InitControls()
        {
            using (new LayoutSuspender(this))
            {
                TableLayoutPanel tablePanel = new TableLayoutPanel
                {
                    AutoSizeMode = AutoSizeMode.GrowAndShrink,
                    Margin       = Padding.Empty,
                    Padding      = Padding.Empty,
                    Size         = ClientSize
                };
                tablePanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100f));
                tablePanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                tablePanel.RowStyles.Add(new RowStyle(SizeType.Percent, 25f));
                tablePanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                tablePanel.RowStyles.Add(new RowStyle(SizeType.Percent, 25f));
                Controls.Add(tablePanel);

                GroupingEvent sizeEvent = Environment.Threading.GroupingEvents[Rgc.Invariant].CreateEvent(
                    m_lifetime,
                    PID + ".SizeChanged",
                    TimeSpan.FromMilliseconds(300.0), () =>
                {
                    Size clientSize = new Size(ClientSize.Width - MARGIN, ClientSize.Height - MARGIN);
                    if (!clientSize.Equals(tablePanel.Size))
                    {
                        using (new LayoutSuspender(this))
                        {
                            tablePanel.Size = clientSize;
                        }
                    }
                });
                EventHandler handler = (sender, args) => sizeEvent.FireIncoming();
                m_lifetime.AddBracket(() => SizeChanged += handler, () => SizeChanged -= handler);

                string titleCaption = "Specify Unity Classes" +
                                      System.Environment.NewLine;
                Controls.Label titleLabel = new Controls.Label(titleCaption)
                {
                    AutoSize = true, Dock = DockStyle.Top
                };
                tablePanel.Controls.Add(titleLabel);

                string[] unityClasses = m_settings.EnumIndexedValues(UnitySettingsAccessor.UnityClasses).ToArray();
                m_unityClassesCollectionEdit = new StringCollectionEdit(Environment,
                                                                        "Unity Classes:", null, m_mainWindow, m_windowsHookManager, m_formValidators)
                {
                    Dock = DockStyle.Fill
                };
                m_unityClassesCollectionEdit.Items.Value = unityClasses;
                tablePanel.Controls.Add(m_unityClassesCollectionEdit, 0, 1);

                string attributesTitleCaption = "Implicit Attributes" +
                                                System.Environment.NewLine;
                Controls.Label attributesTitleLabel = new Controls.Label(attributesTitleCaption)
                {
                    AutoSize = true, Dock = DockStyle.Top
                };
                tablePanel.Controls.Add(attributesTitleLabel, 0, 2);

                string[] unityAttributes = m_settings.EnumIndexedValues(UnitySettingsAccessor.UnityAttributes).ToArray();
                m_unityAttributesCollectionEdit = new StringCollectionEdit(Environment,
                                                                           "Unity Attributes:", null, m_mainWindow, m_windowsHookManager, m_formValidators)
                {
                    Dock = DockStyle.Fill
                };
                m_unityAttributesCollectionEdit.Items.Value = unityAttributes;
                tablePanel.Controls.Add(m_unityAttributesCollectionEdit, 0, 3);
            }
        }