コード例 #1
0
            public IncrementalAnalyzerDelegatee(DiagnosticAnalyzerService owner, Workspace workspace, HostAnalyzerManager hostAnalyzerManager, AbstractHostDiagnosticUpdateSource hostDiagnosticUpdateSource)
                : base(owner, workspace, hostAnalyzerManager, hostDiagnosticUpdateSource)
            {
                var v2CorrelationId = LogAggregator.GetNextId();

                _engineV2 = new EngineV2.DiagnosticIncrementalAnalyzer(owner, v2CorrelationId, workspace, hostAnalyzerManager, hostDiagnosticUpdateSource);
            }
コード例 #2
0
 public PreviewSolutionCrawlerRegistrationServiceFactory(IDiagnosticAnalyzerService analyzerService)
 {
     // this service is directly tied to DiagnosticAnalyzerService and
     // depends on its implementation.
     _analyzerService = analyzerService as DiagnosticAnalyzerService;
     Contract.ThrowIfNull(_analyzerService);
 }
コード例 #3
0
        public void TestGetFirstDiagnosticWithFixAsync()
        {
            var diagnosticService = new DiagnosticAnalyzerService(DiagnosticExtensions.GetCompilerDiagnosticAnalyzersMap());

            var fixers = CreateFixers();
            var fixService = new CodeFixService(
                    diagnosticService, fixers, SpecializedCollections.EmptyEnumerable<Lazy<ISuppressionFixProvider, CodeChangeProviderMetadata>>());

            var code = @"
    a
";

            using (var workspace =
                CSharpWorkspaceFactory.CreateWorkspaceFromFile(code))
            {
                var incrementalAnalzyer = (IIncrementalAnalyzerProvider)diagnosticService;

                // register diagnostic engine to solution crawler
                var analyzer = incrementalAnalzyer.CreateIncrementalAnalyzer(workspace);

                var reference = new MockAnalyzerReference();
                var project = workspace.CurrentSolution.Projects.Single().AddAnalyzerReference(reference);
                var document = project.Documents.Single();
                var unused = fixService.GetFirstDiagnosticWithFixAsync(document, TextSpan.FromBounds(0, 0), CancellationToken.None).Result;

                var fixer1 = fixers.Single().Value as MockFixer;
                var fixer2 = reference.Fixer as MockFixer;

                // check to make sure both of them are called.
                Assert.True(fixer1.Called);
                Assert.True(fixer2.Called);
            }
        }
コード例 #4
0
        private DiagnosticTaggerWrapper(TestWorkspace workspace, DiagnosticAnalyzerService analyzerService, IDiagnosticUpdateSource updateSource)
        {
            if (updateSource == null)
            {
                updateSource = analyzerService;
            }

            this.workspace = workspace;

            this.registrationService = workspace.Services.GetService<ISolutionCrawlerRegistrationService>();
            registrationService.Register(workspace);

            this.asyncListener = new AsynchronousOperationListener();
            var listeners = AsynchronousOperationListener.CreateListeners(
                ValueTuple.Create(FeatureAttribute.DiagnosticService, asyncListener),
                ValueTuple.Create(FeatureAttribute.ErrorSquiggles, asyncListener));

            this.analyzerService = analyzerService;
            var diagnosticService = new DiagnosticService(SpecializedCollections.SingletonEnumerable(updateSource), listeners);

            this.TaggerProvider = new DiagnosticsSquiggleTaggerProvider(
                workspace.Services.GetService<IOptionService>(), diagnosticService,
                workspace.GetService<IForegroundNotificationService>(), listeners);

            if (analyzerService != null)
            {
                this.incrementalAnalyzers = ImmutableArray.Create(analyzerService.CreateIncrementalAnalyzer(workspace));
                this.solutionCrawlerService = workspace.Services.GetService<ISolutionCrawlerRegistrationService>() as SolutionCrawlerRegistrationService;
            }
        }
コード例 #5
0
        private static bool CheckTelemetry(DiagnosticAnalyzerService service, DiagnosticAnalyzer analyzer)
        {
            if (DiagnosticAnalyzerDriver.IsCompilerAnalyzer(analyzer))
            {
                return(true);
            }

            ImmutableArray <DiagnosticDescriptor> diagDescriptors;

            try
            {
                // SupportedDiagnostics is potentially user code and can throw an exception.
                diagDescriptors = service != null?service.GetDiagnosticDescriptors(analyzer) : analyzer.SupportedDiagnostics;
            }
            catch (Exception)
            {
                return(false);
            }

            if (diagDescriptors == null)
            {
                return(false);
            }

            // find if the first diagnostic in this analyzer allows telemetry
            DiagnosticDescriptor diagnostic = diagDescriptors.Length > 0 ? diagDescriptors[0] : null;

            return(diagnostic == null ? false : diagnostic.CustomTags.Any(t => t == WellKnownDiagnosticTags.Telemetry));
        }
コード例 #6
0
 protected BaseDiagnosticIncrementalAnalyzer(DiagnosticAnalyzerService owner, Workspace workspace, HostAnalyzerManager hostAnalyzerManager, AbstractHostDiagnosticUpdateSource hostDiagnosticUpdateSource)
 {
     this.Owner                      = owner;
     this.Workspace                  = workspace;
     this.HostAnalyzerManager        = hostAnalyzerManager;
     this.HostDiagnosticUpdateSource = hostDiagnosticUpdateSource;
     this.DiagnosticLogAggregator    = new DiagnosticLogAggregator(owner);
 }
 protected BaseDiagnosticIncrementalAnalyzer(DiagnosticAnalyzerService owner, Workspace workspace, HostAnalyzerManager hostAnalyzerManager, AbstractHostDiagnosticUpdateSource hostDiagnosticUpdateSource)
 {
     this.Owner = owner;
     this.Workspace = workspace;
     this.HostAnalyzerManager = hostAnalyzerManager;
     this.HostDiagnosticUpdateSource = hostDiagnosticUpdateSource;
     this.DiagnosticLogAggregator = new DiagnosticLogAggregator(owner);
 }
            public IncrementalAnalyzerDelegatee(DiagnosticAnalyzerService owner, Workspace workspace, HostAnalyzerManager hostAnalyzerManager, AbstractHostDiagnosticUpdateSource hostDiagnosticUpdateSource)
                : base(owner, workspace, hostAnalyzerManager, hostDiagnosticUpdateSource)
            {
                var v1CorrelationId = LogAggregator.GetNextId();
                _engineV1 = new EngineV1.DiagnosticIncrementalAnalyzer(owner, v1CorrelationId, workspace, hostAnalyzerManager, hostDiagnosticUpdateSource);

                var v2CorrelationId = LogAggregator.GetNextId();
                _engineV2 = new EngineV2.DiagnosticIncrementalAnalyzer(owner, v2CorrelationId, workspace, hostAnalyzerManager, hostDiagnosticUpdateSource);
            }
コード例 #9
0
            public DiagnosticIncrementalAnalyzer(DiagnosticAnalyzerService owner, int correlationId, Workspace workspace, AnalyzerManager analyzerManager)
            {
                _owner = owner;
                _correlationId = correlationId;
                _memberRangeMap = new MemberRangeMap();
                _analyzersAndState = new DiagnosticAnalyzersAndStates(this, workspace, analyzerManager);
                _executor = new AnalyzerExecutor(this);

                _diagnosticLogAggregator = new DiagnosticLogAggregator(_owner);
            }
コード例 #10
0
        public static bool AllowsTelemetry(DiagnosticAnalyzerService service, DiagnosticAnalyzer analyzer)
        {
            StrongBox <bool> value;

            if (telemetryCache.TryGetValue(analyzer, out value))
            {
                return(value.Value);
            }

            return(telemetryCache.GetValue(analyzer, a => new StrongBox <bool>(CheckTelemetry(service, a))).Value);
        }
            public IncrementalAnalyzerDelegatee(DiagnosticAnalyzerService owner, Workspace workspace, AnalyzerManager analyzerManager)
            {
                _workspace = workspace;
                _analyzerManager = analyzerManager;
                _owner = owner;

                var v1CorrelationId = LogAggregator.GetNextId();
                _engineV1 = new EngineV1.DiagnosticIncrementalAnalyzer(_owner, v1CorrelationId, _workspace, _analyzerManager);

                var v2CorrelationId = LogAggregator.GetNextId();
                _engineV2 = new EngineV2.DiagnosticIncrementalAnalyzer(_owner, v2CorrelationId, _workspace, _analyzerManager);
            }
コード例 #12
0
            private static IEnumerable <DiagnosticAnalyzer> GetAnalyzers(DiagnosticAnalyzerService service, Project project)
            {
                // C# or VB document that supports compiler
                var compilerAnalyzer = service.GetCompilerDiagnosticAnalyzer(project.Language);

                if (compilerAnalyzer != null)
                {
                    return(SpecializedCollections.SingletonEnumerable(compilerAnalyzer));
                }

                // document that doesn't support compiler diagnostics such as FSharp or TypeScript
                return(service.GetDiagnosticAnalyzers(project));
            }
            public IncrementalAnalyzerDelegatee(DiagnosticAnalyzerService owner, Workspace workspace, AnalyzerManager analyzerManager)
            {
                _workspace       = workspace;
                _analyzerManager = analyzerManager;
                _owner           = owner;

                var v1CorrelationId = LogAggregator.GetNextId();

                _engineV1 = new EngineV1.DiagnosticIncrementalAnalyzer(_owner, v1CorrelationId, _workspace, _analyzerManager);

                var v2CorrelationId = LogAggregator.GetNextId();

                _engineV2 = new EngineV2.DiagnosticIncrementalAnalyzer(_owner, v2CorrelationId, _workspace, _analyzerManager);
            }
コード例 #14
0
            public IncrementalAnalyzerDelegatee(DiagnosticAnalyzerService owner, Workspace workspace, WorkspaceAnalyzerManager workspaceAnalyzerManager, AbstractHostDiagnosticUpdateSource hostDiagnosticUpdateSource)
                : base(workspace, hostDiagnosticUpdateSource)
            {
                _workspaceAnalyzerManager = workspaceAnalyzerManager;
                _owner = owner;

                var v1CorrelationId = LogAggregator.GetNextId();

                _engineV1 = new EngineV1.DiagnosticIncrementalAnalyzer(_owner, v1CorrelationId, workspace, _workspaceAnalyzerManager, hostDiagnosticUpdateSource);

                var v2CorrelationId = LogAggregator.GetNextId();

                _engineV2 = new EngineV2.DiagnosticIncrementalAnalyzer(_owner, v2CorrelationId, workspace, _workspaceAnalyzerManager, hostDiagnosticUpdateSource);
            }
コード例 #15
0
ファイル: AnalyzerHelper.cs プロジェクト: lovaya/roslyn
        public static bool ShouldRunForFullProject(this DiagnosticAnalyzerService service, DiagnosticAnalyzer analyzer, Project project)
        {
            var builtInAnalyzer = analyzer as IBuiltInAnalyzer;

            if (builtInAnalyzer != null)
            {
                return(!builtInAnalyzer.OpenFileOnly(project.Solution.Workspace));
            }

            if (analyzer.IsWorkspaceDiagnosticAnalyzer())
            {
                return(true);
            }

            // most of analyzers, number of descriptor is quite small, so this should be cheap.
            return(service.GetDiagnosticDescriptors(analyzer).Any(d => d.GetEffectiveSeverity(project.CompilationOptions) != ReportDiagnostic.Hidden));
        }
コード例 #16
0
        private bool CatchAnalyzerException(Exception e, DiagnosticAnalyzer analyzer, bool testOnly_DonotCatchAnalyzerExceptions)
        {
            DiagnosticAnalyzerLogger.LogAnalyzerCrashCount(analyzer, e, this.logAggregator);

            if (testOnly_DonotCatchAnalyzerExceptions)
            {
                return(false);
            }

            // TODO: move it to AnalyzerHelper later.
            if (!DiagnosticAnalyzerService.ShouldHandleAnalyzer(analyzer) || IsCompilerAnalyzer(analyzer))
            {
                return(FatalError.ReportWithoutCrashUnlessCanceled(e));
            }

            return(true);
        }
コード例 #17
0
        private static void GetTagSource(TestWorkspace workspace, DiagnosticServiceWaiter diagnosticWaiter, ErrorSquiggleWaiter squiggleWaiter, out Analyzer analyzer, out DiagnosticAnalyzerService analyzerService, out DiagnosticsSquiggleTaggerProvider.TagSource taggerSource)
        {
            analyzer = new Analyzer();
            var analyzerMap = new Dictionary<string, ImmutableArray<DiagnosticAnalyzer>>() { { LanguageNames.CSharp, ImmutableArray.Create<DiagnosticAnalyzer>(analyzer) } };
            analyzerService = new DiagnosticAnalyzerService(analyzerMap.ToImmutableDictionary());

            var diagnosticListeners = SpecializedCollections.SingletonEnumerable(new Lazy<IAsynchronousOperationListener, FeatureMetadata>(
                    () => diagnosticWaiter, new FeatureMetadata(new Dictionary<string, object>() { { "FeatureName", FeatureAttribute.DiagnosticService } })));

            var diagnosticService = new DiagnosticService(SpecializedCollections.SingletonEnumerable<IDiagnosticUpdateSource>(analyzerService), diagnosticListeners);

            var document = workspace.Documents.First();
            var buffer = document.GetTextBuffer();

            var foregroundService = new TestForegroundNotificationService();
            var optionsService = workspace.Services.GetService<IOptionService>();
            taggerSource = new DiagnosticsSquiggleTaggerProvider.TagSource(buffer, foregroundService, diagnosticService, optionsService, squiggleWaiter);
        }
コード例 #18
0
        private DiagnosticTaggerWrapper(
            TestWorkspace workspace,
            Dictionary<string, DiagnosticAnalyzer[]> analyzerMap,
            IDiagnosticUpdateSource updateSource,
            bool createTaggerProvider)
        {
            _asyncListener = new AsynchronousOperationListener();
            _listeners = AsynchronousOperationListener.CreateListeners(
                ValueTuple.Create(FeatureAttribute.DiagnosticService, _asyncListener),
                ValueTuple.Create(FeatureAttribute.ErrorSquiggles, _asyncListener));

            if (analyzerMap != null || updateSource == null)
            {
                AnalyzerService = CreateDiagnosticAnalyzerService(analyzerMap, _asyncListener);
            }

            if (updateSource == null)
            {
                updateSource = AnalyzerService;
            }

            _workspace = workspace;

            _registrationService = workspace.Services.GetService<ISolutionCrawlerRegistrationService>();
            _registrationService.Register(workspace);

            DiagnosticService = new DiagnosticService(_listeners);
            DiagnosticService.Register(updateSource);

            if (createTaggerProvider)
            {
                var taggerProvider = this.TaggerProvider;
            }

            if (AnalyzerService != null)
            {
                _incrementalAnalyzers = ImmutableArray.Create(AnalyzerService.CreateIncrementalAnalyzer(workspace));
                _solutionCrawlerService = workspace.Services.GetService<ISolutionCrawlerRegistrationService>() as SolutionCrawlerRegistrationService;
            }
        }
コード例 #19
0
        protected static IEnumerable<ITagSpan<IErrorTag>> GetErrorSpans(TestWorkspace workspace)
        {
            var registrationService = workspace.Services.GetService<IWorkCoordinatorRegistrationService>();
            registrationService.Register(workspace);

            var diagnosticWaiter = new DiagnosticServiceWaiter();
            var diagnosticListeners = SpecializedCollections.SingletonEnumerable(new Lazy<IAsynchronousOperationListener, FeatureMetadata>(
                () => diagnosticWaiter, new FeatureMetadata(new Dictionary<string, object>() { { "FeatureName", FeatureAttribute.DiagnosticService } })));

            var optionsService = workspace.Services.GetService<IOptionService>();
            var compilerAnalyzersMap = DiagnosticExtensions.GetCompilerDiagnosticAnalyzersMap();
            var analyzerService = new DiagnosticAnalyzerService(compilerAnalyzersMap);
            var diagnosticService = new DiagnosticService(SpecializedCollections.SingletonEnumerable<IDiagnosticUpdateSource>(analyzerService), diagnosticListeners);

            var document = workspace.Documents.First();
            var buffer = document.GetTextBuffer();

            var squiggleWaiter = new ErrorSquiggleWaiter();
            var foregroundService = new TestForegroundNotificationService();
            var taggerSource = new DiagnosticsSquiggleTaggerProvider.TagSource(buffer, foregroundService, diagnosticService, optionsService, squiggleWaiter);

            var solutionWorkCoordinator = workspace.Services.GetService<IWorkCoordinatorRegistrationService>() as WorkCoordinatorRegistrationService;
            solutionWorkCoordinator.WaitUntilCompletion_ForTestingPurposesOnly(workspace, ImmutableArray.Create(analyzerService.CreateIncrementalAnalyzer(workspace)));

            diagnosticWaiter.CreateWaitTask().PumpingWait();
            squiggleWaiter.CreateWaitTask().PumpingWait();

            var snapshot = buffer.CurrentSnapshot;
            var intervalTree = taggerSource.GetTagIntervalTreeForBuffer(buffer);
            var spans = intervalTree.GetIntersectingSpans(new SnapshotSpan(snapshot, 0, snapshot.Length)).ToImmutableArray();

            taggerSource.TestOnly_Dispose();

            registrationService.Unregister(workspace);

            return spans;
        }
コード例 #20
0
        private DiagnosticTaggerWrapper(
            TestWorkspace workspace,
            DiagnosticAnalyzerService analyzerService,
            IDiagnosticUpdateSource updateSource,
            bool createTaggerProvider)
        {
            if (updateSource == null)
            {
                updateSource = analyzerService;
            }

            this.workspace = workspace;

            this.registrationService = workspace.Services.GetService<ISolutionCrawlerRegistrationService>();
            registrationService.Register(workspace);

            this.asyncListener = new AsynchronousOperationListener();
            this.listeners = AsynchronousOperationListener.CreateListeners(
                ValueTuple.Create(FeatureAttribute.DiagnosticService, asyncListener),
                ValueTuple.Create(FeatureAttribute.ErrorSquiggles, asyncListener));

            this.analyzerService = analyzerService;
            this.diagnosticService = new DiagnosticService(listeners);
            diagnosticService.Register(updateSource);

            if (createTaggerProvider)
            {
                var taggerProvider = this.TaggerProvider;
            }

            if (analyzerService != null)
            {
                this.incrementalAnalyzers = ImmutableArray.Create(analyzerService.CreateIncrementalAnalyzer(workspace));
                this.solutionCrawlerService = workspace.Services.GetService<ISolutionCrawlerRegistrationService>() as SolutionCrawlerRegistrationService;
            }
        }
コード例 #21
0
 public override Task SynchronizeWithBuildAsync(DiagnosticAnalyzerService.BatchUpdateToken token, Document document, ImmutableArray<DiagnosticData> diagnostics)
 {
     return Analyzer.SynchronizeWithBuildAsync(token, document, diagnostics);
 }
コード例 #22
0
        public static bool AllowsTelemetry(DiagnosticAnalyzerService service, DiagnosticAnalyzer analyzer)
        {
            StrongBox<bool> value;
            if (s_telemetryCache.TryGetValue(analyzer, out value))
            {
                return value.Value;
            }

            return s_telemetryCache.GetValue(analyzer, a => new StrongBox<bool>(CheckTelemetry(service, a))).Value;
        }
コード例 #23
0
        private static bool CheckTelemetry(DiagnosticAnalyzerService service, DiagnosticAnalyzer analyzer)
        {
            if (AnalyzerHelper.IsCompilerAnalyzer(analyzer))
            {
                return true;
            }

            ImmutableArray<DiagnosticDescriptor> diagDescriptors;
            try
            {
                // SupportedDiagnostics is potentially user code and can throw an exception.
                diagDescriptors = service != null ? service.GetDiagnosticDescriptors(analyzer) : analyzer.SupportedDiagnostics;
            }
            catch (Exception)
            {
                return false;
            }

            if (diagDescriptors == null)
            {
                return false;
            }

            // find if the first diagnostic in this analyzer allows telemetry
            DiagnosticDescriptor diagnostic = diagDescriptors.Length > 0 ? diagDescriptors[0] : null;
            return diagnostic == null ? false : diagnostic.CustomTags.Any(t => t == WellKnownDiagnosticTags.Telemetry);
        }
コード例 #24
0
 public DiagnosticLogAggregator(DiagnosticAnalyzerService owner)
 {
     _owner = owner;
     _analyzerInfoMap = ImmutableDictionary<Type, AnalyzerInfo>.Empty;
 }
コード例 #25
0
 /// <summary>
 /// Callback from build listener.
 /// 
 /// Given diagnostics are errors host got from explicit build.
 /// It is up to each incremental analyzer how they will merge this information with live diagnostic info
 /// 
 /// this API doesn't have cancellationToken since it can't be cancelled.
 /// 
 /// given diagnostics are ones that has a source location.
 /// </summary>
 public abstract Task SynchronizeWithBuildAsync(DiagnosticAnalyzerService.BatchUpdateToken token, Document document, ImmutableArray<DiagnosticData> diagnostics);
コード例 #26
0
 public static bool HasNonHiddenDescriptor(this DiagnosticAnalyzerService service, DiagnosticAnalyzer analyzer, Project project)
 {
     // most of analyzers, number of descriptor is quite small, so this should be cheap.
     return(service.GetDiagnosticDescriptors(analyzer).Any(d => d.GetEffectiveSeverity(project.CompilationOptions) != ReportDiagnostic.Hidden));
 }