コード例 #1
0
        public void ReportApplyChangesException(string message)
        {
            var descriptor = EditAndContinueDiagnosticDescriptors.GetDescriptor(EditAndContinueErrorCode.CannotApplyChangesUnexpectedError);

            _emitDiagnosticsUpdateSource.ReportDiagnostics(
                _workspace.CurrentSolution,
                projectId: null,
                new[] { Diagnostic.Create(descriptor, Location.None, new[] { message }) });
        }
コード例 #2
0
        private ImmutableArray <Diagnostic> GetRunModeDocumentDiagnostics(Document newDocument, SyntaxTree newSyntaxTree, IEnumerable <TextSpan> changedSpans)
        {
            if (!changedSpans.Any())
            {
                return(ImmutableArray <Diagnostic> .Empty);
            }

            lock (_documentsWithReportedDiagnosticsDuringRunModeGuard)
            {
                _documentsWithReportedDiagnosticsDuringRunMode.Add(newDocument.Id);
            }

            var descriptor = EditAndContinueDiagnosticDescriptors.GetDescriptor(EditAndContinueErrorCode.ChangesNotAppliedWhileRunning);
            var args       = new[] { newDocument.Project.Name };

            return(changedSpans.SelectAsArray(span => Diagnostic.Create(descriptor, Location.Create(newSyntaxTree, span), args)));
        }
コード例 #3
0
                                    DiagnosticData?syntaxError)> EmitSolutionUpdateAsync(
            Solution solution,
            ActiveStatementSpanProvider activeStatementSpanProvider,
            IDiagnosticAnalyzerService diagnosticService,
            EditAndContinueDiagnosticUpdateSource diagnosticUpdateSource,
            CancellationToken cancellationToken)
        {
            ManagedModuleUpdates            moduleUpdates;
            ImmutableArray <DiagnosticData> diagnosticData;
            ImmutableArray <(DocumentId DocumentId, ImmutableArray <RudeEditDiagnostic> Diagnostics)> rudeEdits;
            DiagnosticData?syntaxError;

            try
            {
                var client = await RemoteHostClient.TryGetClientAsync(_workspace, cancellationToken).ConfigureAwait(false);

                if (client == null)
                {
                    var results = await GetLocalService().EmitSolutionUpdateAsync(_sessionId, solution, activeStatementSpanProvider, cancellationToken).ConfigureAwait(false);

                    moduleUpdates  = results.ModuleUpdates;
                    diagnosticData = results.GetDiagnosticData(solution);
                    rudeEdits      = results.RudeEdits;
                    syntaxError    = results.GetSyntaxErrorData(solution);
                }
                else
                {
                    var result = await client.TryInvokeAsync <IRemoteEditAndContinueService, EmitSolutionUpdateResults.Data>(
                        solution,
                        (service, solutionInfo, callbackId, cancellationToken) => service.EmitSolutionUpdateAsync(solutionInfo, callbackId, _sessionId, cancellationToken),
                        callbackTarget : new ActiveStatementSpanProviderCallback(activeStatementSpanProvider),
                        cancellationToken).ConfigureAwait(false);

                    if (result.HasValue)
                    {
                        moduleUpdates  = result.Value.ModuleUpdates;
                        diagnosticData = result.Value.Diagnostics;
                        rudeEdits      = result.Value.RudeEdits;
                        syntaxError    = result.Value.SyntaxError;
                    }
                    else
                    {
                        moduleUpdates  = new ManagedModuleUpdates(ManagedModuleUpdateStatus.RestartRequired, ImmutableArray <ManagedModuleUpdate> .Empty);
                        diagnosticData = ImmutableArray <DiagnosticData> .Empty;
                        rudeEdits      = ImmutableArray <(DocumentId DocumentId, ImmutableArray <RudeEditDiagnostic> Diagnostics)> .Empty;
                        syntaxError    = null;
                    }
                }
            }
            catch (Exception e) when(FatalError.ReportAndCatchUnlessCanceled(e, cancellationToken))
            {
                var descriptor = EditAndContinueDiagnosticDescriptors.GetDescriptor(RudeEditKind.InternalError);

                var diagnostic = Diagnostic.Create(
                    descriptor,
                    Location.None,
                    string.Format(descriptor.MessageFormat.ToString(), "", e.Message));

                diagnosticData = ImmutableArray.Create(DiagnosticData.Create(diagnostic, project: null));
                rudeEdits      = ImmutableArray <(DocumentId DocumentId, ImmutableArray <RudeEditDiagnostic> Diagnostics)> .Empty;
                moduleUpdates  = new ManagedModuleUpdates(ManagedModuleUpdateStatus.RestartRequired, ImmutableArray <ManagedModuleUpdate> .Empty);
                syntaxError    = null;
            }

            // clear emit/apply diagnostics reported previously:
            diagnosticUpdateSource.ClearDiagnostics(isSessionEnding: false);

            // clear all reported rude edits:
            diagnosticService.Reanalyze(_workspace, documentIds: rudeEdits.Select(d => d.DocumentId));

            // report emit/apply diagnostics:
            diagnosticUpdateSource.ReportDiagnostics(_workspace, solution, diagnosticData, rudeEdits);

            return(moduleUpdates, diagnosticData, rudeEdits, syntaxError);
        }
コード例 #4
0
ファイル: RudeEditDiagnostic.cs プロジェクト: zuvys/roslyn
        internal Diagnostic ToDiagnostic(SyntaxTree tree)
        {
            var descriptor = EditAndContinueDiagnosticDescriptors.GetDescriptor(Kind);

            return(Diagnostic.Create(descriptor, tree.GetLocation(Span), Arguments));
        }