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); }