private DiagnosticData TryCreateDocumentDiagnosticItem(ExternalError error) { var documentId = TryGetDocumentId(error.bstrFileName); if (documentId == null) { return(null); } var line = error.iLine; var column = error.iCol; // something we should move to document service one day. but until then, we keep the old way. // build basically output error location on surface buffer and we map it back to // subject buffer for contained document. so that contained document can map // it back to surface buffer when navigate. whole problem comes in due to the mapped span. // unlike live error, build outputs mapped span and we save it as original span (since we // have no idea whether it is mapped or not). for contained document case, we do know it is // mapped span, so we calculate original span and put that in original span. var containedDocument = ContainedDocument.TryGetContainedDocument(documentId); if (containedDocument != null) { var span = new TextSpan { iStartLine = line, iStartIndex = column, iEndLine = line, iEndIndex = column, }; var spans = new TextSpan[1]; Marshal.ThrowExceptionForHR(containedDocument.BufferCoordinator.MapPrimaryToSecondarySpan( span, spans)); line = spans[0].iStartLine; column = spans[0].iStartIndex; } // save error line/column (surface buffer location) as mapped line/column so that we can display // right location on closed Venus file. return(GetDiagnosticData( documentId, _projectId, GetErrorId(error), message: error.bstrText, GetDiagnosticSeverity(error), _language, mappedFilePath: null, mappedStartLine: error.iLine, mappedStartColumn: error.iCol, mappedEndLine: error.iLine, mappedEndColumn: error.iCol, originalFilePath: error.bstrFileName, originalStartLine: line, originalStartColumn: column, originalEndLine: line, originalEndColumn: column)); }
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); }
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; }
private DiagnosticData CreateDocumentDiagnosticItem(ExternalError error) { var hostProject = _workspace.GetHostProject(_projectId); if (!hostProject.ContainsFile(error.bstrFileName)) { return(null); } var hostDocument = hostProject.GetCurrentDocumentFromPath(error.bstrFileName); var line = error.iLine; var column = error.iCol; if (hostDocument is ContainedDocument containedDocument) { var span = new VsTextSpan { iStartLine = line, iStartIndex = column, iEndLine = line, iEndIndex = column, }; var spans = new VsTextSpan[1]; Marshal.ThrowExceptionForHR(containedDocument.ContainedLanguage.BufferCoordinator.MapPrimaryToSecondarySpan( span, spans)); line = spans[0].iStartLine; column = spans[0].iStartIndex; } return(GetDiagnosticData(error, hostDocument.Id, line, column)); }
private DiagnosticData CreateDocumentDiagnosticItem(ExternalError error) { var documentId = TryGetDocumentId(error.bstrFileName); if (documentId == null) { return(null); } var line = error.iLine; var column = error.iCol; /* TODO: make work again * if (hostDocument is ContainedDocument containedDocument) * { * var span = new VsTextSpan * { * iStartLine = line, * iStartIndex = column, * iEndLine = line, * iEndIndex = column, * }; * * var spans = new VsTextSpan[1]; * Marshal.ThrowExceptionForHR(containedDocument.ContainedLanguage.BufferCoordinator.MapPrimaryToSecondarySpan( * span, * spans)); * * line = spans[0].iStartLine; * column = spans[0].iStartIndex; * } */ return(GetDiagnosticData(error, documentId, line, column)); }
/// <summary> /// This method *has* to convert whatever NHibernate exception to a valid PPWCode exception /// Some hibernate exceptions might be semantic, some might be errors. /// This may depend on the actual product. /// This method translates semantic exceptions in PPWCode.Util.Exception.SemanticException and throws them /// and all other exceptions in PPWCode.Util.Exception.Error and throws them. /// </summary> /// <param name="exception">The hibernate exception we are triaging.</param> /// <param name="message">This message will be used in the logging in the case aException = Error.</param> /// <returns>An exception that is a sub class either from <see cref="SemanticException" /> or from <see cref="Error" />.</returns> protected virtual Exception TriageException(Exception exception, string message) { Contract.Requires(exception != null); Contract.Requires(!string.IsNullOrEmpty(message)); Exception result; Logger.Debug(message, exception); GenericADOException genericAdoException = exception as GenericADOException; if (genericAdoException != null) { RepositorySqlException repositorySqlException = new RepositorySqlException(message, genericAdoException.InnerException) { SqlString = genericAdoException.SqlString, }; SqlException sqlException = genericAdoException.InnerException as SqlException; if (sqlException != null) { repositorySqlException.Constraint = sqlException.GetConstraint(); } result = repositorySqlException; } else { result = new ExternalError(message, exception); } throw result; }
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), _language, 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); }
private DiagnosticData GetDiagnosticData( ExternalError error, DocumentId id = null, int line = 0, int column = 0) { if (id != null) { // save error line/column (surface buffer location) as mapped line/column so that we can display // right location on closed Venus file. return(GetDiagnosticData( id, GetErrorId(error), error.bstrText, GetDiagnosticSeverity(error), null, error.iLine, error.iCol, error.iLine, error.iCol, error.bstrFileName, line, column, line, column)); } return(GetDiagnosticData( id, GetErrorId(error), error.bstrText, GetDiagnosticSeverity(error), null, 0, 0, 0, 0, null, 0, 0, 0, 0)); }
private DiagnosticData CreateProjectDiagnosticItem(ExternalError error) { return GetDiagnosticData(error); }
private DiagnosticData CreateDocumentDiagnosticItem(ExternalError error) { var hostProject = _workspace.GetHostProject(_projectId); if (!hostProject.ContainsFile(error.bstrFileName)) { return null; } var hostDocument = hostProject.GetCurrentDocumentFromPath(error.bstrFileName); var line = error.iLine; var column = error.iCol; var containedDocument = hostDocument as ContainedDocument; if (containedDocument != null) { var span = new VsTextSpan { iStartLine = line, iStartIndex = column, iEndLine = line, iEndIndex = column, }; var spans = new VsTextSpan[1]; Marshal.ThrowExceptionForHR(containedDocument.ContainedLanguage.BufferCoordinator.MapPrimaryToSecondarySpan( span, spans)); line = spans[0].iStartLine; column = spans[0].iStartIndex; } return GetDiagnosticData(error, hostDocument.Id, line, column); }
private DiagnosticData GetDiagnosticData( ExternalError error, DocumentId id = null, int line = 0, int column = 0) { if (id != null) { // save error line/column (surface buffer location) as mapped line/column so that we can display // right location on closed Venus file. return GetDiagnosticData( id, GetErrorId(error), error.bstrText, GetDiagnosticSeverity(error), null, error.iLine, error.iCol, error.iLine, error.iCol, error.bstrFileName, line, column, line, column); } return GetDiagnosticData( id, GetErrorId(error), error.bstrText, GetDiagnosticSeverity(error), null, 0, 0, 0, 0, null, 0, 0, 0, 0); }
public RelayException(ExternalError externalError) : base( $"{RelayErrorCode.ExternalError}: {externalError.error_reason} ({externalError.error_code})") { Code = RelayErrorCode.ExternalError; }
private static DiagnosticSeverity GetDiagnosticSeverity(ExternalError error) { return error.fError != 0 ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning; }
private string GetErrorId(ExternalError error) { return string.Format("{0}{1:0000}", _errorCodePrefix, error.iErrorID); }
private DiagnosticData CreateProjectDiagnosticItem(ExternalError error) { return(GetDiagnosticData(error)); }
private string GetErrorId(ExternalError error) { return(string.Format("{0}{1:0000}", _errorCodePrefix, error.iErrorID)); }
private static DiagnosticSeverity GetDiagnosticSeverity(ExternalError error) { return(error.fError != 0 ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning); }