private void PopulateInitialData(Workspace workspace, IDiagnosticService diagnosticService)
 {
     foreach (var args in diagnosticService.GetDiagnosticsUpdatedEventArgs(workspace, projectId: null, documentId: null, cancellationToken: CancellationToken.None))
     {
         OnDataAddedOrChanged(args);
     }
 }
Esempio n. 2
0
        void UpdateInitialDiagnostics()
        {
            if (!AnalysisOptions.EnableFancyFeatures)
            {
                return;
            }

            var doc = DocumentContext.AnalysisDocument;

            if (doc == null || DocumentContext.IsAdHocProject)
            {
                return;
            }

            var ad = new AnalysisDocument(Editor, DocumentContext);

            Task.Run(() => {
                var ws = DocumentContext.RoslynWorkspace;
                var analysisDocument = DocumentContext.AnalysisDocument;
                if (analysisDocument == null)
                {
                    return;
                }
                var project  = analysisDocument.Project.Id;
                var document = analysisDocument.Id;

                // Force an initial diagnostic update from the engine.
                foreach (var updateArgs in diagService.GetDiagnosticsUpdatedEventArgs(ws, project, document, src.Token))
                {
                    var diagnostics = AdjustInitialDiagnostics(analysisDocument.Project.Solution, updateArgs, src.Token);
                    if (diagnostics.Length == 0)
                    {
                        continue;
                    }

                    var e = DiagnosticsUpdatedArgs.DiagnosticsCreated(
                        updateArgs.Id, updateArgs.Workspace, analysisDocument.Project.Solution, updateArgs.ProjectId, updateArgs.DocumentId, diagnostics);

                    OnDiagnosticsUpdated(this, e);
                }
            });
        }
        private void ProduceTags(TaggerContext <TTag> context, DocumentSnapshotSpan spanToTag)
        {
            if (!this.IsEnabled)
            {
                return;
            }

            var document = spanToTag.Document;

            if (document == null)
            {
                return;
            }

            var editorSnapshot = spanToTag.SnapshotSpan.Snapshot;

            var cancellationToken = context.CancellationToken;
            var workspace         = document.Project.Solution.Workspace;

            // See if we've marked any spans as those we want to suppress diagnostics for.
            // This can happen for buffers used in the preview workspace where some feature
            // is generating code that it doesn't want errors shown for.
            var buffer = editorSnapshot.TextBuffer;
            var suppressedDiagnosticsSpans = default(NormalizedSnapshotSpanCollection);

            buffer?.Properties.TryGetProperty(PredefinedPreviewTaggerKeys.SuppressDiagnosticsSpansKey, out suppressedDiagnosticsSpans);

            var eventArgs = _diagnosticService.GetDiagnosticsUpdatedEventArgs(
                workspace, document.Project.Id, document.Id, context.CancellationToken);

            var sourceText = editorSnapshot.AsText();

            foreach (var updateArg in eventArgs)
            {
                ProduceTags(
                    context, spanToTag, workspace, document, sourceText,
                    suppressedDiagnosticsSpans, updateArg, cancellationToken);
            }
        }