コード例 #1
0
        public override async Task <ImmutableArray <Diagnostic> > AnalyzeSemanticsAsync(Document document, CancellationToken cancellationToken)
        {
            try
            {
                var encService = document.Project.Solution.Workspace.Services.GetService <IDebuggingWorkspaceService>()?.EditAndContinueServiceOpt;
                if (encService == null)
                {
                    return(ImmutableArray <Diagnostic> .Empty);
                }

                EditSession session = encService.EditSession;
                if (session == null ||
                    session.BaseSolution.WorkspaceVersion == document.Project.Solution.WorkspaceVersion ||
                    !session.HasProject(document.Project.Id))
                {
                    return(ImmutableArray <Diagnostic> .Empty);
                }

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

                var analysis = await session.GetDocumentAnalysis(document).GetValueAsync(cancellationToken).ConfigureAwait(false);

                if (analysis.RudeEditErrors.IsDefault)
                {
                    return(ImmutableArray <Diagnostic> .Empty);
                }

                session.LogRudeEditErrors(analysis.RudeEditErrors);
                return(analysis.RudeEditErrors.SelectAsArray((e, t) => e.ToDiagnostic(t), tree));
            }
            catch (Exception e) when(FatalError.ReportUnlessCanceled(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
コード例 #2
0
        public override async Task AnalyzeSemanticsAsync(Document document, Action <Diagnostic> addDiagnostic, CancellationToken cancellationToken)
        {
            try
            {
                var encService = document.Project.Solution.Workspace.Services.GetService <IEditAndContinueWorkspaceService>();
                if (encService == null)
                {
                    return;
                }

                EditSession session = encService.EditSession;
                if (session == null || !session.HasProject(document.Project.Id))
                {
                    return;
                }

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

                var analysis = await session.GetDocumentAnalysis(document).GetValueAsync(cancellationToken).ConfigureAwait(false);

                if (!analysis.RudeEditErrors.IsDefault)
                {
                    session.LogRudeEditErrors(analysis.RudeEditErrors);

                    foreach (var error in analysis.RudeEditErrors)
                    {
                        addDiagnostic(error.ToDiagnostic(tree));
                    }
                }
            }
            catch (Exception e) when(FatalError.ReportUnlessCanceled(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }