using Microsoft.CodeAnalysis; namespace ScriptPad.Roslyn { /// /// 错误项 /// public class ErrorListItem { public ErrorListItem(ErrorSeverity errorSeverity, string description, int startLine, int startColumn, int endLine, int endColumn) { ErrorSeverity = errorSeverity; Description = description; StartLine = startLine; StartColumn = startColumn; EndLine = endLine; EndColumn = endColumn; } /// /// 严重性 /// public ErrorSeverity ErrorSeverity { get; } /// /// 描述 /// public string Description { get; } /// /// 起始行 /// public int StartLine { get; } /// /// 起始列 /// public int StartColumn { get; } /// /// 结束行 /// public int EndLine { get; } /// /// 结束列 /// public int EndColumn { get; } public static ErrorListItem CreateErrorListItem(Diagnostic diagnostic) { var mappedSpan = diagnostic.Location.GetMappedLineSpan(); ErrorSeverity errorSeverity; if (diagnostic.Severity == DiagnosticSeverity.Error) { errorSeverity = ErrorSeverity.Error; } else if (diagnostic.Severity == DiagnosticSeverity.Warning) { errorSeverity = ErrorSeverity.Warning; } else { errorSeverity = ErrorSeverity.Info; } return new ErrorListItem(errorSeverity, diagnostic.GetMessage(), mappedSpan.Span.Start.Line, mappedSpan.Span.Start.Character, mappedSpan.Span.End.Line, mappedSpan.Span.End.Character); } } }