public int AddNewErrors(IVsEnumExternalErrors pErrors)
        {
            var projectErrors     = new HashSet <DiagnosticData>();
            var documentErrorsMap = new Dictionary <DocumentId, HashSet <DiagnosticData> >();

            var  errors = new ExternalError[1];
            uint fetched;

            while (pErrors.Next(1, errors, out fetched) == VSConstants.S_OK && fetched == 1)
            {
                var error = errors[0];

                DiagnosticData diagnostic;
                if (error.bstrFileName != null)
                {
                    diagnostic = CreateDocumentDiagnosticItem(error);
                    if (diagnostic != null)
                    {
                        var diagnostics = documentErrorsMap.GetOrAdd(diagnostic.DocumentId, _ => new HashSet <DiagnosticData>());
                        diagnostics.Add(diagnostic);
                        continue;
                    }

                    projectErrors.Add(CreateProjectDiagnosticItem(error));
                }
                else
                {
                    projectErrors.Add(CreateProjectDiagnosticItem(error));
                }
            }

            _diagnosticProvider.AddNewErrors(_projectId, projectErrors, documentErrorsMap);
            return(VSConstants.S_OK);
        }
Example #2
0
        public int AddNewErrors(IVsEnumExternalErrors pErrors)
        {
            var projectErrors     = new HashSet <DiagnosticData>();
            var documentErrorsMap = new Dictionary <DocumentId, HashSet <DiagnosticData> >();

            var errors = new ExternalError[1];

            while (pErrors.Next(1, errors, out var fetched) == VSConstants.S_OK && fetched == 1)
            {
                var error = errors[0];
                if (error.bstrFileName != null)
                {
                    var diagnostic = TryCreateDocumentDiagnosticItem(error);
                    if (diagnostic != null)
                    {
                        var diagnostics = documentErrorsMap.GetOrAdd(diagnostic.DocumentId, _ => new HashSet <DiagnosticData>());
                        diagnostics.Add(diagnostic);
                        continue;
                    }
                }

                projectErrors.Add(GetDiagnosticData(
                                      documentId: null,
                                      _projectId,
                                      GetErrorId(error),
                                      error.bstrText,
                                      GetDiagnosticSeverity(error),
                                      mappedFilePath: null,
                                      mappedStartLine: 0,
                                      mappedStartColumn: 0,
                                      mappedEndLine: 0,
                                      mappedEndColumn: 0,
                                      originalFilePath: null,
                                      originalStartLine: 0,
                                      originalStartColumn: 0,
                                      originalEndLine: 0,
                                      originalEndColumn: 0));
            }

            _diagnosticProvider.AddNewErrors(_projectId, projectErrors, documentErrorsMap);
            return(VSConstants.S_OK);
        }