コード例 #1
0
            public ClassifierHelper(string code, PythonLanguageVersion version)
            {
                _view = new PythonEditor("", version);

                var providers = _view.VS.ComponentModel.GetExtensions <IClassifierProvider>().ToArray();

                _provider1 = providers.OfType <PythonClassifierProvider>().Single();
                _provider2 = providers.OfType <PythonAnalysisClassifierProvider>().Single();

                _classificationsReady1 = new ManualResetEventSlim();
                _classificationsReady2 = new ManualResetEventSlim();

                AstClassifier.ClassificationChanged += (s, e) => SafeSetEvent(_classificationsReady1);
                var startVersion = _view.CurrentSnapshot.Version;

                AnalysisClassifier.ClassificationChanged += (s, e) => {
                    var entry = (AnalysisEntry)_view.GetAnalysisEntry();
                    // make sure we have classifications from the version we analyzed after
                    // setting the text below.
                    if (entry.GetAnalysisVersion(_view.CurrentSnapshot.TextBuffer).VersionNumber > startVersion.VersionNumber)
                    {
                        SafeSetEvent(_classificationsReady2);
                    }
                };

                _view.Text = code;
            }
コード例 #2
0
            public ClassifierHelper(string code, PythonLanguageVersion version)
            {
                _view = new PythonEditor("", version);

                var providers = _view.VS.ComponentModel.GetExtensions <IClassifierProvider>().ToArray();

                _provider1 = providers.OfType <PythonClassifierProvider>().Single();
                _provider2 = providers.OfType <PythonAnalysisClassifierProvider>().Single();

                _classificationsReady1 = new ManualResetEventSlim();
                _classificationsReady2 = new ManualResetEventSlim();

                AstClassifier.ClassificationChanged += (s, e) => _classificationsReady1.SetIfNotDisposed();
                var startVersion = _view.CurrentSnapshot.Version;

                AnalysisClassifier.ClassificationChanged += (s, e) => {
                    try {
                        var bi = PythonTextBufferInfo.TryGetForBuffer(_view.View.TextView.TextBuffer);
                        if (bi?.LastAnalysisReceivedVersion == null)
                        {
                            return;
                        }
                        // make sure we have classifications from the version we analyzed after
                        // setting the text below.
                        if (bi.LastAnalysisReceivedVersion.VersionNumber > startVersion.VersionNumber)
                        {
                            _classificationsReady2.SetIfNotDisposed();
                        }
                    } catch (Exception ex) {
                        _excInfo = ExceptionDispatchInfo.Capture(ex);
                    }
                };

                _view.Text = code;
            }
コード例 #3
0
ファイル: ClassifierTests.cs プロジェクト: mkolovic/PTVS
            public ClassifierHelper(string code, PythonLanguageVersion version)
            {
                _view = new PythonEditor("", version);

                var providers = _view.VS.ComponentModel.GetExtensions <IClassifierProvider>().ToArray();

                _provider1 = providers.OfType <PythonClassifierProvider>().Single();
                _provider2 = providers.OfType <PythonAnalysisClassifierProvider>().Single();

                _classificationsReady1 = new ManualResetEventSlim();
                _classificationsReady2 = new ManualResetEventSlim();

                AstClassifier.ClassificationChanged      += (s, e) => _classificationsReady1.SetIfNotDisposed();
                AnalysisClassifier.ClassificationChanged += (s, e) => _classificationsReady2.SetIfNotDisposed();

                _view.Text = code;
            }
コード例 #4
0
ファイル: ClassifierTests.cs プロジェクト: gilbertw/PTVS
            public ClassifierHelper(string code, PythonLanguageVersion version)
            {
                _vs = new MockVs();

                var reg       = _vs.ContentTypeRegistry;
                var providers = _vs.ComponentModel.GetExtensions <IClassifierProvider>().ToArray();

                _provider1 = providers.OfType <PythonClassifierProvider>().Single();
                _provider2 = providers.OfType <PythonAnalysisClassifierProvider>().Single();

                var factory = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion());

                _analyzer = new VsProjectAnalyzer(_vs.ServiceProvider, factory, new[] { factory });

                _view = _vs.CreateTextView(PythonCoreConstants.ContentType, code, v => {
                    v.TextView.TextBuffer.Properties.AddProperty(typeof(VsProjectAnalyzer), _analyzer);
                });
            }
コード例 #5
0
            public ClassifierHelper(MockTextBuffer buffer, PythonLanguageVersion version)
            {
                var serviceProvider = PythonToolsTestUtilities.CreateMockServiceProvider();

                _contentRegistry        = new MockContentTypeRegistryService(PythonCoreConstants.ContentType);
                _classificationRegistry = new MockClassificationTypeRegistryService();
                _provider1 = new PythonClassifierProvider(_contentRegistry, serviceProvider)
                {
                    _classificationRegistry = _classificationRegistry
                };
                _provider2 = new PythonAnalysisClassifierProvider(_contentRegistry, serviceProvider)
                {
                    _classificationRegistry = _classificationRegistry
                };

                _buffer  = buffer;
                _factory = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion());

                var analyzer = new VsProjectAnalyzer(serviceProvider, _factory, new[] { _factory });

                _buffer.AddProperty(typeof(VsProjectAnalyzer), analyzer);

                _view = new MockTextView(_buffer);
            }