/// <summary> /// Find the Error tokens in the set of all tokens and create an ErrorTag for each /// </summary> public IEnumerable <ITagSpan <ErrorTag> > GetTags(NormalizedSnapshotSpanCollection spans) { foreach (var tagSpan in this._aggregator.GetTags(spans)) { if (tagSpan.Tag.type == PkgDefLanguageTokens.Error) { var tagSpans = tagSpan.Span.GetSpans(spans[0].Snapshot); PkgDefErrorTag tag = tagSpan.Tag as PkgDefErrorTag; yield return(new TagSpan <ErrorTag>(tagSpans[0], new ErrorTag("error", tag.message))); } } }
#pragma warning restore /// <summary> /// Updates the Error List by clearing our items and adding any errors found in the current set of tags /// </summary> void ReparseFile(object sender, EventArgs args) { ITextSnapshot snapshot = _buffer.CurrentSnapshot; NormalizedSnapshotSpanCollection spans = new NormalizedSnapshotSpanCollection(new SnapshotSpan(snapshot, 0, snapshot.Length)); _errorProvider.Tasks.Clear(); foreach (var tagSpan in this._aggregator.GetTags(spans)) { if (tagSpan.Tag.type == PkgDefLanguageTokens.Error) { var tagSpans = tagSpan.Span.GetSpans(spans[0].Snapshot); PkgDefErrorTag tag = tagSpan.Tag as PkgDefErrorTag; AddErrorTask(tagSpans[0], tag); } } }
/// <summary> /// Add one task to the Error List based on the given tag /// </summary> private void AddErrorTask(SnapshotSpan span, PkgDefErrorTag tag) { if (_errorProvider != null) { ErrorTask task = new ErrorTask(); task.CanDelete = true; if (_document != null) { task.Document = _document.FilePath; } task.ErrorCategory = TaskErrorCategory.Error; task.Text = tag.message; task.Line = span.Start.GetContainingLine().LineNumber; task.Column = span.Start.Position - span.Start.GetContainingLine().Start.Position; task.Navigate += new EventHandler(task_Navigate); _errorProvider.Tasks.Add(task); } }