Example #1
0
 public override ImmutableArray <DiagnosticAnalyzer> GetAnalyzers(string language)
 {
     FileWatcherService.WatchDirectories(_visualStudioAnalyzer, new [] { _visualStudioAnalyzer.FullPath.ParentDirectory }).Ignore();
     return(_underlying.GetAnalyzers(language));
 }
Example #2
0
 public Assembly LoadFromPath(string fullPath)
 {
     FileWatcherService.WatchDirectories(_analyzer, new [] { _analyzer.FullPath.ParentDirectory }).Ignore();
     return(_analyzer._loader.LoadFromPath(fullPath));
 }
 public void Dispose()
 {
     FileService.FileChanged -= OnUpdatedOnDisk;
     FileWatcherService.WatchDirectories(this, null);
 }
            void WatchDirectories()
            {
                var directories = watchedFiles.Count == 0 ? null : watchedFiles.Select(file => new FilePath(file).ParentDirectory);

                FileWatcherService.WatchDirectories(this, directories);
            }
        public async Task ReferenceCacheSnapshotUpdates()
        {
            string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln");

            var tempPath = Path.GetFullPath(Path.GetTempFileName());
            var oldAsm   = typeof(MonoDevelopMetadataReferenceManagerTests).Assembly.Location;

            File.Copy(oldAsm, tempPath, true);

            try {
                using (var sol = (MonoDevelop.Projects.Solution) await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile))
                    using (var ws = await TypeSystemServiceTestExtensions.LoadSolution(sol)) {
                        await FileWatcherService.Add(sol);

                        var manager = ws.MetadataReferenceManager;
                        var item    = manager.GetOrCreateMetadataReference(tempPath, MetadataReferenceProperties.Assembly);
                        Assert.IsNotNull(item);

                        await FileWatcherService.Update();

                        var initialId = item.CurrentSnapshot.GetMetadataId();

                        var taskForNewAsm = WaitForSnapshotChange(item);

                        // Replace the assembly with another one.
                        var newAsm = typeof(MonoDevelopMetadataReference).Assembly.Location;
                        File.Copy(newAsm, tempPath, true);

                        var argsForNewAsm = await taskForNewAsm;

                        Assert.AreSame(item.CurrentSnapshot, argsForNewAsm.OldSnapshot);

                        Assert.AreNotSame(argsForNewAsm.OldSnapshot, argsForNewAsm.NewSnapshot.Value);
                        // item.CurrentSnapshot is now updated
                        Assert.AreNotEqual(initialId, item.CurrentSnapshot.GetMetadataId());

                        var taskForOldAsm = WaitForSnapshotChange(item);
                        File.Copy(newAsm, tempPath, true);

                        var argsForOldAsm = await taskForOldAsm;

                        Assert.AreSame(item.CurrentSnapshot, argsForOldAsm.OldSnapshot);

                        Assert.AreNotSame(argsForNewAsm.OldSnapshot, argsForNewAsm.NewSnapshot.Value);
                        // Even though the old assembly was put back, it has a new id this time.
                        Assert.AreNotEqual(initialId, item.CurrentSnapshot.GetMetadataId());
                    }

                await FileWatcherService.Update();

                // At this point, the metadata reference should be disposed.
                // Check to see if file updates will trigger a file service noification
                var tcsShouldTimeout = new TaskCompletionSource <bool> ();
                var ctsFail          = new CancellationTokenSource();
                ctsFail.Token.Register(() => tcsShouldTimeout.TrySetResult(true));
                Core.FileService.FileChanged += (sender, args) => {
                    foreach (var file in args)
                    {
                        if (file.FileName == tempPath)
                        {
                            tcsShouldTimeout.TrySetResult(false);
                        }
                    }
                };

                ctsFail.CancelAfter(1000 * 5);
                File.WriteAllText(tempPath, "");
                Assert.AreEqual(true, await tcsShouldTimeout.Task);
            } finally {
                File.Delete(tempPath);
            }
        }