Пример #1
0
        private ImmutableArray <DiagnosticBucket> GetDiagnosticBuckets(
            Workspace workspace,
            ProjectId projectId,
            DocumentId documentId,
            bool forPullDiagnostics,
            DiagnosticMode diagnosticMode,
            CancellationToken cancellationToken)
        {
            // If this is a pull client, but pull diagnostics is not on, then they get nothing.  Similarly, if this is a
            // push client and pull diagnostics are on, they get nothing.
            if (forPullDiagnostics != (diagnosticMode == DiagnosticMode.Pull))
            {
                return(ImmutableArray <DiagnosticBucket> .Empty);
            }

            using var _1 = ArrayBuilder <DiagnosticBucket> .GetInstance(out var result);

            using var _2 = ArrayBuilder <Data> .GetInstance(out var buffer);

            foreach (var source in _updateSources)
            {
                buffer.Clear();
                cancellationToken.ThrowIfCancellationRequested();

                AppendMatchingData(source, workspace, projectId, documentId, id: null, buffer);
                foreach (var data in buffer)
                {
                    result.Add(new DiagnosticBucket(data.Id, data.Workspace, data.ProjectId, data.DocumentId));
                }
            }

            return(result.ToImmutable());
        }
Пример #2
0
        private ValueTask <ImmutableArray <DiagnosticData> > GetDiagnosticsAsync(
            Workspace workspace,
            ProjectId projectId,
            DocumentId documentId,
            object id,
            bool includeSuppressedDiagnostics,
            bool forPullDiagnostics,
            DiagnosticMode diagnosticMode,
            CancellationToken cancellationToken)
        {
            // If this is a pull client, but pull diagnostics is not on, then they get nothing.  Similarly, if this is a
            // push client and pull diagnostics are on, they get nothing.
            if (forPullDiagnostics != (diagnosticMode == DiagnosticMode.Pull))
            {
                return(new ValueTask <ImmutableArray <DiagnosticData> >(ImmutableArray <DiagnosticData> .Empty));
            }

            if (id != null)
            {
                // get specific one
                return(GetSpecificDiagnosticsAsync(workspace, projectId, documentId, id, includeSuppressedDiagnostics, cancellationToken));
            }

            // get aggregated ones
            return(GetDiagnosticsAsync(workspace, projectId, documentId, includeSuppressedDiagnostics, cancellationToken));
        }
        public static async ValueTask <ImmutableArray <DiagnosticData> > GetDiagnosticsAsync(
            this IDiagnosticService service,
            Workspace workspace,
            Project?project,
            Document?document,
            bool includeSuppressedDiagnostics,
            bool forPullDiagnostics,
            DiagnosticMode diagnosticMode,
            CancellationToken cancellationToken)
        {
            Contract.ThrowIfTrue(document != null && document.Project != project);
            Contract.ThrowIfTrue(project != null && project.Solution.Workspace != workspace);

            using var _ = ArrayBuilder <DiagnosticData> .GetInstance(out var result);

            var buckets = forPullDiagnostics
                ? service.GetPullDiagnosticBuckets(workspace, project?.Id, document?.Id, diagnosticMode, cancellationToken)
                : service.GetPushDiagnosticBuckets(workspace, project?.Id, document?.Id, diagnosticMode, cancellationToken);

            foreach (var bucket in buckets)
            {
                Contract.ThrowIfFalse(workspace.Equals(bucket.Workspace));
                Contract.ThrowIfFalse(document?.Id == bucket.DocumentId);

                var diagnostics = forPullDiagnostics
                    ? await service.GetPullDiagnosticsAsync(bucket, includeSuppressedDiagnostics, diagnosticMode, cancellationToken).ConfigureAwait(false)
                    : await service.GetPushDiagnosticsAsync(bucket, includeSuppressedDiagnostics, diagnosticMode, cancellationToken).ConfigureAwait(false);

                result.AddRange(diagnostics);
            }

            return(result.ToImmutable());
        }
Пример #4
0
        public string GenerateOutput(HttpContext context, Config c)
        {
            StringBuilder sb = new StringBuilder();

            //Figure out CustomErrorsMode
            System.Configuration.Configuration configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);
            CustomErrorsSection section = (configuration != null) ? section = (CustomErrorsSection)configuration.GetSection("system.web/customErrors") : null;
            CustomErrorsMode    mode    = (section != null) ? section.Mode : CustomErrorsMode.RemoteOnly;
            //What is diagnostics enableFor set to?
            DiagnosticMode dmode = c.get <DiagnosticMode>("diagnostics.enableFor", DiagnosticMode.None);
            //Is it set all all?
            bool diagDefined = (c.get("diagnostics.enableFor", null) != null);
            //Is it available from localhost.
            bool availLocally = (!diagDefined && mode == CustomErrorsMode.RemoteOnly) || (dmode == DiagnosticMode.Localhost);

            sb.AppendLine("The Resizer diagnostics page is " + (availLocally ? "only available from localhost." : "disabled."));
            sb.AppendLine();
            if (diagDefined)
            {
                sb.AppendLine("This is because <diagnostics enableFor=\"" + dmode.ToString() + "\" />.");
            }
            else
            {
                sb.AppendLine("This is because <customErrors mode=\"" + mode.ToString() + "\" />.");
            }
            sb.AppendLine();
            sb.AppendLine("To override for localhost access, add <diagnostics enableFor=\"localhost\" /> in the <resizer> section of Web.config.");
            sb.AppendLine();
            sb.AppendLine("To ovveride for remote access, add <diagnostics enableFor=\"allhosts\" /> in the <resizer> section of Web.config.");
            sb.AppendLine();
            return(sb.ToString());
        }
Пример #5
0
 protected override Task <ImmutableArray <DiagnosticData> > GetDiagnosticsAsync(
     RequestContext context, Document document, DiagnosticMode diagnosticMode, CancellationToken cancellationToken)
 {
     // For closed files, go to the IDiagnosticService for results.  These won't necessarily be totally up to
     // date.  However, that's fine as these are closed files and won't be in the process of being edited.  So
     // any deviations in the spans of diagnostics shouldn't be impactful for the user.
     return(DiagnosticService.GetPullDiagnosticsAsync(document, includeSuppressedDiagnostics: false, diagnosticMode, cancellationToken).AsTask());
 }
 static bool?GetCheckboxValueForDiagnosticMode(DiagnosticMode mode)
 {
     return(mode switch
     {
         DiagnosticMode.Push => false,
         DiagnosticMode.Pull => true,
         DiagnosticMode.Default => null,
         _ => throw new System.ArgumentException("unknown diagnostic mode"),
     });
 public static ValueTask <ImmutableArray <DiagnosticData> > GetPullDiagnosticsAsync(
     this IDiagnosticService service,
     Document document,
     bool includeSuppressedDiagnostics,
     DiagnosticMode diagnosticMode,
     CancellationToken cancellationToken)
 {
     return(GetDiagnosticsAsync(service, document.Project.Solution.Workspace, document.Project, document, includeSuppressedDiagnostics, forPullDiagnostics: true, diagnosticMode, cancellationToken));
 }
Пример #8
0
 protected override Task <ImmutableArray <DiagnosticData> > GetDiagnosticsAsync(
     RequestContext context, Document document, DiagnosticMode diagnosticMode, CancellationToken cancellationToken)
 {
     // For open documents, directly use the IDiagnosticAnalyzerService.  This will use the actual snapshots
     // we're passing in.  If information is already cached for that snapshot, it will be returned.  Otherwise,
     // it will be computed on demand.  Because it is always accurate as per this snapshot, all spans are correct
     // and do not need to be adjusted.
     return(_analyzerService.GetDiagnosticsForSpanAsync(document, range: null, cancellationToken: cancellationToken));
 }
Пример #9
0
        /// <summary>
        /// True if diagnostics can be displayed to the current user.
        /// If &lt;diagnostics enableFor="None" /&gt;, returns false.
        /// If &lt;diagnostics enableFor="Localhost" /&gt;, returns false for remote requests
        /// If &lt;diagnostics enableFor="AllHosts" /&gt;, returns true.
        /// If unspecified, uses the same behavior as ASP.NET Custom Errors.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public bool AllowResponse(HttpContext context)
        {
            bool           detailedErrors = !context.IsCustomErrorEnabled;
            DiagnosticMode def            = (detailedErrors) ? DiagnosticMode.AllHosts : DiagnosticMode.None;

            DiagnosticMode mode = c.get <DiagnosticMode>("diagnostics.enableFor", def);

            if (mode == DiagnosticMode.None)
            {
                return(false);
            }
            if (mode == DiagnosticMode.AllHosts)
            {
                return(true);
            }
            return(context.Request.IsLocal);
        }
 protected internal override bool SupportsDignosticMode(DiagnosticMode mode)
 {
     // We only support push diagnostics.  When pull diagnostics are on, ellipses suggestions are handled by the
     // lsp client.
     return(mode == DiagnosticMode.Push);
 }
Пример #11
0
 public ImmutableArray <DiagnosticBucket> GetPushDiagnosticBuckets(Workspace workspace, ProjectId projectId, DocumentId documentId, DiagnosticMode diagnosticMode, CancellationToken cancellationToken)
 => GetDiagnosticBuckets(workspace, projectId, documentId, forPullDiagnostics: false, diagnosticMode, cancellationToken);
Пример #12
0
 public ValueTask <ImmutableArray <DiagnosticData> > GetPushDiagnosticsAsync(Workspace workspace, ProjectId projectId, DocumentId documentId, object id, bool includeSuppressedDiagnostics, DiagnosticMode diagnosticMode, CancellationToken cancellationToken)
 => GetDiagnosticsAsync(workspace, projectId, documentId, id, includeSuppressedDiagnostics, forPullDiagnostics: false, diagnosticMode, cancellationToken);
 protected internal override bool SupportsDignosticMode(DiagnosticMode mode)
 {
     // We support inline diagnostics in both push and pull (since lsp doesn't support inline diagnostics yet).
     return(true);
 }
 public static ValueTask <ImmutableArray <DiagnosticData> > GetPushDiagnosticsAsync(this IDiagnosticService service, DiagnosticBucket bucket, bool includeSuppressedDiagnostics, DiagnosticMode diagnosticMode, CancellationToken cancellationToken)
 => service.GetPushDiagnosticsAsync(bucket.Workspace, bucket.ProjectId, bucket.DocumentId, bucket.Id, includeSuppressedDiagnostics, diagnosticMode, cancellationToken);
Пример #15
0
 protected internal override bool SupportsDignosticMode(DiagnosticMode mode)
 {
     // We only support push diagnostics.  When pull diagnostics are on, squiggles are handled by the lsp client.
     return(mode == DiagnosticMode.Push);
 }
Пример #16
0
 public ImmutableArray <DiagnosticBucket> GetPushDiagnosticBuckets(Workspace workspace, ProjectId?projectId, DocumentId?documentId, DiagnosticMode diagnosticMode, CancellationToken cancellationToken)
 {
     return(GetDiagnosticBuckets(workspace, projectId, documentId));
 }
Пример #17
0
 public ValueTask <ImmutableArray <DiagnosticData> > GetPushDiagnosticsAsync(Workspace workspace, ProjectId?projectId, DocumentId?documentId, object?id, bool includeSuppressedDiagnostics, DiagnosticMode diagnosticMode, CancellationToken cancellationToken)
 {
     return(new ValueTask <ImmutableArray <DiagnosticData> >(GetDiagnostics(workspace, projectId, documentId)));
 }