public async Task AnalyzeSyntaxAsync(Document document, CancellationToken cancellationToken)
            {
                // if closed file diagnostic is off and document is not opened, then don't do anything
                if (!_workspace.Options.GetOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, document.Project.Language) && !document.IsOpen())
                {
                    return;
                }

                var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
                var diagnostics = tree.GetDiagnostics(cancellationToken);

                Contract.Requires(document.Project.Solution.Workspace == _workspace);

                var diagnosticData = diagnostics == null ? ImmutableArray<DiagnosticData>.Empty : diagnostics.Select(d => DiagnosticData.Create(document, d)).ToImmutableArrayOrEmpty();
                _service.RaiseDiagnosticsUpdated(new DiagnosticsUpdatedArgs(ValueTuple.Create(this, document.Id), _workspace, document.Project.Solution, document.Project.Id, document.Id, diagnosticData));
            }
            public Task DocumentResetAsync(Document document, CancellationToken cancellationToken)
            {
                // no closed file diagnostic and file is not opened, remove any existing diagnostics
                if (!_workspace.Options.GetOption(ServiceFeatureOnOffOptions.ClosedFileDiagnostic, document.Project.Language) && !document.IsOpen())
                {
                    RaiseEmptyDiagnosticUpdated(document.Id);
                }

                return SpecializedTasks.EmptyTask;
            }
            public async Task AnalyzeDocumentAsync(Document document, SyntaxNode bodyOpt, CancellationToken cancellationToken)
            {
                try
                {
                    // do nothing if this document is not currently open.
                    // to prevent perf from getting too poor for large projects, only examine open documents.
                    if (!document.IsOpen())
                    {
                        return;
                    }

                    // Only analyzing C# for now
                    if (document.Project.Language != LanguageNames.CSharp)
                    {
                        return;
                    }

                    List<CompilationErrorDetails> errorDetails = await _errorDetailDiscoverer.GetCompilationErrorDetails(document, bodyOpt, cancellationToken).ConfigureAwait(false);

                    var errorsToReport = _errorDetailCache.GetErrorsToReportAndRecordErrors(document.Id, errorDetails);
                    if (errorsToReport != null)
                    {
                        using (var hashProvider = new SHA256CryptoServiceProvider())
                        {
                            foreach (CompilationErrorDetails errorDetail in errorsToReport)
                            {
                                var telemetryEvent = TelemetryHelper.TelemetryService.CreateEvent(TelemetryEventPath);
                                telemetryEvent.SetStringProperty(TelemetryErrorId, errorDetail.ErrorId);

                                string projectGuid = _projectGuidCache.GetProjectGuidFromProjectPath(document.Project.FilePath);
                                telemetryEvent.SetStringProperty(TelemetryProjectGuid, string.IsNullOrEmpty(projectGuid) ? UnspecifiedProjectGuid : projectGuid.ToString());

                                if (!string.IsNullOrEmpty(errorDetail.UnresolvedMemberName))
                                {
                                    telemetryEvent.SetStringProperty(TelemetryUnresolvedMemberName, GetHashedString(errorDetail.UnresolvedMemberName, hashProvider));
                                }

                                if (!string.IsNullOrEmpty(errorDetail.LeftExpressionDocId))
                                {
                                    telemetryEvent.SetStringProperty(TelemetryLeftExpressionDocId, GetHashedString(errorDetail.LeftExpressionDocId, hashProvider));
                                }

                                if (!IsArrayNullOrEmpty(errorDetail.LeftExpressionBaseTypeDocIds))
                                {
                                    string telemetryBaseTypes = string.Join(";", errorDetail.LeftExpressionBaseTypeDocIds.Select(docId => GetHashedString(docId, hashProvider)));
                                    telemetryEvent.SetStringProperty(TelemetryBaseTypes, telemetryBaseTypes);
                                }

                                if (!IsArrayNullOrEmpty(errorDetail.GenericArguments))
                                {
                                    string telemetryGenericArguments = string.Join(";", errorDetail.GenericArguments.Select(docId => GetHashedString(docId, hashProvider)));
                                    telemetryEvent.SetStringProperty(TelemetryGenericArguments, telemetryGenericArguments);
                                }

                                if (!string.IsNullOrEmpty(errorDetail.MethodName))
                                {
                                    telemetryEvent.SetStringProperty(TelemetryMethodName, GetHashedString(errorDetail.MethodName, hashProvider));
                                }

                                if (!IsArrayNullOrEmpty(errorDetail.ArgumentTypes))
                                {
                                    string telemetryMisMatchedArgumentTypeDocIds = string.Join(";", errorDetail.ArgumentTypes.Select(docId => GetHashedString(docId, hashProvider)));
                                    telemetryEvent.SetStringProperty(TelemetryMismatchedArgumentTypeDocIds, telemetryMisMatchedArgumentTypeDocIds);
                                }

                                TelemetryHelper.DefaultTelemetrySession.PostEvent(telemetryEvent);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    // The telemetry service itself can throw.
                    // So, to be very careful, put this in a try/catch too.
                    try
                    {
                        var exceptionEvent = TelemetryHelper.TelemetryService.CreateEvent(TelemetryExceptionEventPath);
                        exceptionEvent.SetStringProperty("Type", e.GetTypeDisplayName());
                        exceptionEvent.SetStringProperty("Message", e.Message);
                        exceptionEvent.SetStringProperty("StackTrace", e.StackTrace);
                        TelemetryHelper.DefaultTelemetrySession.PostEvent(exceptionEvent);
                    }
                    catch
                    {
                    }
                }
            }