private static bool HasSemanticDocumentActions(AnalyzerActions analyzerActions)
 {
     return analyzerActions.SymbolActionsCount > 0 ||
         analyzerActions.SyntaxNodeActionsCount > 0 ||
         analyzerActions.SemanticModelActionsCount > 0 ||
         analyzerActions.CodeBlockActionsCount > 0 ||
         analyzerActions.CodeBlockStartActionsCount > 0;
 }
        internal static AnalyzerActionCounts Create(AnalyzerActions analyzerActions)
        {
            if (analyzerActions == null)
            {
                return Empty;
            }

            return new AnalyzerActionCounts(analyzerActions);
        }
 public void SetAnalyzerTypeCount(AnalyzerActions analyzerActions)
 {
     Counts[0] = analyzerActions.CodeBlockEndActionsCount;
     Counts[1] = analyzerActions.CodeBlockStartActionsCount;
     Counts[2] = analyzerActions.CompilationEndActionsCount;
     Counts[3] = analyzerActions.CompilationStartActionsCount;
     Counts[4] = analyzerActions.SemanticModelActionsCount;
     Counts[5] = analyzerActions.SymbolActionsCount;
     Counts[6] = analyzerActions.SyntaxNodeActionsCount;
     Counts[7] = analyzerActions.SyntaxTreeActionsCount;
 }
Exemple #4
0
 private AnalyzerActionCounts(AnalyzerActions analyzerActions)
 {
     CompilationStartActionsCount = analyzerActions.CompilationStartActionsCount;
     CompilationEndActionsCount = analyzerActions.CompilationEndActionsCount;
     CompilationActionsCount = analyzerActions.CompilationActionsCount;
     SyntaxTreeActionsCount = analyzerActions.SyntaxTreeActionsCount;
     SemanticModelActionsCount = analyzerActions.SemanticModelActionsCount;
     SymbolActionsCount = analyzerActions.SymbolActionsCount;
     SyntaxNodeActionsCount = analyzerActions.SyntaxNodeActionsCount;
     CodeBlockStartActionsCount = analyzerActions.CodeBlockStartActionsCount;
     CodeBlockEndActionsCount = analyzerActions.CodeBlockEndActionsCount;
     CodeBlockActionsCount = analyzerActions.CodeBlockActionsCount;
 }
 private ActionCounts(AnalyzerActions analyzerActions)
 {
     CompilationStartActionsCount = analyzerActions.CompilationStartActionsCount;
     CompilationEndActionsCount   = analyzerActions.CompilationEndActionsCount;
     CompilationActionsCount      = analyzerActions.CompilationActionsCount;
     SyntaxTreeActionsCount       = analyzerActions.SyntaxTreeActionsCount;
     SemanticModelActionsCount    = analyzerActions.SemanticModelActionsCount;
     SymbolActionsCount           = analyzerActions.SymbolActionsCount;
     SyntaxNodeActionsCount       = analyzerActions.SyntaxNodeActionsCount;
     CodeBlockStartActionsCount   = analyzerActions.CodeBlockStartActionsCount;
     CodeBlockEndActionsCount     = analyzerActions.CodeBlockEndActionsCount;
     CodeBlockActionsCount        = analyzerActions.CodeBlockActionsCount;
 }
 public void SetAnalyzerTypeCount(AnalyzerActions analyzerActions)
 {
     Counts[0] = analyzerActions.CodeBlockActionsCount;
     Counts[1] = analyzerActions.CodeBlockEndActionsCount;
     Counts[2] = analyzerActions.CodeBlockStartActionsCount;
     Counts[3] = analyzerActions.CompilationActionsCount;
     Counts[4] = analyzerActions.CompilationEndActionsCount;
     Counts[5] = analyzerActions.CompilationStartActionsCount;
     Counts[6] = analyzerActions.SemanticModelActionsCount;
     Counts[7] = analyzerActions.SymbolActionsCount;
     Counts[8] = analyzerActions.SyntaxNodeActionsCount;
     Counts[9] = analyzerActions.SyntaxTreeActionsCount;
 }
            public AnalyzerInfo(DiagnosticAnalyzer analyzer, AnalyzerActions analyzerActions, bool telemetry)
            {
                CLRType   = analyzer.GetType();
                Telemetry = telemetry;

                Counts[0] = analyzerActions.CodeBlockEndActionsCount;
                Counts[1] = analyzerActions.CodeBlockStartActionsCount;
                Counts[2] = analyzerActions.CompilationEndActionsCount;
                Counts[3] = analyzerActions.CompilationStartActionsCount;
                Counts[4] = analyzerActions.SemanticModelActionsCount;
                Counts[5] = analyzerActions.SymbolActionsCount;
                Counts[6] = analyzerActions.SyntaxNodeActionsCount;
                Counts[7] = analyzerActions.SyntaxTreeActionsCount;
            }
        public void UpdateAnalyzerTypeCount(DiagnosticAnalyzer analyzer, AnalyzerActions analyzerActions)
        {
            var telemetry = DiagnosticAnalyzerLogger.AllowsTelemetry(_owner, analyzer);

            ImmutableInterlocked.AddOrUpdate(
                ref _analyzerInfoMap,
                analyzer.GetType(),
                addValue: new AnalyzerInfo(analyzer, analyzerActions, telemetry),
                updateValueFactory: (k, ai) =>
                {
                    ai.SetAnalyzerTypeCount(analyzerActions);
                    return ai;
                });
        }
Exemple #9
0
            public AnalyzerActions Append(AnalyzerActions otherActions)
            {
                AnalyzerActions actions = new AnalyzerActions();
                actions.compilationStartActions = this.compilationStartActions.AddRange(otherActions.compilationStartActions);
                actions.compilationEndActions = this.compilationEndActions.AddRange(otherActions.compilationEndActions);
                actions.syntaxTreeActions = this.syntaxTreeActions.AddRange(otherActions.syntaxTreeActions);
                actions.semanticModelActions = this.semanticModelActions.AddRange(otherActions.semanticModelActions);
                actions.symbolActions = this.symbolActions.AddRange(otherActions.symbolActions);
                actions.codeBlockStartActions = this.codeBlockStartActions.AddRange(otherActions.codeBlockStartActions);
                actions.codeBlockEndActions = this.codeBlockEndActions.AddRange(otherActions.codeBlockEndActions);
                actions.syntaxNodeActions = this.syntaxNodeActions.AddRange(otherActions.syntaxNodeActions);

                return actions;
            }
            public AnalyzerInfo(DiagnosticAnalyzer analyzer, AnalyzerActions analyzerActions, bool telemetry)
            {
                CLRType = analyzer.GetType();
                Telemetry = telemetry;

                Counts[0] = analyzerActions.CodeBlockEndActionsCount;
                Counts[1] = analyzerActions.CodeBlockStartActionsCount;
                Counts[2] = analyzerActions.CompilationEndActionsCount;
                Counts[3] = analyzerActions.CompilationStartActionsCount;
                Counts[4] = analyzerActions.SemanticModelActionsCount;
                Counts[5] = analyzerActions.SymbolActionsCount;
                Counts[6] = analyzerActions.SyntaxNodeActionsCount;
                Counts[7] = analyzerActions.SyntaxTreeActionsCount;
            }
        public void UpdateAnalyzerTypeCount(DiagnosticAnalyzer analyzer, AnalyzerActions analyzerActions)
        {
            var telemetry = DiagnosticAnalyzerLogger.AllowsTelemetry(_owner, analyzer);

            ImmutableInterlocked.AddOrUpdate(
                ref _analyzerInfoMap,
                analyzer.GetType(),
                addValue: new AnalyzerInfo(analyzer, analyzerActions, telemetry),
                updateValueFactory: (k, ai) =>
            {
                ai.SetAnalyzerTypeCount(analyzerActions);
                return(ai);
            });
        }
 internal ActionCounts(AnalyzerActions analyzerActions)
 {
     analyzerActions = analyzerActions ?? AnalyzerActions.Empty;
     CompilationStartActionsCount = analyzerActions.CompilationStartActionsCount;
     CompilationEndActionsCount = analyzerActions.CompilationEndActionsCount;
     CompilationActionsCount = analyzerActions.CompilationActionsCount;
     SyntaxTreeActionsCount = analyzerActions.SyntaxTreeActionsCount;
     SemanticModelActionsCount = analyzerActions.SemanticModelActionsCount;
     SymbolActionsCount = analyzerActions.SymbolActionsCount;
     SyntaxNodeActionsCount = analyzerActions.SyntaxNodeActionsCount;
     CodeBlockStartActionsCount = analyzerActions.CodeBlockStartActionsCount;
     CodeBlockEndActionsCount = analyzerActions.CodeBlockEndActionsCount;
     CodeBlockActionsCount = analyzerActions.CodeBlockActionsCount;
 }
Exemple #13
0
            public override AnalyzerActions GetAnalyzerActions(DiagnosticAnalyzer analyzer)
            {
                AnalyzerActions compilationActions = base.GetAnalyzerActions(analyzer);
                AnalyzerActions sessionActions = this.sessionScope.GetAnalyzerActions(analyzer);

                if (sessionActions == null)
                {
                    return compilationActions;
                }

                if (compilationActions == null)
                {
                    return sessionActions;
                }

                return compilationActions.Append(sessionActions);
            }
        /// <summary>
        /// Initializes the compilation for the analyzer driver.
        /// It also computes and initializes <see cref="analyzerActions"/> and <see cref="_symbolActionsByKind"/>.
        /// Finally, it initializes and starts the <see cref="_primaryTask"/> for the driver.
        /// </summary>
        /// <remarks>
        /// NOTE: This method must only be invoked from <see cref="AnalyzerDriver.Create(Compilation, ImmutableArray{DiagnosticAnalyzer}, AnalyzerOptions, AnalyzerManager, Action{Diagnostic}, out Compilation, CancellationToken)"/>.
        /// </remarks>
        private void Initialize(Compilation comp, AnalyzerExecutor analyzerExecutor, CancellationToken cancellationToken)
        {
            try
            {
                Debug.Assert(_compilation == null);
                Debug.Assert(comp.EventQueue == this.CompilationEventQueue);

                _compilation = comp;
                this.analyzerExecutor = analyzerExecutor;

                // Compute the set of effective actions based on suppression, and running the initial analyzers
                var analyzerActionsTask = GetAnalyzerActionsAsync(_analyzers, analyzerManager, analyzerExecutor);
                var initializeTask = analyzerActionsTask.ContinueWith(t =>
                {
                    this.analyzerActions = t.Result;
                    _symbolActionsByKind = MakeSymbolActionsByKind();
                    _semanticModelActionsMap = MakeSemanticModelActionsByAnalyzer();
                    _compilationActionsMap = MakeCompilationActionsByAnalyzer(this.analyzerActions.CompilationActions);
                    _compilationEndActionsMap = MakeCompilationActionsByAnalyzer(this.analyzerActions.CompilationEndActions);
                }, cancellationToken, TaskContinuationOptions.None, TaskScheduler.Default);

                // create the primary driver task.
                cancellationToken.ThrowIfCancellationRequested();
                _primaryTask = Task.Run(async () =>
                    {
                        await initializeTask.ConfigureAwait(false);

                        await ProcessCompilationEventsAsync(cancellationToken).ConfigureAwait(false);
                    }, cancellationToken)
                    .ContinueWith(c => DiagnosticQueue.TryComplete(), cancellationToken, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
            }
            finally
            {
                if (_primaryTask == null)
                {
                    // Set primaryTask to be a cancelled task.
                    var tcs = new TaskCompletionSource<int>();
                    tcs.SetCanceled();
                    _primaryTask = tcs.Task;

                    // Try to set the DiagnosticQueue to be complete.
                    this.DiagnosticQueue.TryComplete();
                }
            }
        }
 internal AnalyzerActionCounts(AnalyzerActions analyzerActions) :
     this(
         analyzerActions?.CompilationStartActionsCount ?? 0,
         analyzerActions?.CompilationEndActionsCount ?? 0,
         analyzerActions?.CompilationActionsCount ?? 0,
         analyzerActions?.SyntaxTreeActionsCount ?? 0,
         analyzerActions?.SemanticModelActionsCount ?? 0,
         analyzerActions?.SymbolActionsCount ?? 0,
         analyzerActions?.SyntaxNodeActionsCount ?? 0,
         analyzerActions?.CodeBlockStartActionsCount ?? 0,
         analyzerActions?.CodeBlockEndActionsCount ?? 0,
         analyzerActions?.CodeBlockActionsCount ?? 0,
         analyzerActions?.OperationActionsCount ?? 0,
         analyzerActions?.OperationBlockStartActionsCount ?? 0,
         analyzerActions?.OperationBlockEndActionsCount ?? 0,
         analyzerActions?.OperationBlockActionsCount ?? 0)
 {
 }
 internal AnalyzerActionCounts(AnalyzerActions analyzerActions) :
     this(
         analyzerActions?.CompilationStartActionsCount ?? 0,
         analyzerActions?.CompilationEndActionsCount ?? 0,
         analyzerActions?.CompilationActionsCount ?? 0,
         analyzerActions?.SyntaxTreeActionsCount ?? 0,
         analyzerActions?.SemanticModelActionsCount ?? 0,
         analyzerActions?.SymbolActionsCount ?? 0,
         analyzerActions?.SyntaxNodeActionsCount ?? 0,
         analyzerActions?.CodeBlockStartActionsCount ?? 0,
         analyzerActions?.CodeBlockEndActionsCount ?? 0,
         analyzerActions?.CodeBlockActionsCount ?? 0,
         analyzerActions?.OperationActionsCount ?? 0,
         analyzerActions?.OperationBlockStartActionsCount ?? 0,
         analyzerActions?.OperationBlockEndActionsCount ?? 0,
         analyzerActions?.OperationBlockActionsCount ?? 0)
 {
 }
        private AnalyzerActionCounts(AnalyzerActions analyzerActions)
        {
            CompilationStartActionsCount    = analyzerActions.CompilationStartActionsCount;
            CompilationEndActionsCount      = analyzerActions.CompilationEndActionsCount;
            CompilationActionsCount         = analyzerActions.CompilationActionsCount;
            SyntaxTreeActionsCount          = analyzerActions.SyntaxTreeActionsCount;
            SemanticModelActionsCount       = analyzerActions.SemanticModelActionsCount;
            SymbolActionsCount              = analyzerActions.SymbolActionsCount;
            SyntaxNodeActionsCount          = analyzerActions.SyntaxNodeActionsCount;
            CodeBlockStartActionsCount      = analyzerActions.CodeBlockStartActionsCount;
            CodeBlockEndActionsCount        = analyzerActions.CodeBlockEndActionsCount;
            CodeBlockActionsCount           = analyzerActions.CodeBlockActionsCount;
            OperationActionsCount           = analyzerActions.OperationActionsCount;
            OperationBlockStartActionsCount = analyzerActions.OperationBlockStartActionsCount;
            OperationBlockEndActionsCount   = analyzerActions.OperationBlockEndActionsCount;
            OperationBlockActionsCount      = analyzerActions.OperationBlockActionsCount;

            HasAnyExecutableCodeActions = CodeBlockActionsCount > 0 ||
                                          CodeBlockStartActionsCount > 0 ||
                                          SyntaxNodeActionsCount > 0 ||
                                          OperationActionsCount > 0 ||
                                          OperationBlockActionsCount > 0 ||
                                          OperationBlockStartActionsCount > 0;
        }
        private AnalyzerActionCounts(AnalyzerActions analyzerActions)
        {
            CompilationStartActionsCount = analyzerActions.CompilationStartActionsCount;
            CompilationEndActionsCount = analyzerActions.CompilationEndActionsCount;
            CompilationActionsCount = analyzerActions.CompilationActionsCount;
            SyntaxTreeActionsCount = analyzerActions.SyntaxTreeActionsCount;
            SemanticModelActionsCount = analyzerActions.SemanticModelActionsCount;
            SymbolActionsCount = analyzerActions.SymbolActionsCount;
            SyntaxNodeActionsCount = analyzerActions.SyntaxNodeActionsCount;
            CodeBlockStartActionsCount = analyzerActions.CodeBlockStartActionsCount;
            CodeBlockEndActionsCount = analyzerActions.CodeBlockEndActionsCount;
            CodeBlockActionsCount = analyzerActions.CodeBlockActionsCount;
            OperationActionsCount = analyzerActions.OperationActionsCount;
            OperationBlockStartActionsCount = analyzerActions.OperationBlockStartActionsCount;
            OperationBlockEndActionsCount = analyzerActions.OperationBlockEndActionsCount;
            OperationBlockActionsCount = analyzerActions.OperationBlockActionsCount;

            HasAnyExecutableCodeActions = CodeBlockActionsCount > 0 ||
                CodeBlockStartActionsCount > 0 ||
                SyntaxNodeActionsCount > 0 ||
                OperationActionsCount > 0 ||
                OperationBlockActionsCount > 0 ||
                OperationBlockStartActionsCount > 0;
        }
        private AnalyzerActions GetPerCompilationAnalyzerActions(
            DiagnosticAnalyzer analyzer,
            AnalyzerActions sessionActions,
            Compilation compilation,
            Action<Diagnostic> addDiagnostic)
        {
            Contract.ThrowIfFalse(sessionActions.CompilationStartActionsCount > 0);

            var compilationActionsMap = s_compilationActionsTable.GetOrCreateValue(compilation);
            AnalyzerActions result;
            if (compilationActionsMap.TryGetValue(analyzer, out result))
            {
                return result;
            }

            result = AnalyzerDriverHelper.ExecuteCompilationStartActions(sessionActions, analyzer, compilation,
                _analyzerOptions, addDiagnostic, CatchAnalyzerException, _cancellationToken);

            if (!compilationActionsMap.TryAdd(analyzer, result))
            {
                return compilationActionsMap[analyzer];
            }

            return result;
        }
Exemple #20
0
        private static void VerifyArguments(
            SyntaxTree syntaxTree,
            AnalyzerActions actions,
            AnalyzerOptions analyzerOptions,
            Action<Diagnostic> addDiagnostic,
            Func<Exception, DiagnosticAnalyzer, bool> continueOnAnalyzerException)
        {
            if (syntaxTree == null)
            {
                throw new ArgumentNullException(nameof(syntaxTree));
            }

            VerifyArguments(actions, analyzerOptions, addDiagnostic, continueOnAnalyzerException);
        }
        public static void UpdateAnalyzerTypeCount(DiagnosticAnalyzer analyzer, AnalyzerActions analyzerActions, DiagnosticLogAggregator logAggregator)
        {
            if (analyzerActions == null || analyzer == null || logAggregator == null)
            {
                return;
            }

            logAggregator.UpdateAnalyzerTypeCount(analyzer, analyzerActions);
        }
Exemple #22
0
        private static void VerifyArguments(
            Compilation compilation,
            AnalyzerActions actions,
            AnalyzerOptions analyzerOptions,
            DiagnosticAnalyzer analyzer,
            Action<Diagnostic> addDiagnostic,
            Func<Exception, DiagnosticAnalyzer, bool> continueOnAnalyzerException)
        {
            if (compilation == null)
            {
                throw new ArgumentNullException(nameof(compilation));
            }

            if (analyzer == null)
            {
                throw new ArgumentNullException(nameof(analyzer));
            }

            VerifyArguments(actions, analyzerOptions, addDiagnostic, continueOnAnalyzerException);
        }
Exemple #23
0
        /// <summary>
        /// Initializes the <see cref="analyzerActions"/> and related actions maps for the analyzer driver.
        /// It kicks off the <see cref="WhenInitializedTask"/> task for initialization.
        /// Note: This method must be invoked exactly once on the driver.
        /// </summary>
        private void Initialize(AnalyzerExecutor analyzerExecutor, DiagnosticQueue diagnosticQueue, CompilationData compilationData, CancellationToken cancellationToken)
        {
            try
            {
                Debug.Assert(_initializeTask == null);

                this.analyzerExecutor = analyzerExecutor;
                this.compilationData = compilationData;
                this.DiagnosticQueue = diagnosticQueue;

                // Compute the set of effective actions based on suppression, and running the initial analyzers
                _initializeTask = Task.Run(async () =>
                {
                    var unsuppressedAnalyzers = GetUnsuppressedAnalyzers(analyzers, analyzerManager, analyzerExecutor);
                    this.analyzerActions = await GetAnalyzerActionsAsync(unsuppressedAnalyzers, analyzerManager, analyzerExecutor).ConfigureAwait(false);
                    _analyzerGateMap = await GetAnalyzerGateMapAsync(unsuppressedAnalyzers, analyzerManager, analyzerExecutor).ConfigureAwait(false);

                    _generatedCodeAnalysisFlagsMap = await GetGeneratedCodeAnalysisFlagsAsync(unsuppressedAnalyzers, analyzerManager, analyzerExecutor).ConfigureAwait(false);
                    _doNotAnalyzeGeneratedCode = ShouldSkipAnalysisOnGeneratedCode(unsuppressedAnalyzers);
                    _treatAllCodeAsNonGeneratedCode = ShouldTreatAllCodeAsNonGeneratedCode(unsuppressedAnalyzers, _generatedCodeAnalysisFlagsMap);
                    _lazyGeneratedCodeFilesMap = _treatAllCodeAsNonGeneratedCode ? null : new Dictionary<SyntaxTree, bool>();
                    _lazyGeneratedCodeSymbolsMap = _treatAllCodeAsNonGeneratedCode ? null : new Dictionary<SyntaxTree, ImmutableHashSet<ISymbol>>();
                    _generatedCodeAttribute = analyzerExecutor.Compilation?.GetTypeByMetadataName("System.CodeDom.Compiler.GeneratedCodeAttribute");

                    _symbolActionsByKind = MakeSymbolActionsByKind();
                    _semanticModelActionsMap = MakeSemanticModelActionsByAnalyzer();
                    _syntaxTreeActionsMap = MakeSyntaxTreeActionsByAnalyzer();
                    _compilationActionsMap = MakeCompilationActionsByAnalyzer(this.analyzerActions.CompilationActions);
                    _compilationEndActionsMap = MakeCompilationActionsByAnalyzer(this.analyzerActions.CompilationEndActions);
                }, cancellationToken);

                // create the primary driver task. 
                cancellationToken.ThrowIfCancellationRequested();

                _initializeSucceeded = true;
            }
            finally
            {
                if (_initializeTask == null)
                {
                    // Set initializeTask to be a cancelled task.
                    var tcs = new TaskCompletionSource<int>();
                    tcs.SetCanceled();
                    _initializeTask = tcs.Task;

                    // Set primaryTask to be a cancelled task.
                    tcs = new TaskCompletionSource<int>();
                    tcs.SetCanceled();
                    _primaryTask = tcs.Task;

                    // Try to set the DiagnosticQueue to be complete.
                    this.DiagnosticQueue.TryComplete();
                }
            }
        }
Exemple #24
0
        private static Task<AnalyzerActions> GetAnalyzerActionsAsync(
            ImmutableArray<DiagnosticAnalyzer> analyzers,
            AnalyzerManager analyzerManager,
            AnalyzerExecutor analyzerExecutor)
        {
            return Task.Run(async () =>
            {
                AnalyzerActions allAnalyzerActions = new AnalyzerActions();
                foreach (var analyzer in analyzers)
                {
                    if (!IsDiagnosticAnalyzerSuppressed(analyzer, analyzerExecutor.Compilation.Options, analyzerManager, analyzerExecutor))
                    {
                        var analyzerActions = await analyzerManager.GetAnalyzerActionsAsync(analyzer, analyzerExecutor).ConfigureAwait(false);
                        if (analyzerActions != null)
                        {
                            allAnalyzerActions = allAnalyzerActions.Append(analyzerActions);
                        }
                    }
                }

                return allAnalyzerActions;
            }, analyzerExecutor.CancellationToken);
        }
Exemple #25
0
        private static void VerifyArguments(
            IEnumerable<ISymbol> symbols,
            Compilation compilation,
            AnalyzerActions actions,
            AnalyzerOptions analyzerOptions,
            Action<Diagnostic> addDiagnostic,
            Func<Exception, DiagnosticAnalyzer, bool> continueOnAnalyzerException)
        {
            if (symbols == null)
            {
                throw new ArgumentNullException(nameof(symbols));
            }

            if (symbols.Any(s => s == null))
            {
                throw new ArgumentException(CodeAnalysisResources.ArgumentElementCannotBeNull, nameof(symbols));
            }

            VerifyArguments(compilation, actions, analyzerOptions, addDiagnostic, continueOnAnalyzerException);
        }
Exemple #26
0
        internal static void VerifyArguments(
            AnalyzerActions actions,
            AnalyzerOptions analyzerOptions,
            Action<Diagnostic> addDiagnostic,
            Func<Exception, DiagnosticAnalyzer, bool> continueOnAnalyzerException)
        {
            if (actions == null)
            {
                throw new ArgumentNullException(nameof(actions));
            }

            VerifyArguments(analyzerOptions, addDiagnostic, continueOnAnalyzerException);
        }
Exemple #27
0
        /// <summary>
        /// Initializes the <see cref="analyzerActions"/> and related actions maps for the analyzer driver.
        /// It kicks off the <see cref="WhenInitializedTask"/> task for initialization.
        /// Note: This method must be invoked exactly once on the driver.
        /// </summary>
        private void Initialize(AnalyzerExecutor analyzerExecutor, DiagnosticQueue diagnosticQueue, CancellationToken cancellationToken)
        {
            try
            {
                Debug.Assert(_initializeTask == null);

                this.analyzerExecutor = analyzerExecutor;
                this.DiagnosticQueue = diagnosticQueue;

                // Compute the set of effective actions based on suppression, and running the initial analyzers
                var analyzerActionsTask = GetAnalyzerActionsAsync(analyzers, analyzerManager, analyzerExecutor);
                _initializeTask = analyzerActionsTask.ContinueWith(t =>
                {
                    this.analyzerActions = t.Result;
                    _symbolActionsByKind = MakeSymbolActionsByKind();
                    _semanticModelActionsMap = MakeSemanticModelActionsByAnalyzer();
                    _syntaxTreeActionsMap = MakeSyntaxTreeActionsByAnalyzer();
                    _compilationActionsMap = MakeCompilationActionsByAnalyzer(this.analyzerActions.CompilationActions);
                    _compilationEndActionsMap = MakeCompilationActionsByAnalyzer(this.analyzerActions.CompilationEndActions);
                }, cancellationToken, TaskContinuationOptions.None, TaskScheduler.Default);

                // create the primary driver task.
                cancellationToken.ThrowIfCancellationRequested();

                _initializeSucceeded = true;
            }
            finally
            {
                if (_initializeTask == null)
                {
                    // Set initializeTask to be a cancelled task.
                    var tcs = new TaskCompletionSource<int>();
                    tcs.SetCanceled();
                    _initializeTask = tcs.Task;

                    // Set primaryTask to be a cancelled task.
                    tcs = new TaskCompletionSource<int>();
                    tcs.SetCanceled();
                    _primaryTask = tcs.Task;

                    // Try to set the DiagnosticQueue to be complete.
                    this.DiagnosticQueue.TryComplete();
                }
            }
        }
Exemple #28
0
        private static async Task<AnalyzerActions> GetAnalyzerActionsAsync(
            ImmutableArray<DiagnosticAnalyzer> analyzers,
            AnalyzerManager analyzerManager,
            AnalyzerExecutor analyzerExecutor)
        {
            var allAnalyzerActions = new AnalyzerActions();
            foreach (var analyzer in analyzers)
            {
                Debug.Assert(!IsDiagnosticAnalyzerSuppressed(analyzer, analyzerExecutor.Compilation.Options, analyzerManager, analyzerExecutor));

                var analyzerActions = await analyzerManager.GetAnalyzerActionsAsync(analyzer, analyzerExecutor).ConfigureAwait(false);
                if (analyzerActions != null)
                {
                    allAnalyzerActions = allAnalyzerActions.Append(analyzerActions);
                }
            }

            return allAnalyzerActions;
        }