private ProjectInfo FindProjectInfo(string file, IVsProject vsProject = null) { if (vsProject == null) { // bschnurr todo: this is only looking at opened files var rdt = (IVsRunningDocumentTable)_serviceProvider.GetService(typeof(SVsRunningDocumentTable)); vsProject = VsProjectExtensions.PathToProject(file, rdt); } if (vsProject != null) { string projectHome = vsProject.GetProjectHome(); if (projectHome != null && _projectMap.TryGetValue(projectHome, out ProjectInfo foundProjectInfo)) { return(foundProjectInfo); } } //Renamed old files are no longer in the project so linear search var projectInfo = _projectMap.Values.FirstOrDefault(p => p.TryGetContainer(file, out _)); return(projectInfo); }
private void OnProjectItemChanged(object sender, TestFileChangedEventArgs e) { if (String.IsNullOrEmpty(e.File)) { return; } if (IsSettingsFile(e.File)) { switch (e.ChangedReason) { case TestFileChangedReason.None: break; case TestFileChangedReason.Renamed: // TestFileAddRemoveListener rename triggers Added and Removed break; case TestFileChangedReason.Added: _testFilesUpdateWatcher.AddWatch(e.File); break; case TestFileChangedReason.Changed: _testFilesUpdateWatcher.AddWatch(e.File); break; case TestFileChangedReason.Removed: _testFilesUpdateWatcher.RemoveWatch(e.File); break; } _isRefresh = true; NotifyContainerChanged(); return; } if (!IsTestFile(e.File)) { return; } // bschnurr todo: this is only looking at opened files IVsProject vsProject = e.Project; if (vsProject == null) { var rdt = (IVsRunningDocumentTable)_serviceProvider.GetService(typeof(SVsRunningDocumentTable)); vsProject = VsProjectExtensions.PathToProject(e.File, rdt); } if (vsProject == null) { return; } string projectHome = vsProject.GetProjectHome(); if (projectHome != null && _projectMap.TryGetValue(projectHome, out ProjectInfo projectInfo)) { var sources = new List <string>() { e.File }; switch (e.ChangedReason) { case TestFileChangedReason.Added: UpdateSolutionTestContainersAndFileWatchers(sources, projectInfo, isAdd: true); break; case TestFileChangedReason.Changed: //Need to increment version number so Test Explorer notices a change UpdateSolutionTestContainersAndFileWatchers(sources, projectInfo, isAdd: true); break; case TestFileChangedReason.Removed: UpdateSolutionTestContainersAndFileWatchers(sources, projectInfo, isAdd: false); break; default: //In changed case file watcher observed a file changed event //In this case we just have to fire TestContainerChnaged event //TestFileAddRemoveListener rename event triggers Added and Removed so Rename isn't needed break; } NotifyContainerChanged(); } }