private void SetupWorkspace(IPythonWorkspaceContext workspace) { if (workspace == null) { return; } TestFrameworkType testFrameworkType = GetTestFramework(workspace); if (testFrameworkType != TestFrameworkType.None) { var projInfo = new ProjectInfo(workspace); _projectMap[projInfo.ProjectHome] = projInfo; var oldWatcher = _testFilesUpdateWatcher; _testFilesUpdateWatcher = new TestFilesUpdateWatcher(); _testFilesUpdateWatcher.FileChangedEvent += OnWorkspaceFileChanged; _testFilesUpdateWatcher.AddDirectoryWatch(workspace.Location); oldWatcher?.Dispose(); Regex testFileFilterRegex = new Regex(@".*\.(py|txt)", RegexOptions.Compiled | RegexOptions.IgnoreCase); Predicate <string> testFileFilter = (x) => testFileFilterRegex.IsMatch(x); foreach (var file in _workspaceContextProvider.Workspace.EnumerateUserFiles(testFileFilter)) { projInfo.AddTestContainer(this, file); } workspace.ActiveInterpreterChanged -= OnActiveInterpreterChanged; workspace.ActiveInterpreterChanged += OnActiveInterpreterChanged; _packageManagerEventSink.WatchPackageManagers(workspace.CurrentFactory); } }
private void SetupWorkspace(IPythonWorkspaceContext workspace) { if (workspace == null || GetTestFramework(workspace) == TestFrameworkType.None) { return; } try { Predicate <string> testFileFilter = (x) => PythonConstants.TestFileExtensionRegex.IsMatch(PathUtils.GetFileOrDirectoryName(x)); var projInfo = new ProjectInfo(workspace); foreach (var file in _workspaceContextProvider.Workspace.EnumerateUserFiles(testFileFilter)) { projInfo.AddTestContainer(this, file); } _projectMap[projInfo.ProjectHome] = projInfo; } catch (Exception ex) when(!ex.IsCriticalException()) { Trace.WriteLine("Exception : " + ex.Message); } // Register listeners var oldWatcher = _testFilesUpdateWatcher; _testFilesUpdateWatcher = new TestFilesUpdateWatcher(); _testFilesUpdateWatcher.FileChangedEvent += OnWorkspaceFileChanged; _testFilesUpdateWatcher.AddDirectoryWatch(workspace.Location); oldWatcher?.Dispose(); workspace.ActiveInterpreterChanged -= OnActiveInterpreterChanged; workspace.ActiveInterpreterChanged += OnActiveInterpreterChanged; _packageManagerEventSink.WatchPackageManagers(workspace.CurrentFactory); }
public void UpdateSolutionTestContainersAndFileWatchers(IEnumerable <string> sources, ProjectInfo projInfo, bool isAdd) { foreach (var path in sources) { if (isAdd) { projInfo.AddTestContainer(this, path); _testFilesUpdateWatcher.AddWatch(path); } else { projInfo.RemoveTestContainer(path); _testFilesUpdateWatcher.RemoveWatch(path); } } }
public void UpdateContainersAndListeners(IEnumerable <string> sources, ProjectInfo projInfo, bool isAdd) { if (projInfo == null) { return; } foreach (var path in sources) { if (isAdd) { projInfo.AddTestContainer(this, path); _testFilesUpdateWatcher.AddWatch(path); } else { projInfo.RemoveTestContainer(path); _testFilesUpdateWatcher.RemoveWatch(path); } } }