// Internal for testing
        internal void OnDocumentStructureChanged(object state)
        {
            _dispatcher.AssertForegroundThread();

            if (_disposed)
            {
                return;
            }

            var args = (DocumentStructureChangedEventArgs)state;

            if (_latestChangeReference == null || // extra hardening
                !_latestChangeReference.IsAssociatedWith(args) ||
                args.Snapshot != TextBuffer.CurrentSnapshot)
            {
                // In the middle of parsing a newer change or about to parse a newer change.
                return;
            }

            _latestChangeReference = null;
            _codeDocument          = args.CodeDocument;
            _snapshot      = args.Snapshot;
            _partialParser = new RazorSyntaxTreePartialParser(CodeDocument.GetSyntaxTree());

            DocumentStructureChanged?.Invoke(this, args);
        }
        // Internal for testing
        internal void OnDocumentStructureChanged(object state)
        {
            _dispatcher.AssertForegroundThread();

            if (_disposed)
            {
                return;
            }

            var backgroundParserArgs = (BackgroundParserResultsReadyEventArgs)state;

            if (_latestChangeReference == null || // extra hardening
                _latestChangeReference != backgroundParserArgs.ChangeReference ||
                backgroundParserArgs.ChangeReference.Snapshot != TextBuffer.CurrentSnapshot)
            {
                // In the middle of parsing a newer change or about to parse a newer change.
                return;
            }

            _latestChangeReference = null;
            _codeDocument          = backgroundParserArgs.CodeDocument;
            _snapshot      = backgroundParserArgs.ChangeReference.Snapshot;
            _partialParser = new RazorSyntaxTreePartialParser(CodeDocument.GetSyntaxTree());

            var documentStructureChangedArgs = new DocumentStructureChangedEventArgs(
                backgroundParserArgs.ChangeReference.Change,
                backgroundParserArgs.ChangeReference.Snapshot,
                backgroundParserArgs.CodeDocument);

            DocumentStructureChanged?.Invoke(this, documentStructureChangedArgs);
        }
        public ChangeReference QueueChange(SourceChange change, ITextSnapshot snapshot)
        {
            var changeReference = new ChangeReference(change, snapshot);

            _main.QueueChange(changeReference);
            return(changeReference);
        }
        private void QueueChange(SourceChange change, ITextSnapshot snapshot)
        {
            _dispatcher.AssertForegroundThread();

            _latestChangeReference = new ChangeReference(change, snapshot);
            _parser.QueueChange(change, snapshot);
        }
Exemple #5
0
        private void QueueChange(SourceChange change, ITextSnapshot snapshot)
        {
            _joinableTaskContext.AssertUIThread();

            // _parser can be null if we're in the midst of rebuilding the internal parser (TagHelper refresh/solution teardown)
            _latestChangeReference = _parser?.QueueChange(change, snapshot);
        }
        private void QueueChange(SourceChange change, ITextSnapshot snapshot)
        {
            _dispatcher.AssertForegroundThread();

            // _parser can be null if we're in the midst of rebuilding the internal parser (TagHelper refresh/solution teardown)
            _latestChangeReference = _parser?.QueueChange(change, snapshot);
        }
        // Internal for testing
        internal void OnDocumentStructureChanged(object state)
        {
            _dispatcher.AssertForegroundThread();

            if (_disposed)
            {
                return;
            }

            var backgroundParserArgs = (BackgroundParserResultsReadyEventArgs)state;
            if (_latestChangeReference == null || // extra hardening
                _latestChangeReference != backgroundParserArgs.ChangeReference)
            {
                // In the middle of parsing a newer change or about to parse a newer change.
                return;
            }

            if (backgroundParserArgs.ChangeReference.Snapshot != TextBuffer.CurrentSnapshot)
            {
                // Changes have impacted the snapshot after our we recorded our last change reference.
                // This can happen for a multitude of reasons, usually because of a user auto-completing
                // C# statements (causes multiple edits in quick succession). This ensures that our latest
                // parse corresponds to the current snapshot.
                QueueReparse();
                return;
            }

            _latestChangeReference = null;

            var documentStructureChangedArgs = new DocumentStructureChangedEventArgs(
                backgroundParserArgs.ChangeReference.Change,
                backgroundParserArgs.ChangeReference.Snapshot,
                backgroundParserArgs.CodeDocument);
            DocumentStructureChanged?.Invoke(this, documentStructureChangedArgs);
        }
            public void QueueChange(ChangeReference change)
            {
                // Any thread can queue a change.

                lock (_stateLock)
                {
                    // CurrentParcel token source is not null ==> There's a parse underway
                    if (_currentParcelCancelSource != null)
                    {
                        _currentParcelCancelSource.Cancel();
                    }

                    _changes.Add(change);
                    _hasParcel.Set();
                }
            }
Exemple #9
0
 public BackgroundParserResultsReadyEventArgs(ChangeReference edit, RazorCodeDocument codeDocument)
 {
     ChangeReference = edit;
     CodeDocument    = codeDocument;
 }