示例#1
0
        public static DiagnosticAnalysisResult CreateFromBuild(
            Project project,
            ImmutableArray <DiagnosticData> diagnostics,
            IEnumerable <DocumentId> initialDocuments
            )
        {
            // we can't distinguish locals and non locals from build diagnostics nor determine right snapshot version for the build.
            // so we put everything in as semantic local with default version. this lets us to replace those to live diagnostics when needed easily.
            var version = VersionStamp.Default;

            var documentIds = ImmutableHashSet.CreateBuilder <DocumentId>();

            documentIds.AddRange(initialDocuments);

            var diagnosticsWithDocumentId = PooledDictionary <
                DocumentId,
                ArrayBuilder <DiagnosticData>
                > .GetInstance();

            var diagnosticsWithoutDocumentId = ArrayBuilder <DiagnosticData> .GetInstance();

            foreach (var data in diagnostics)
            {
                var documentId = data.DocumentId;
                if (documentId != null)
                {
                    documentIds.Add(documentId);
                    diagnosticsWithDocumentId.MultiAdd(documentId, data);
                }
                else
                {
                    diagnosticsWithoutDocumentId.Add(data);
                }
            }

            var result = new DiagnosticAnalysisResult(
                project.Id,
                version,
                documentIds: documentIds.ToImmutable(),
                syntaxLocals: ImmutableDictionary <DocumentId, ImmutableArray <DiagnosticData> > .Empty,
                semanticLocals: diagnosticsWithDocumentId.ToImmutableMultiDictionaryAndFree(),
                nonLocals: ImmutableDictionary <DocumentId, ImmutableArray <DiagnosticData> > .Empty,
                others: diagnosticsWithoutDocumentId.ToImmutableAndFree(),
                fromBuild: true
                );

            return(result);
        }
示例#2
0
        public static DiagnosticAnalysisResult CreateFromBuild(Project project, ImmutableArray <DiagnosticData> diagnostics)
        {
            // we can't distinguish locals and non locals from build diagnostics nor determine right snapshot version for the build.
            // so we put everything in as semantic local with default version. this lets us to replace those to live diagnostics when needed easily.
            var version = VersionStamp.Default;

            // filter out any document that doesn't support diagnostics.
            // g.Key == null means diagnostics on the project which assigned to "others" error category
            var group = diagnostics.GroupBy(d => d.DocumentId).Where(g => g.Key == null || project.GetDocument(g.Key).SupportsDiagnostics()).ToList();

            var result = new DiagnosticAnalysisResult(
                project.Id,
                version,
                documentIds: group.Where(g => g.Key != null).Select(g => g.Key).ToImmutableHashSet(),
                syntaxLocals: ImmutableDictionary <DocumentId, ImmutableArray <DiagnosticData> > .Empty,
                semanticLocals: group.Where(g => g.Key != null).ToImmutableDictionary(g => g.Key, g => g.ToImmutableArray()),
                nonLocals: ImmutableDictionary <DocumentId, ImmutableArray <DiagnosticData> > .Empty,
                others: group.Where(g => g.Key == null).SelectMany(g => g).ToImmutableArrayOrEmpty(),
                fromBuild: true);

            return(result);
        }