protected static void GatherDiagnostics(
            SyntaxElement root,
            List <Diagnostic> diagnostics,
            DiagnosticsInclude include,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            bool includeSyntax    = (include & DiagnosticsInclude.Syntactic) != 0;
            bool includeSemantic  = (include & DiagnosticsInclude.Semantic) != 0;
            bool includeExpansion = (include & DiagnosticsInclude.Expansion) != 0;

            var fnDescend = (include == DiagnosticsInclude.Syntactic)
                ? (Func <SyntaxElement, bool>)((SyntaxElement e) => e.ContainsSyntaxDiagnostics)
                : null;

            SyntaxElement.WalkElements(root,
                                       fnBefore: element =>
            {
                if (element.HasSyntaxDiagnostics && includeSyntax)
                {
                    // each syntax diagnostic is located at the element that carries it.
                    diagnostics.AddRange(element.SyntaxDiagnostics.Select(d => d.HasLocation ? d : SetLocation(d, element)));
                }

                if (includeSemantic && element is SyntaxNode node && node.SemanticDiagnostics.Count > 0)
                {
                    diagnostics.AddRange(node.SemanticDiagnostics);
                }
            },
 internal void InitializeTriviaStarts()
 {
     SyntaxElement.WalkElements(
         this.Root,
         fnBefore: element =>
     {
         System.Diagnostics.Debug.Assert(element.Parent == null || element.Parent._triviaStart >= 0);
         element._triviaStart = (element.Parent?._triviaStart ?? 0) + element.OffsetInParent;
     });
 }