protected void Dispose(bool disposing) { if (_isDisposed) { return; } _isDisposed = true; if (_projectWithHookedEvents != null) { _projectWithHookedEvents.ActiveInterpreterChanged -= Project_ConfigurationChanged; _projectWithHookedEvents._searchPaths.Changed -= Project_ConfigurationChanged; _projectWithHookedEvents = null; } if (disposing) { var thread = Interlocked.Exchange(ref _thread, null); if (thread != null) { thread.Dispose(); WriteError(Strings.ReplExited); } _analyzer?.Dispose(); } }
protected virtual void Dispose(bool disposing) { if (_isDisposed) { return; } _isDisposed = true; if (_projectWithHookedEvents != null) { _projectWithHookedEvents.ActiveInterpreterChanged -= Project_ConfigurationChanged; _projectWithHookedEvents._searchPaths.Changed -= Project_ConfigurationChanged; _projectWithHookedEvents = null; } if (_workspaceWithHookedEvents != null) { _workspaceWithHookedEvents.ActiveInterpreterChanged -= Workspace_ConfigurationChanged; _workspaceWithHookedEvents.SearchPathsSettingChanged -= Workspace_ConfigurationChanged; _workspaceWithHookedEvents = null; } if (disposing) { _analyzer?.Dispose(); } }
public void Dispose() { _site.MustBeCalledFromUIThread(); _deferredModulesChangeNotification.Dispose(); _deferredWorkspaceFileChangeNotification.Dispose(); _recreatingAnalyzer.Dispose(); _pythonWorkspace.ActiveInterpreterChanged -= OnActiveInterpreterChanged; _pythonWorkspace.SearchPathsSettingChanged -= OnSearchPathsChanged; if (_analyzer != null) { _analyzer.ClearAllTasks(); if (_analyzer.RemoveUser()) { _analyzer.AbnormalAnalysisExit -= OnAnalysisProcessExited; _analyzer.Dispose(); } _analyzer = null; } UnsubscribePackageManagers(); var watcher = _workspaceFileWatcher; _workspaceFileWatcher = null; watcher?.Dispose(); }
public override void Dispose() { if (_ownsAnalyzer && _replAnalyzer != null) { _replAnalyzer.Dispose(); _replAnalyzer = null; } base.Dispose(); }
protected override void Reload() { using (new DebugTimer("Project Load")) { _intermediateOutputPath = Path.Combine(ProjectHome, GetProjectProperty("BaseIntermediateOutputPath")); if (_analyzer != null && _analyzer.RemoveUser()) { _analyzer.Dispose(); } _analyzer = new VsProjectAnalyzer(ProjectFolder); _analyzer.MaxLogLength = NodejsPackage.Instance.IntellisenseOptionsPage.AnalysisLogMax; LogAnalysisLevel(); base.Reload(); SyncFileSystem(); NodejsPackage.Instance.CheckSurveyNews(false); ModulesNode.ReloadHierarchySafe(); // scan for files which were loaded from cached analysis but no longer // exist and remove them. _analyzer.ReloadComplete(); var ignoredPaths = GetProjectProperty(NodejsConstants.AnalysisIgnoredDirectories); if (!string.IsNullOrWhiteSpace(ignoredPaths)) { _analysisIgnoredDirs = ignoredPaths.Split(';').Select(x => '\\' + x + '\\').ToArray(); } else { _analysisIgnoredDirs = new string[0]; } var maxFileSizeProp = GetProjectProperty(NodejsConstants.AnalysisMaxFileSize); int maxFileSize; if (maxFileSizeProp != null && Int32.TryParse(maxFileSizeProp, out maxFileSize)) { _maxFileSize = maxFileSize; } } }
private void IntellisenseOptionsPageAnalysisLevelChanged(object sender, EventArgs e) { var analyzer = new VsProjectAnalyzer(IntellisenseOptionsPage.AnalysisLevel, IntellisenseOptionsPage.SaveToDisk); analyzer.SwitchAnalyzers(_analyzer); if (_analyzer.RemoveUser()) { _analyzer.Dispose(); } _analyzer = analyzer; LogLooseFileAnalysisLevel(); }
private void IntellisenseOptionsPageAnalysisLevelChanged(object sender, EventArgs e) { if (_analyzer != null) { var analyzer = CreateLooseVsProjectAnalyzer(); analyzer.SwitchAnalyzers(_analyzer); if (_analyzer.RemoveUser()) { _analyzer.Dispose(); } _analyzer = analyzer; LogLooseFileAnalysisLevel(); } TelemetryLogger.LogAnalysisLevelChanged(IntellisenseOptionsPage.AnalysisLevel); }
protected void Dispose(bool disposing) { if (_isDisposed) { return; } _isDisposed = true; if (disposing) { var thread = Interlocked.Exchange(ref _thread, null); if (thread != null) { thread.Dispose(); WriteError(Strings.ReplExited); } _analyzer?.Dispose(); } }
public void Dispose() { if (View != null) { View.Dispose(); } if (Analyzer != null && _disposeAnalyzer) { Analyzer.Dispose(); } if (Factory != null && _disposeFactory) { var disp = Factory as IDisposable; if (disp != null) { disp.Dispose(); } } if (VS != null && _disposeVS) { VS.Dispose(); } }
public PythonEditor( string content = null, PythonLanguageVersion version = PythonLanguageVersion.V27, MockVs vs = null, IPythonInterpreterFactory factory = null, VsProjectAnalyzer analyzer = null, string filename = null, bool?inProcAnalyzer = null ) { if (vs == null) { _disposeVS = true; vs = new MockVs(); } MockVsTextView view = null; try { AdvancedEditorOptions advancedOptions = null; vs.InvokeSync(() => { advancedOptions = vs.GetPyService().AdvancedOptions; advancedOptions.AutoListMembers = true; advancedOptions.AutoListIdentifiers = false; }); AdvancedOptions = advancedOptions; if (factory == null) { vs.InvokeSync(() => { factory = vs.ComponentModel.GetService <IInterpreterRegistryService>() .Interpreters .FirstOrDefault(c => c.GetLanguageVersion() == version && c.Configuration.Id.StartsWith("Global|PythonCore")); if (factory != null) { Console.WriteLine($"Using interpreter {factory.Configuration.InterpreterPath}"); } }); if (factory == null) { _disposeFactory = true; factory = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion()); Console.WriteLine("Using analysis-only interpreter"); } } if (analyzer == null) { _disposeAnalyzer = true; analyzer = vs.InvokeTask(() => VsProjectAnalyzer.CreateForTestsAsync(vs.ComponentModel.GetService <PythonEditorServices>(), factory, inProcAnalyzer ?? Debugger.IsAttached), 10000); } Uri uri; if (string.IsNullOrEmpty(filename)) { filename = Path.ChangeExtension(Path.GetRandomFileName(), ".py"); } if (Path.IsPathRooted(filename)) { uri = new Uri(filename); } else { var d = Path.GetRandomFileName(); uri = new Uri($"python://test/{d}/{filename}"); filename = $"_:\\PYTHON\\{d}\\{filename}"; } var cancel = CancellationTokens.After60s; view = vs.CreateTextView(PythonCoreConstants.ContentType, content ?? "", v => { v.TextView.TextBuffer.Properties[BufferParser.ParseImmediately] = true; v.TextView.TextBuffer.Properties[IntellisenseController.SuppressErrorLists] = IntellisenseController.SuppressErrorLists; v.TextView.TextBuffer.Properties[VsProjectAnalyzer._testAnalyzer] = analyzer; v.TextView.TextBuffer.Properties[VsProjectAnalyzer._testFilename] = filename; v.TextView.TextBuffer.Properties[VsProjectAnalyzer._testDocumentUri] = uri; }, filename); var services = vs.ComponentModel.GetService <PythonEditorServices>(); var bi = services.GetBufferInfo(view.TextView.TextBuffer); var entry = bi.GetAnalysisEntryAsync(cancel).WaitAndUnwrapExceptions(); Assert.IsNotNull(entry, "failed to get analysis entry"); if (!string.IsNullOrEmpty(content) && !cancel.IsCancellationRequested && !entry.IsAnalyzed) { var task = entry.Analyzer.WaitForNextCompleteAnalysis(); var bp = entry.TryGetBufferParser(); while (bp == null) { Thread.Sleep(50); cancel.ThrowIfCancellationRequested(); bp = entry.TryGetBufferParser(); } try { bp.EnsureCodeSyncedAsync(bi.Buffer, true).Wait(cancel); task.Wait(cancel); } catch (AggregateException ex) when(ex.InnerException != null) { throw ex.InnerException; } catch (OperationCanceledException) { } } if (cancel.IsCancellationRequested) { Assert.Fail("Timed out waiting for code analysis"); } vs.ThrowPendingException(); View = view; view = null; Analyzer = analyzer; analyzer = null; Factory = factory; factory = null; VS = vs; vs = null; } finally { if (view != null) { view.Dispose(); } if (analyzer != null && _disposeAnalyzer) { analyzer.Dispose(); } if (factory != null && _disposeFactory) { var disp = factory as IDisposable; if (disp != null) { disp.Dispose(); } } if (vs != null && _disposeVS) { vs.Dispose(); } } }
public PythonEditor( string content = null, PythonLanguageVersion version = PythonLanguageVersion.V27, MockVs vs = null, IPythonInterpreterFactory factory = null, VsProjectAnalyzer analyzer = null, string filename = null, bool?inProcAnalyzer = null ) { if (vs == null) { _disposeVS = true; vs = new MockVs(); } MockVsTextView view = null; try { AdvancedEditorOptions advancedOptions = null; vs.InvokeSync(() => { advancedOptions = vs.GetPyService().AdvancedOptions; advancedOptions.AutoListMembers = true; advancedOptions.AutoListIdentifiers = false; }); AdvancedOptions = advancedOptions; if (factory == null) { vs.InvokeSync(() => { factory = vs.ComponentModel.GetService <IInterpreterRegistryService>() .Interpreters .FirstOrDefault(c => c.GetLanguageVersion() == version && c.Configuration.Id.StartsWith("Global|PythonCore")); if (factory != null) { Console.WriteLine($"Using interpreter {factory.Configuration.InterpreterPath}"); } }); if (factory == null) { _disposeFactory = true; factory = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion()); Console.WriteLine("Using analysis-only interpreter"); } } if (analyzer == null) { _disposeAnalyzer = true; analyzer = vs.InvokeTask(() => VsProjectAnalyzer.CreateForTestsAsync(vs.ComponentModel.GetService <PythonEditorServices>(), factory, inProcAnalyzer ?? Debugger.IsAttached)); } if (string.IsNullOrEmpty(filename)) { do { filename = PathUtils.GetAbsoluteFilePath(TestData.GetTempPath(), Path.GetRandomFileName()) + ".py"; } while (File.Exists(filename)); } var cancel = CancellationTokens.After60s; using (var mre = new ManualResetEventSlim()) { view = vs.CreateTextView(PythonCoreConstants.ContentType, content ?? "", v => { v.TextView.TextBuffer.Properties[BufferParser.ParseImmediately] = true; v.TextView.TextBuffer.Properties[IntellisenseController.SuppressErrorLists] = IntellisenseController.SuppressErrorLists; v.TextView.TextBuffer.Properties[VsProjectAnalyzer._testAnalyzer] = analyzer; v.TextView.TextBuffer.Properties[VsProjectAnalyzer._testFilename] = filename; }, filename); var entry = analyzer.GetAnalysisEntryFromPath(filename); while (entry == null && !cancel.IsCancellationRequested) { Thread.Sleep(50); entry = analyzer.GetAnalysisEntryFromPath(filename); } if (!string.IsNullOrEmpty(content) && !cancel.IsCancellationRequested && !entry.IsAnalyzed) { EventHandler evt = (s, e) => mre.SetIfNotDisposed(); try { entry.AnalysisComplete += evt; while (!mre.Wait(50, cancel) && !vs.HasPendingException && !entry.IsAnalyzed) { if (!analyzer.IsAnalyzing && !entry.IsAnalyzed) { var bp = entry.TryGetBufferParser(); Assert.IsNotNull(bp, "No buffer parser was ever created"); var bi = PythonTextBufferInfo.TryGetForBuffer(view.TextView.TextBuffer); Assert.IsNotNull(bi, "No BufferInfo was ever created"); bi.LastSentSnapshot = null; bp.EnsureCodeSyncedAsync(view.TextView.TextBuffer).WaitAndUnwrapExceptions(); } } } catch (OperationCanceledException) { } finally { entry.AnalysisComplete -= evt; } } if (cancel.IsCancellationRequested) { Assert.Fail("Timed out waiting for code analysis"); } vs.ThrowPendingException(); } View = view; view = null; Analyzer = analyzer; analyzer = null; Factory = factory; factory = null; VS = vs; vs = null; } finally { if (view != null) { view.Dispose(); } if (analyzer != null && _disposeAnalyzer) { analyzer.Dispose(); } if (factory != null && _disposeFactory) { var disp = factory as IDisposable; if (disp != null) { disp.Dispose(); } } if (vs != null && _disposeVS) { vs.Dispose(); } } }
public void Dispose() { _vs.Dispose(); _analyzer.Dispose(); }