/// <summary>
        /// Parses the specified text buffer.  Continues to monitor the parsed buffer and updates
        /// the parse tree asynchronously as the buffer changes.
        /// </summary>
        /// <param name="buffer"></param>
        public BufferParser EnqueueBuffer(IProjectEntry projEntry, ITextView textView, ITextBuffer buffer)
        {
            // only attach one parser to each buffer, we can get multiple enqueue's
            // for example if a document is already open when loading a project.
            BufferParser bufferParser;

            if (!buffer.Properties.TryGetProperty <BufferParser>(typeof(BufferParser), out bufferParser))
            {
                Dispatcher dispatcher = null;
                var        uiElement  = textView as UIElement;
                if (uiElement != null)
                {
                    dispatcher = uiElement.Dispatcher;
                }
                bufferParser = new BufferParser(this, dispatcher, projEntry, _parser, buffer);

                var curSnapshot = buffer.CurrentSnapshot;
                var severity    = _parser.PyService.GeneralOptions.IndentationInconsistencySeverity;
                bufferParser.EnqueingEntry();
                EnqueWorker(() => {
                    _parser.ParseBuffers(bufferParser, severity, curSnapshot);
                });
            }
            else
            {
                bufferParser.AttachedViews++;
            }

            return(bufferParser);
        }
        internal void ReparseWorker(object unused)
        {
            ITextSnapshot[] snapshots;
            lock (this) {
                if (_parsing)
                {
                    NotReparsing();
                    Interlocked.Decrement(ref _queue._analysisPending);
                    return;
                }

                _parsing = true;
                var buffers = Buffers;
                snapshots = new ITextSnapshot[buffers.Length];
                for (int i = 0; i < buffers.Length; i++)
                {
                    snapshots[i] = buffers[i].CurrentSnapshot;
                }
            }

            _parser.ParseBuffers(this, IndentationInconsistencySeverity, snapshots);
            Interlocked.Decrement(ref _queue._analysisPending);

            lock (this) {
                _parsing = false;
                if (_requeue)
                {
                    RequeueWorker();
                }
                _requeue = false;
            }
        }