Esempio n. 1
0
        internal void UpdateErrors(ITextSnapshot currentSnapshot, ErrorSnapShot errors)
        {
            ErrorSnapShot oldErrors = _errors;

            _errors = errors;

            EventHandler <SnapshotSpanEventArgs> h = this.TagsChanged;

            if (h != null)
            {
                // Raise a single tags changed event over the span that could have been affected by the change in the errors.
                int start = int.MaxValue;
                int end   = int.MinValue;

                if ((oldErrors != null) && (oldErrors.Errors.Count > 0))
                {
                    start = oldErrors.Errors[0].Span.Start.TranslateTo(currentSnapshot, PointTrackingMode.Negative);
                    end   = oldErrors.Errors[oldErrors.Errors.Count - 1].Span.End.TranslateTo(currentSnapshot, PointTrackingMode.Positive);
                }

                if (errors.Count > 0)
                {
                    start = Math.Min(start, errors.Errors[0].Span.Start.Position);
                    end   = Math.Max(end, errors.Errors[errors.Errors.Count - 1].Span.End.Position);
                }

                if (start < end)
                {
                    h(this, new SnapshotSpanEventArgs(new SnapshotSpan(currentSnapshot, Span.FromBounds(start, end))));
                }
            }
        }
Esempio n. 2
0
        private void OnBufferChange(object sender, TextContentChangedEventArgs e)
        {
            _currentSnapshot = e.After;

            // Translate all errors to the new snapshot (and remove anything that is a dirty region since we will need to check that again).
            var oldErrors = this._factory.CurrentSnapshot;
            var newErrors = new ErrorSnapShot(this._filePath, oldErrors.VersionNumber + 1);

            // Copy all of the old errors to the new errors unless the error was affected by the text change
            foreach (var error in oldErrors.Errors)
            {
                Debug.Assert(error.NextIndex == -1);

                ErrorSpan newError = ErrorSpan.CloneAndTranslateTo(error, e.After);

                if (newError != null)
                {
                    Debug.Assert(newError.Span.Length == error.Span.Length);
                    error.NextIndex = newErrors.Errors.Count;
                    newErrors.Errors.Add(newError);
                }
            }

            this.UpdateErrors(newErrors);

            this.KickUpdate();
        }
Esempio n. 3
0
        internal ErrorHighLightTagger(ErrorHighLightChecker errorChecker)
        {
            _errorChecker = errorChecker;
            _errors       = errorChecker.LastError;

            errorChecker.AddTagger(this);
        }
Esempio n. 4
0
        private void DoUpdate()
        {
            // It would be good to do all of this work on a background thread but we can't:
            //      _classifier.GetClassificationSpans() should only be called on the UI thread because some classifiers assume they are called from the UI thread.
            //      Raising the TagsChanged event from the taggers needs to happen on the UI thread (because some consumers might assume it is being raised on the UI thread).
            //
            // Updating the snapshot for the factory and calling the sink can happen on any thread but those operations are so fast that there is no point.
            if (!_isDisposed)
            {
                if (_buffer.Equals(_textview.TextBuffer))
                {
                    ErrorSnapShot           oldErrors = this._factory.CurrentSnapshot;
                    ErrorSnapShot           newErrors = new ErrorSnapShot(this._filePath, oldErrors.VersionNumber + 1);
                    List <ErrorInformation> newSpanErrors;
                    // Go through the existing errors. If they are on the line we are currently parsing then
                    // copy them to oldLineErrors, otherwise they go to the new errors.

                    newSpanErrors = this.GetErrorInformation(_buffer.CurrentSnapshot.GetText());
                    if (!newSpanErrors.Equals(_spanErrors))
                    {
                        _spanErrors.Clear();
                        _spanErrors.AddRange(newSpanErrors);
                        foreach (ErrorInformation spanError in _spanErrors)
                        {
                            if (spanError.Length >= 0)
                            {
                                SnapshotSpan newSpan  = new SnapshotSpan(_buffer.CurrentSnapshot, spanError.StartIndex, spanError.Length);
                                ErrorSpan    oldError = oldErrors.Errors.Find((e) => e.Span == newSpan);

                                if (oldError != null)
                                {
                                    // There was a error at the same span as the old one so we should be able to just reuse it.
                                    oldError.NextIndex = newErrors.Errors.Count;
                                    newErrors.Errors.Add(ErrorSpan.Clone(oldError));    // Don't clone the old error yet
                                }
                                else
                                {
                                    newErrors.Errors.Add(new ErrorSpan(newSpan, spanError.ErrorMessage, spanError.ErrorCode));
                                }
                            }
                        }
                        this.UpdateErrors(newErrors);
                    }
                    else
                    {
                        foreach (var error in oldErrors.Errors)
                        {
                            error.NextIndex = -1;
                        }
                    }
                }
            }
            _isUpdating = false;
        }
Esempio n. 5
0
        private void UpdateErrors(ErrorSnapShot errors)
        {
            // Tell our factory to snap to a new snapshot.
            this._factory.UpdateErrors(errors);

            // Tell the provider to mark all the sinks dirty (so, as a side-effect, they will start an update pass that will get the new snapshot
            // from the factory).
            _provider.UpdateAllSinks();

            foreach (var tagger in _activeTaggers)
            {
                tagger.UpdateErrors(_currentSnapshot, errors);
            }

            this.LastError = errors;
        }
Esempio n. 6
0
 internal void UpdateErrors(ErrorSnapShot errors)
 {
     this.CurrentSnapshot.NextSnapshot = errors;
     this.CurrentSnapshot = errors;
 }
Esempio n. 7
0
        public ErrorFactory(ErrorHighLightChecker errorChecker, ErrorSnapShot errors)
        {
            _errorChecker = errorChecker;

            this.CurrentSnapshot = errors;
        }