添加项目文件。
This commit is contained in:
70
ScriptPad/Roslyn/ErrorListItem.cs
Normal file
70
ScriptPad/Roslyn/ErrorListItem.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using Microsoft.CodeAnalysis;
|
||||
|
||||
namespace ScriptPad.Roslyn
|
||||
{
|
||||
/// <summary>
|
||||
/// 错误项
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 严重性
|
||||
/// </summary>
|
||||
public ErrorSeverity ErrorSeverity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 起始行
|
||||
/// </summary>
|
||||
public int StartLine { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 起始列
|
||||
/// </summary>
|
||||
public int StartColumn { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束行
|
||||
/// </summary>
|
||||
public int EndLine { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束列
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user