public IClassifier GetClassifier(ITextBuffer textBuffer)
        {
            var dte = (DTE)ServiceProvider.GetService(typeof(DTE));

            ClangServices.Initialize(dte);
            Func <IClassifier> preprocessorClassifierFunc = () => new PreprocessorClassifier(dte, textBuffer, classificationTypeRegistry) as IClassifier;

            return(textBuffer.Properties.GetOrCreateSingletonProperty <IClassifier>(preprocessorClassifierFunc));
        }
        public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag
        {
            var dte = (DTE)ServiceProvider.GetService(typeof(DTE));

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

            return(buffer.Properties.GetOrCreateSingletonProperty <ITagger <T> >(taggerFunc));
        }
Exemple #3
0
        void FindSkippedRegions()
        {
            lock (obj)
            {
                excludedSpans.Clear();

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

                ClangServices.Process(buffer);
                var preprocessor = ClangServices.GetPreprocessorAdapter(buffer);
                if (preprocessor == null)
                {
                    return;
                }

                {
                    foreach (var skippedBlock in preprocessor.GetSkippedBlockLineNumbers())
                    {
                        var textLine      = buffer.CurrentSnapshot.GetLineFromLineNumber(skippedBlock.Item1 - 1);
                        var startPosition = textLine.Start.Position;

                        int endLineNumber = skippedBlock.Item2 == 0 ? buffer.CurrentSnapshot.LineCount : skippedBlock.Item2;
                        var endTextLine   = buffer.CurrentSnapshot.GetLineFromLineNumber(endLineNumber - 1);
                        var endPosition   = endTextLine.End.Position;

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

                        if (!lastSpan.IsEmpty)
                        {
                            minPosition = Math.Min(minPosition, lastSpan.Start);
                            maxPosition = Math.Max(maxPosition, lastSpan.End);
                        }

                        SnapshotSpan span = new SnapshotSpan(buffer.CurrentSnapshot, Span.FromBounds(startPosition, endPosition));
                        excludedSpans.Add(span);
                    }
                }

                minPosition = Math.Max(minPosition, 0);
                maxPosition = Math.Min(maxPosition, buffer.CurrentSnapshot.Length);

                if (excludedSpans.Any())
                {
                    RaiseTagsChanged(minPosition, maxPosition);
                }
                else
                {
                    if (ClassificationChanged != null)
                    {
                        ClassificationChanged(this, new ClassificationChangedEventArgs(new SnapshotSpan(buffer.CurrentSnapshot, Span.FromBounds(0, buffer.CurrentSnapshot.Length))));
                    }
                }
            }
        }
Exemple #4
0
        private void FindDiagnostics()
        {
            spansAndDiagnostics.Clear();

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

            ClangServices.Process(buffer);
            foreach (var diagnostic in ClangServices.GetDiagnostics(buffer))
            {
                if (!diagnostic.FilePath.Any(c => Path.GetInvalidPathChars().Contains(c)))
                {
                    // Crude check, should find a more sophisticated way to check if two paths are equal, ignoring different directory separator chars.
                    if (Path.GetFileName(diagnostic.FilePath) == Path.GetFileName(document.FilePath))
                    {
                        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)
                {
                    TagsChanged(this, new SnapshotSpanEventArgs(lastTotalDiagnosticsSpan));
                }
            }
        }
Exemple #5
0
        public static IEnumerable <Diagnostic> Find(ITextBuffer buffer)
        {
            ITextDocument document;

            if (!buffer.Properties.TryGetProperty(typeof(ITextDocument), out document) || document == null)
            {
                return(Enumerable.Empty <Diagnostic>());
            }

            ClangServices.Process(buffer);
            ErrorList.ClearDiagnosticsFromFile(document.FilePath);

            var diags = (from diag in ClangServices.GetDiagnostics(buffer)
                         where DiagnosticsBlacklist.Contains(diag) == false &&
                         !diag.FilePath.Any(c => Path.GetInvalidPathChars().Contains(c)) &&
                         Path.GetFileName(diag.FilePath) == Path.GetFileName(document.FilePath)
                         select diag).ToList();

            ErrorList.Show(diags);
            return(diags);
        }
Exemple #6
0
 public static void Initialize(IServiceProvider serviceProvider, DTE dte)
 {
     ErrorList.Initialize(serviceProvider, dte);
     ClangServices.Initialize(dte);
     DiagnosticsBlacklist.Initialize();
 }