-
-
Notifications
You must be signed in to change notification settings - Fork 746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add simple diagnostic output to InterfaceStubGenerator. #79
Changes from 1 commit
e80321b
5c2bfd7
d77485c
92f9f55
9a09cda
803de99
d02831b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Refit.Generator | ||
{ | ||
public class DiagnosticsLogger | ||
{ | ||
List<Diagnostic> diagnostics = new List<Diagnostic>(); | ||
|
||
public IEnumerable<Diagnostic> Diagnostics { get { return diagnostics.AsReadOnly(); } } | ||
|
||
public void Add(Diagnostic diagnostic) | ||
{ | ||
this.diagnostics.Add(diagnostic); | ||
} | ||
|
||
public void AddRange(IEnumerable<Diagnostic> collection) | ||
{ | ||
this.diagnostics.AddRange(collection); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
public void Dump() | ||
{ | ||
var builder = new StringBuilder(); | ||
|
||
foreach (var diagnostic in diagnostics) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⬆️ |
||
builder.Clear(); | ||
|
||
if (!string.IsNullOrWhiteSpace(diagnostic.File)) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⬆️ |
||
builder.Append(diagnostic.File); | ||
if (diagnostic.Line.HasValue) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⬆️ |
||
builder.AppendFormat("({0}", diagnostic.Line); | ||
if (diagnostic.Character.HasValue) | ||
builder.AppendFormat(",{0}", diagnostic.Character); | ||
builder.Append(")"); | ||
} | ||
builder.Append(": "); | ||
} | ||
builder.AppendFormat("{0} {1}", diagnostic.Type, diagnostic.Code); | ||
if (!string.IsNullOrWhiteSpace(diagnostic.Message)) | ||
builder.AppendFormat(": {0}", diagnostic.Message); | ||
|
||
Console.Error.WriteLine(builder.ToString()); | ||
} | ||
} | ||
} | ||
|
||
public class Diagnostic | ||
{ | ||
public string Type { get; private set; } | ||
public string Code { get; private set; } | ||
public string File { get; protected set; } | ||
public int? Line { get; protected set; } | ||
public int? Character { get; protected set; } | ||
public string Message { get; protected set; } | ||
|
||
public Diagnostic(string type, string code) | ||
{ | ||
this.Type = type; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
this.Code = code; | ||
} | ||
} | ||
|
||
public class Warning : Diagnostic | ||
{ | ||
public Warning(string code) : base("warning", code) { } | ||
} | ||
|
||
public class MissingRefitAttributeWarning : Warning | ||
{ | ||
public string InterfaceName { get; private set; } | ||
public string MethodName { get; private set; } | ||
|
||
public MissingRefitAttributeWarning(InterfaceDeclarationSyntax @interface, MethodDeclarationSyntax method) | ||
: base("RF001") | ||
{ | ||
var location = method.GetLocation(); | ||
var line = location.GetMappedLineSpan().StartLinePosition; | ||
|
||
this.File = location.FilePath; | ||
this.Line = line.Line + 1; | ||
this.Character = line.Character + 1; | ||
this.InterfaceName = @interface.Identifier.Text; | ||
this.MethodName = method.Identifier.Text; | ||
|
||
this.Message = string.Format( | ||
"Method {0}.{1} either has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument.", | ||
this.InterfaceName, this.MethodName); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.