private void EmitDiagnostics(DocumentDiagnostics results)
 {
     _forwarder.Forward(new DiagnosticMessage
     {
         Results = new[]
         {
             new DiagnosticResult
             {
                 FileName = results.DocumentPath, QuickFixes = results.Diagnostics
                                                               .Select(x => x.ToDiagnosticLocation())
                                                               .ToList()
             }
         }
     });
 }
示例#2
0
        private void UpdateCurrentDiagnostics(Document document, ImmutableArray <Diagnostic> diagnosticsWithAnalyzers)
        {
            DocumentDiagnostics documentDiagnostics = new DocumentDiagnostics(document, diagnosticsWithAnalyzers);

            try
            {
                _currentDiagnosticResultLookup.Add(document, documentDiagnostics);
            }
            catch (ArgumentException)
            {
                // The work for this document was already done. Solutions (and by extension Documents) are immutable,
                // so this is fine to silently swallow, as we'll get the same results every time.
            }
            EmitDiagnostics(documentDiagnostics);
        }
示例#3
0
        private async Task <ImmutableArray <DocumentDiagnostics> > GetDiagnosticsByDocument(ImmutableArray <Document> documents, bool waitForDocuments)
        {
            if (documents.IsDefaultOrEmpty)
            {
                return(ImmutableArray <DocumentDiagnostics> .Empty);
            }

            ImmutableArray <DocumentDiagnostics> .Builder resultsBuilder = ImmutableArray.CreateBuilder <DocumentDiagnostics>(documents.Length);
            resultsBuilder.Count = documents.Length;

            bool foundAll = true;

            for (int i = 0; i < documents.Length; i++)
            {
                if (_currentDiagnosticResultLookup.TryGetValue(documents[i], out var diagnostics))
                {
                    resultsBuilder[i] = diagnostics;
                }
                else
                {
                    _workQueue.QueueDocumentForeground(documents[i]);
                    foundAll = false;
                }
            }

            if (foundAll)
            {
                return(resultsBuilder.MoveToImmutable());
            }

            await _workQueue.WaitForegroundWorkComplete();

            for (int i = 0; i < documents.Length; i++)
            {
                if (_currentDiagnosticResultLookup.TryGetValue(documents[i], out var diagnostics))
                {
                    resultsBuilder[i] = diagnostics;
                }
                else
                {
                    Debug.Fail("Should have diagnostics after waiting for work");
                    resultsBuilder[i] = new DocumentDiagnostics(documents[i], ImmutableArray <Diagnostic> .Empty);
                }
            }

            return(resultsBuilder.MoveToImmutable());
        }