private bool CatchAnalyzerException(Exception e, DiagnosticAnalyzer analyzer, bool testOnly_DonotCatchAnalyzerExceptions)
        {
            DiagnosticAnalyzerLogger.LogAnalyzerCrashCount(analyzer, e, _logAggregator);

            if (testOnly_DonotCatchAnalyzerExceptions)
            {
                return(false);
            }

            if (AnalyzerHelper.IsBuiltInAnalyzer(analyzer))
            {
                return(FatalError.ReportWithoutCrashUnlessCanceled(e));
            }

            return(true);
        }
示例#2
0
        /// <summary>
        /// Return <see cref="DiagnosticAnalyzer.SupportedDiagnostics"/> of given <paramref name="analyzer"/>.
        /// </summary>
        public ImmutableArray <DiagnosticDescriptor> GetDiagnosticDescriptors(DiagnosticAnalyzer analyzer)
        {
            var descriptors = _descriptorCache.GetValue(analyzer, key =>
            {
                try
                {
                    return(analyzer.SupportedDiagnostics);
                }
                catch when(!AnalyzerHelper.IsBuiltInAnalyzer(analyzer))
                {
                    // TODO: here, we should report the issue to host update service
                    // If the SupportedDiagnostics throws an exception, then we don't want to run the analyzer.
                    return(ImmutableArray <DiagnosticDescriptor> .Empty);
                }
            });

            return((ImmutableArray <DiagnosticDescriptor>)descriptors);
        }
        /// <summary>
        /// Return <see cref="DiagnosticAnalyzer.SupportedDiagnostics"/> of given <paramref name="analyzer"/>.
        /// </summary>
        public ImmutableArray <DiagnosticDescriptor> GetDiagnosticDescriptors(DiagnosticAnalyzer analyzer)
        {
            Func <Exception, DiagnosticAnalyzer, bool> continueOnAnalyzerException = (ex, a) => !AnalyzerHelper.IsBuiltInAnalyzer(analyzer);
            var analyzerExecutor = AnalyzerHelper.GetAnalyzerExecutorForSupportedDiagnostics(analyzer, _hostDiagnosticUpdateSource, continueOnAnalyzerException, CancellationToken.None);

            return(AnalyzerManager.Instance.GetSupportedDiagnosticDescriptors(analyzer, analyzerExecutor));
        }