/// <summary>
        /// Calculate dignostics. this works differently than other ones such as todo comments or designer attribute scanner
        /// since in proc and out of proc runs quite differently due to concurrency and due to possible amount of data
        /// that needs to pass through between processes
        /// </summary>
        public Task CalculateDiagnosticsAsync(DiagnosticArguments arguments, string pipeName, CancellationToken cancellationToken)
        {
            return(RunServiceAsync(async() =>
            {
                // if this analysis is explicitly asked by user, boost priority of this request
                using (RoslynLogger.LogBlock(FunctionId.CodeAnalysisService_CalculateDiagnosticsAsync, arguments.ProjectId.DebugName, cancellationToken))
                    using (arguments.ForcedAnalysis ? UserOperationBooster.Boost() : default)
                    {
                        // entry point for diagnostic service
                        var solution = await GetSolutionAsync(cancellationToken).ConfigureAwait(false);

                        var projectId = arguments.ProjectId;
                        var analyzers = RoslynServices.AssetService.GetGlobalAssetsOfType <AnalyzerReference>(cancellationToken);

                        var result = await new DiagnosticComputer(solution.GetProject(projectId)).GetDiagnosticsAsync(
                            analyzers, arguments.AnalyzerIds, arguments.ReportSuppressedDiagnostics, arguments.LogAnalyzerExecutionTime, cancellationToken).ConfigureAwait(false);

                        await RemoteEndPoint.WriteDataToNamedPipeAsync(pipeName, result, (writer, data, cancellationToken) =>
                        {
                            var(diagnostics, telemetry, exceptions) = DiagnosticResultSerializer.WriteDiagnosticAnalysisResults(writer, data, cancellationToken);

                            // save log for debugging
                            Log(TraceEventType.Information, $"diagnostics: {diagnostics}, telemetry: {telemetry}, exceptions: {exceptions}");

                            return Task.CompletedTask;
                        }, cancellationToken).ConfigureAwait(false);
                    }
            }, cancellationToken));
        }
Exemple #2
0
        /// <summary>
        /// Calculate dignostics. this works differently than other ones such as todo comments or designer attribute scanner
        /// since in proc and out of proc runs quite differently due to concurrency and due to possible amount of data
        /// that needs to pass through between processes
        /// </summary>
        public Task CalculateDiagnosticsAsync(PinnedSolutionInfo solutionInfo, DiagnosticArguments arguments, string pipeName, CancellationToken cancellationToken)
        {
            return(RunServiceAsync(async() =>
            {
                using (RoslynLogger.LogBlock(FunctionId.CodeAnalysisService_CalculateDiagnosticsAsync, arguments.ProjectId.DebugName, cancellationToken))
                    using (arguments.IsHighPriority ? UserOperationBooster.Boost() : default)
                    {
                        var solution = await GetSolutionAsync(solutionInfo, cancellationToken).ConfigureAwait(false);

                        var documentId = arguments.DocumentId;
                        var projectId = arguments.ProjectId;
                        var project = solution.GetProject(projectId);
                        var documentSpan = arguments.DocumentSpan;
                        var documentAnalysisKind = arguments.DocumentAnalysisKind;
                        var diagnosticComputer = new DiagnosticComputer(documentId, project, documentSpan, documentAnalysisKind, _analyzerInfoCache);

                        var result = await diagnosticComputer.GetDiagnosticsAsync(
                            arguments.AnalyzerIds,
                            reportSuppressedDiagnostics: arguments.ReportSuppressedDiagnostics,
                            logPerformanceInfo: arguments.LogPerformanceInfo,
                            getTelemetryInfo: arguments.GetTelemetryInfo,
                            cancellationToken).ConfigureAwait(false);

                        await RemoteEndPoint.WriteDataToNamedPipeAsync(pipeName, (result, documentAnalysisKind), (writer, data, cancellationToken) =>
                        {
                            var(diagnostics, telemetry) = DiagnosticResultSerializer.WriteDiagnosticAnalysisResults(writer, data.documentAnalysisKind, data.result, cancellationToken);

                            // save log for debugging
                            Log(TraceEventType.Information, $"diagnostics: {diagnostics}, telemetry: {telemetry}");

                            return Task.CompletedTask;
                        }, cancellationToken).ConfigureAwait(false);
                    }
            }, cancellationToken));
        }
        private async Task <DiagnosticAnalysisResultMap <DiagnosticAnalyzer, DiagnosticAnalysisResult> > GetCompilerAnalysisResultAsync(Stream stream, Dictionary <string, DiagnosticAnalyzer> analyzerMap, Project project, CancellationToken cancellationToken)
        {
            // handling of cancellation and exception
            var version = await DiagnosticIncrementalAnalyzer.GetDiagnosticVersionAsync(project, cancellationToken).ConfigureAwait(false);

            using (var reader = new ObjectReader(stream))
            {
                return(DiagnosticResultSerializer.Deserialize(reader, analyzerMap, project, version, cancellationToken));
            }
        }
            private async Task <DiagnosticAnalysisResultMap <DiagnosticAnalyzer, DiagnosticAnalysisResult> > GetCompilerAnalysisResultAsync(Stream stream, Dictionary <string, DiagnosticAnalyzer> analyzerMap, Project project, CancellationToken cancellationToken)
            {
                // handling of cancellation and exception
                var version = await DiagnosticIncrementalAnalyzer.GetDiagnosticVersionAsync(project, cancellationToken).ConfigureAwait(false);

                using var reader = ObjectReader.TryGetReader(stream);
                Debug.Assert(reader != null,
                             @"We only ge a reader for data transmitted between live processes.
This data should always be correct as we're never persisting the data between sessions.");
                return(DiagnosticResultSerializer.Deserialize(reader, analyzerMap, project, version, cancellationToken));
            }
        private async Task SerializeDiagnosticResultAsync(string streamName, DiagnosticAnalysisResultMap <string, DiagnosticAnalysisResultBuilder> result)
        {
            using (var stream = await DirectStream.GetAsync(streamName, CancellationToken).ConfigureAwait(false))
            {
                using (var writer = new ObjectWriter(stream))
                {
                    DiagnosticResultSerializer.Serialize(writer, result, CancellationToken);
                }

                await stream.FlushAsync(CancellationToken).ConfigureAwait(false);
            }
        }
            private async Task <DiagnosticAnalysisResultMap <DiagnosticAnalyzer, DiagnosticAnalysisResult> > ReadCompilerAnalysisResultAsync(Stream stream, Dictionary <string, DiagnosticAnalyzer> analyzerMap, Project project, CancellationToken cancellationToken)
            {
                // handling of cancellation and exception
                var version = await GetDiagnosticVersionAsync(project, cancellationToken).ConfigureAwait(false);

                using var reader = ObjectReader.TryGetReader(stream, leaveOpen: true, cancellationToken);

                // We only get a reader for data transmitted between live processes.
                // This data should always be correct as we're never persisting the data between sessions.
                Contract.ThrowIfNull(reader);

                return(DiagnosticResultSerializer.ReadDiagnosticAnalysisResults(reader, analyzerMap, project, version, cancellationToken));
            }
Exemple #7
0
        private async Task SerializeDiagnosticResultAsync(string streamName, DiagnosticAnalysisResultMap <string, DiagnosticAnalysisResultBuilder> result)
        {
            using (RoslynLogger.LogBlock(FunctionId.CodeAnalysisService_SerializeDiagnosticResultAsync, GetResultLogInfo, result, CancellationToken))
                using (var stream = await DirectStream.GetAsync(streamName, CancellationToken).ConfigureAwait(false))
                {
                    using (var writer = new StreamObjectWriter(stream))
                    {
                        DiagnosticResultSerializer.Serialize(writer, result, CancellationToken);
                    }

                    await stream.FlushAsync(CancellationToken).ConfigureAwait(false);
                }
        }
Exemple #8
0
        private async Task SerializeDiagnosticResultAsync(string streamName, DiagnosticAnalysisResultMap <string, DiagnosticAnalysisResultBuilder> result, CancellationToken cancellationToken)
        {
            using (RoslynLogger.LogBlock(FunctionId.CodeAnalysisService_SerializeDiagnosticResultAsync, GetResultLogInfo, result, cancellationToken))
                using (var stream = await DirectStream.GetAsync(streamName, cancellationToken).ConfigureAwait(false))
                {
                    using (var writer = new ObjectWriter(stream))
                    {
                        var info = DiagnosticResultSerializer.Serialize(writer, result, cancellationToken);

                        // save log for debugging
                        Log(TraceEventType.Information, $"diagnostics: {info.diagnostics}, telemetry: {info.telemetry}, exceptions: {info.exceptions}");
                    }

                    await stream.FlushAsync(cancellationToken).ConfigureAwait(false);
                }
        }