Exemplo n.º 1
0
        private void GenerateDiagnostics(IEnumerable <ClangDiagnostic> clangDiagnostics, ClangTranslationUnit translationUnit, IProject project, TextSegmentCollection <Diagnostic> result)
        {
            foreach (var diagnostic in clangDiagnostics)
            {
                if (diagnostic.Location.IsFromMainFile)
                {
                    var diag = new Diagnostic
                    {
                        Project     = project,
                        StartOffset = diagnostic.Location.FileLocation.Offset,
                        Line        = diagnostic.Location.FileLocation.Line,
                        Spelling    = diagnostic.Spelling,
                        File        = diagnostic.Location.FileLocation.File.FileName,
                        Level       = (DiagnosticLevel)diagnostic.Severity
                    };

                    var cursor = translationUnit.GetCursor(diagnostic.Location);

                    var tokens = translationUnit.Tokenize(cursor.CursorExtent);

                    foreach (var token in tokens.Tokens)
                    {
                        if (token.Location == diagnostic.Location)
                        {
                            diag.EndOffset = diag.StartOffset + token.Spelling.Length;
                        }
                    }

                    result.Add(diag);
                    tokens.Dispose();
                }
            }
        }
        private void GenerateDiagnostics(IEnumerable <ClangDiagnostic> clangDiagnostics, ClangTranslationUnit translationUnit, ISourceFile file, List <Diagnostic> result)
        {
            foreach (var diagnostic in clangDiagnostics)
            {
                if (diagnostic.Location.IsFromMainFile)
                {
                    var diag = new Diagnostic(
                        diagnostic.Location.FileLocation.Offset,
                        0,
                        file.Project,
                        diagnostic.Location.FileLocation.File.FileName,
                        diagnostic.Location.FileLocation.Line,
                        diagnostic.Spelling,
                        (DiagnosticLevel)diagnostic.Severity,
                        DiagnosticCategory.Compiler);

                    var cursor = translationUnit.GetCursor(diagnostic.Location);

                    var tokens = translationUnit.Tokenize(cursor.CursorExtent);

                    foreach (var token in tokens.Tokens)
                    {
                        if (token.Location == diagnostic.Location)
                        {
                            diag.EndOffset = diag.StartOffset + token.Spelling.Length;
                        }
                    }

                    result.Add(diag);
                    tokens.Dispose();
                }
            }
        }
Exemplo n.º 3
0
        private void GenerateDiagnostics(IEnumerable <ClangDiagnostic> clangDiagnostics, ClangTranslationUnit translationUnit, IProject project, TextSegmentCollection <Diagnostic> result, TextMarkerService service)
        {
            foreach (var diagnostic in clangDiagnostics)
            {
                if (diagnostic.Location.IsFromMainFile)
                {
                    var diag = new Diagnostic
                    {
                        Project     = project,
                        StartOffset = diagnostic.Location.FileLocation.Offset,
                        Line        = diagnostic.Location.FileLocation.Line,
                        Spelling    = diagnostic.Spelling,
                        File        = diagnostic.Location.FileLocation.File.FileName,
                        Level       = (DiagnosticLevel)diagnostic.Severity
                    };

                    var cursor = translationUnit.GetCursor(diagnostic.Location);

                    var tokens = translationUnit.Tokenize(cursor.CursorExtent);

                    foreach (var token in tokens.Tokens)
                    {
                        if (token.Location == diagnostic.Location)
                        {
                            diag.EndOffset = diag.StartOffset + token.Spelling.Length;
                        }
                    }

                    result.Add(diag);
                    tokens.Dispose();

                    Color markerColor;

                    switch (diag.Level)
                    {
                    case DiagnosticLevel.Error:
                    case DiagnosticLevel.Fatal:
                        markerColor = Color.FromRgb(253, 45, 45);
                        break;

                    case DiagnosticLevel.Warning:
                        markerColor = Color.FromRgb(255, 207, 40);
                        break;

                    default:
                        markerColor = Color.FromRgb(0, 42, 74);
                        break;
                    }

                    service.Create(diag.StartOffset, diag.Length, diag.Spelling, markerColor);
                }
            }
        }