Beispiel #1
0
        private void OnNewAnalysis(object sender, EventArgs e)
        {
            if (_provider._serviceProvider.GetPythonToolsService().AdvancedOptions.ColorNames == false)
            {
                lock (_spanCacheLock) {
                    if (_spanCache != null)
                    {
                        _spanCache = null;
                        OnNewClassifications(_buffer.CurrentSnapshot);
                    }
                }
                return;
            }

            PythonAst       tree;
            IAnalysisCookie cookie;

            _entry.GetTreeAndCookie(out tree, out cookie);
            var sCookie  = cookie as SnapshotCookie;
            var snapshot = sCookie != null ? sCookie.Snapshot : null;

            if (tree == null || snapshot == null)
            {
                return;
            }


            var moduleAnalysis = (_provider._serviceProvider.GetPythonToolsService().AdvancedOptions.ColorNamesWithAnalysis)
                ? _entry.Analysis
                : null;

            var walker = new ClassifierWalker(tree, moduleAnalysis, snapshot, Provider.CategoryMap);

            tree.Walk(walker);
            var newCache = walker.Spans;

            lock (_spanCacheLock) {
                if (snapshot == snapshot.TextBuffer.CurrentSnapshot)
                {
                    // Ensure we have not raced with another update
                    _spanCache = newCache;
                }
                else
                {
                    snapshot = null;
                }
            }
            if (snapshot != null)
            {
                OnNewClassifications(snapshot);
            }
        }
Beispiel #2
0
        private void OnNewAnalysis(object sender, EventArgs e)
        {
            var entry = sender as IPythonProjectEntry;

            if (entry == null || entry != _entry || !entry.IsAnalyzed)
            {
                Debug.Fail("Project entry does not match expectation");
                return;
            }

            var pyService = _provider._serviceProvider.GetPythonToolsService();
            var options   = pyService != null ? pyService.AdvancedOptions : null;

            if (options == null || options.ColorNames == false)
            {
                lock (_spanCacheLock) {
                    if (_spanCache != null)
                    {
                        _spanCache = null;
                        OnNewClassifications(_buffer.CurrentSnapshot);
                    }
                }
                return;
            }

            PythonAst       tree;
            IAnalysisCookie cookie;

            entry.GetTreeAndCookie(out tree, out cookie);
            var sCookie  = cookie as SnapshotCookie;
            var snapshot = sCookie != null ? sCookie.Snapshot : null;

            if (tree == null || snapshot == null)
            {
                return;
            }


            var moduleAnalysis = options.ColorNamesWithAnalysis ? entry.Analysis : null;

            var walker = new ClassifierWalker(tree, moduleAnalysis, snapshot, Provider.CategoryMap);

            tree.Walk(walker);
            var newCache = walker.Spans;

            lock (_spanCacheLock) {
                if (snapshot == snapshot.TextBuffer.CurrentSnapshot)
                {
                    // Ensure we have not raced with another update
                    _spanCache = newCache;
                }
                else
                {
                    snapshot = null;
                }
            }
            if (snapshot != null)
            {
                OnNewClassifications(snapshot);
            }
        }