public void Analyze()
            {
                var analyzer = Analyzer;

                var wasMonitoring = MonitorTextBuffer;

                MonitorTextBuffer = true;
                var classifier = AnalysisClassifier;

                using (var evt = new ManualResetEventSlim()) {
                    classifier.ClassificationChanged += (o, e) => evt.Set();
                    var ensureClassifier = AnalysisClassifierSpans.ToArray();
                    _buffer.GetPythonProjectEntry().Analyze(CancellationToken.None, true);
                    analyzer.WaitForCompleteAnalysis(_ => true);
                    while (_buffer.GetPythonProjectEntry().Analysis == null)
                    {
                        Thread.Sleep(500);
                    }
                    Assert.IsTrue(evt.Wait(10000));
                    MonitorTextBuffer = wasMonitoring;
                }
            }
Exemple #2
0
        private static async Task <IEnumerable <TrackingTagSpan <ErrorTag> > > AnalyzeTextBufferAsync(
            MockTextBuffer buffer,
            PythonLanguageVersion version = PythonLanguageVersion.V27
            )
        {
            var fact = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion());

            try {
                var serviceProvider = PythonToolsTestUtilities.CreateMockServiceProvider();
                var errorProvider   = serviceProvider.ComponentModel.GetService <IErrorProviderFactory>();
                Assert.IsNotNull(errorProvider, "Error provider factory is not available");
                var analyzer = new VsProjectAnalyzer(serviceProvider, fact, new[] { fact });
                buffer.AddProperty(typeof(VsProjectAnalyzer), analyzer);
                var classifierProvider = new PythonClassifierProvider(new MockContentTypeRegistryService(PythonCoreConstants.ContentType), serviceProvider);
                classifierProvider._classificationRegistry = new MockClassificationTypeRegistryService();
                classifierProvider.GetClassifier(buffer);
                var squiggles       = errorProvider.GetErrorTagger(buffer);
                var textView        = new MockTextView(buffer);
                var monitoredBuffer = analyzer.MonitorTextBuffer(textView, buffer);

                var tcs = new TaskCompletionSource <object>();
                buffer.GetPythonProjectEntry().OnNewAnalysis += (s, e) => tcs.SetResult(null);
                await tcs.Task;

                var snapshot = buffer.CurrentSnapshot;

                // Ensure all tasks have been updated
                var taskProvider = (ErrorTaskProvider)serviceProvider.GetService(typeof(ErrorTaskProvider));
                var time         = await taskProvider.FlushAsync();

                Console.WriteLine("TaskProvider.FlushAsync took {0}ms", time.TotalMilliseconds);

                var spans = squiggles.GetTaggedSpans(new SnapshotSpan(snapshot, 0, snapshot.Length));

                analyzer.StopMonitoringTextBuffer(monitoredBuffer.BufferParser, textView);

                return(spans);
            } finally {
            }
        }