Exemplo n.º 1
0
        public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag
        {
            var dte = (DTE)ServiceProvider.GetService(typeof(DTE));

            DiagnosticsFinder.Initialize(ServiceProvider, dte);
            Func <ITagger <T> > taggerFunc = () => new DiagnosticTagger(dte, buffer) as ITagger <T>;

            return(buffer.Properties.GetOrCreateSingletonProperty <ITagger <T> >(taggerFunc));
        }
Exemplo n.º 2
0
        private void FindDiagnostics()
        {
            try
            {
                spansAndDiagnostics.Clear();

                int minPosition = buffer.CurrentSnapshot.Length;
                int maxPosition = 0;

                foreach (var diagnostic in DiagnosticsFinder.Find(buffer))
                {
                    if (diagnostic.StartLine != 0)
                    {
                        diagnostic.StartLine--;
                    }

                    var textLine      = buffer.CurrentSnapshot.GetLineFromLineNumber(diagnostic.StartLine);
                    var startPosition = textLine.Start.Position;
                    var endPosition   = textLine.End.Position;

                    minPosition = Math.Min(minPosition, startPosition);
                    maxPosition = Math.Max(maxPosition, endPosition);

                    SnapshotSpan span = new SnapshotSpan(buffer.CurrentSnapshot,
                                                         Span.FromBounds(startPosition, endPosition));
                    spansAndDiagnostics.Add(Tuple.Create(span, diagnostic));
                }

                if (spansAndDiagnostics.Any())
                {
                    RaiseTagsChanged(minPosition, maxPosition);
                }
                else
                {
                    if (TagsChanged != null && !lastTotalDiagnosticsSpan.IsEmpty)
                    {
                        TagsChanged(this, new SnapshotSpanEventArgs(lastTotalDiagnosticsSpan));
                    }
                }
            }
            catch (Exception e)
            {
                dte.StatusBar.Text = "Naggy Error: " + e.Message;
            }
        }