-
Notifications
You must be signed in to change notification settings - Fork 72
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
Json error format #230
Merged
Merged
Json error format #230
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bb1400d
initial support for json error format
14c634b
Added missing file
112c50f
Added reading rustc version for using json-error format
Vbif db11f06
Check version correctly. Remove Russian language from source.
Vbif cf61467
Fixed code span printing. Omit "aborting due to previous error" error
Vbif 1338f4b
Check for 1.12 version for JSON error format. JSON dll added to insta…
Vbif File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace VisualRust.Build.Message.Human | ||
{ | ||
static class RustcMessageHumanParser | ||
{ | ||
private static readonly Regex defectRegex = new Regex(@"^([^\n:]+):(\d+):(\d+):\s+(\d+):(\d+)\s+(.*)$", RegexOptions.Multiline | RegexOptions.CultureInvariant); | ||
|
||
private static readonly Regex errorCodeRegex = new Regex(@"\[([A-Z]\d\d\d\d)\]$", RegexOptions.CultureInvariant); | ||
|
||
public static IEnumerable<RustcMessageHuman> Parse(string output) | ||
{ | ||
MatchCollection errorMatches = defectRegex.Matches(output); | ||
|
||
RustcMessageHuman previous = null; | ||
foreach (Match match in errorMatches) | ||
{ | ||
string remainingMsg = match.Groups[6].Value.Trim(); | ||
Match errorMatch = errorCodeRegex.Match(remainingMsg); | ||
string errorCode = errorMatch.Success ? errorMatch.Groups[1].Value : null; | ||
int line = Int32.Parse(match.Groups[2].Value, NumberStyles.None); | ||
int col = Int32.Parse(match.Groups[3].Value, NumberStyles.None); | ||
int endLine = Int32.Parse(match.Groups[4].Value, NumberStyles.None); | ||
int endCol = Int32.Parse(match.Groups[5].Value, NumberStyles.None); | ||
|
||
if (remainingMsg.StartsWith("warning: ")) | ||
{ | ||
string msg = match.Groups[6].Value.Substring(9, match.Groups[6].Value.Length - 9 - (errorCode != null ? 8 : 0)); | ||
if (previous != null) yield return previous; | ||
previous = new RustcMessageHuman(RustcMessageType.Warning, msg, errorCode, match.Groups[1].Value, | ||
line, col, endLine, endCol); | ||
} | ||
else if (remainingMsg.StartsWith("note: ") || remainingMsg.StartsWith("help: ")) | ||
{ | ||
if (remainingMsg.StartsWith("help: pass `--explain ") && previous != null) | ||
{ | ||
previous.CanExplain = true; | ||
continue; | ||
} | ||
|
||
// NOTE: "note: " and "help: " are both 6 characters long (though hardcoding this is probably still not a very good idea) | ||
string msg = remainingMsg.Substring(6, remainingMsg.Length - 6 - (errorCode != null ? 8 : 0)); | ||
var type = remainingMsg.StartsWith("note: ") ? RustcMessageType.Note : RustcMessageType.Help; | ||
RustcMessageHuman note = new RustcMessageHuman(type, msg, errorCode, match.Groups[1].Value, | ||
line, col, endLine, endCol); | ||
|
||
if (previous != null) | ||
{ | ||
// try to merge notes and help messages with a previous message (warning or error where it belongs to), if the span is the same | ||
if (previous.TryMergeWithFollowing(note)) | ||
{ | ||
continue; // skip setting new previous, because we successfully merged the new note into the previous message | ||
} | ||
else | ||
{ | ||
yield return previous; | ||
} | ||
} | ||
previous = note; | ||
} | ||
else | ||
{ | ||
bool startsWithError = remainingMsg.StartsWith("error: "); | ||
string msg = remainingMsg.Substring((startsWithError ? 7 : 0), remainingMsg.Length - (startsWithError ? 7 : 0) - (errorCode != null ? 8 : 0)); | ||
if (previous != null) yield return previous; | ||
previous = new RustcMessageHuman(RustcMessageType.Error, msg, errorCode, match.Groups[1].Value, | ||
line, col, endLine, endCol); | ||
} | ||
} | ||
|
||
if (previous != null) yield return previous; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace VisualRust.Build.Message.Json | ||
{ | ||
public class RustcMessageJson | ||
{ | ||
public class DiagnosticCode | ||
{ | ||
/// <summary> | ||
/// The code itself. | ||
/// </summary> | ||
public string code { get; set; } | ||
/// <summary> | ||
/// An explanation for the code. | ||
/// </summary> | ||
public string explanation { get; set; } | ||
} | ||
|
||
public class DiagnosticSpanLine | ||
{ | ||
public string text { get; set; } | ||
public int highlight_start { get; set; } | ||
public int highlight_end { get; set; } | ||
} | ||
|
||
public class DiagnosticSpanMacroExpansion | ||
{ | ||
/// <summary> | ||
/// span where macro was applied to generate this code; note that | ||
/// this may itself derive from a macro (if | ||
/// `span.expansion.is_some()`) | ||
/// </summary> | ||
public DiagnosticSpan span { get; set; } | ||
/// <summary> | ||
/// name of macro that was applied (e.g., "foo!" or "#[derive(Eq)]") | ||
/// </summary> | ||
public String macro_decl_name { get; set; } | ||
/// <summary> | ||
/// span where macro was defined (if known) | ||
/// </summary> | ||
public DiagnosticSpan def_site_span { get; set; } | ||
} | ||
|
||
public class DiagnosticSpan | ||
{ | ||
public string file_name { get; set; } | ||
public int byte_start { get; set; } | ||
public int byte_end { get; set; } | ||
public int line_start { get; set; } | ||
public int line_end { get; set; } | ||
public int column_start { get; set; } | ||
public int column_end { get; set; } | ||
/// <summary> | ||
/// Is this a "primary" span -- meaning the point, or one of the points, | ||
/// where the error occurred? | ||
/// </summary> | ||
public bool is_primary { get; set; } | ||
/// <summary> | ||
/// Source text from the start of line_start to the end of line_end. | ||
/// </summary> | ||
public List<DiagnosticSpanLine> text { get; set; } | ||
/// <summary> | ||
/// Label that should be placed at this location (if any) | ||
/// </summary> | ||
public object label { get; set; } | ||
/// <summary> | ||
/// If we are suggesting a replacement, this will contain text | ||
/// that should be sliced in atop this span. You may prefer to | ||
/// load the fully rendered version from the parent `Diagnostic`, | ||
/// however. | ||
/// </summary> | ||
public String suggested_replacement { get; set; } | ||
/// <summary> | ||
/// Macro invocations that created the code at this span, if any. | ||
/// </summary> | ||
public DiagnosticSpanMacroExpansion expansion { get; set; } | ||
} | ||
|
||
/// <summary> | ||
/// The primary error message. | ||
/// </summary> | ||
public string message { get; set; } | ||
public DiagnosticCode code { get; set; } | ||
/// <summary> | ||
/// "error: internal compiler error", "error", "warning", "note", "help" | ||
/// </summary> | ||
public string level { private get; set; } | ||
public List<DiagnosticSpan> spans { get; set; } | ||
/// <summary> | ||
/// Associated diagnostic messages. | ||
/// </summary> | ||
public List<object> children { get; set; } | ||
/// <summary> | ||
/// The message as rustc would render it. Currently this is only | ||
/// `Some` for "suggestions", but eventually it will include all | ||
/// snippets. | ||
/// </summary> | ||
public object rendered { get; set; } | ||
|
||
public RustcMessageType GetLevelAsEnum() | ||
{ | ||
if (level == "error: internal compiler error" || level == "error") | ||
return RustcMessageType.Error; | ||
if (level == "warning") | ||
return RustcMessageType.Warning; | ||
if (level == "note") | ||
return RustcMessageType.Note; | ||
if (level == "help") | ||
return RustcMessageType.Help; | ||
|
||
return RustcMessageType.Error; | ||
} | ||
|
||
public DiagnosticSpan GetPrimarySpan() | ||
{ | ||
if (spans == null || spans.Count == 0) | ||
return null; | ||
|
||
return spans.FirstOrDefault(a => a.is_primary); | ||
} | ||
|
||
public String GetErrorCodeAsString() | ||
{ | ||
if (code == null) | ||
return string.Empty; | ||
return code.code; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using Newtonsoft.Json; | ||
|
||
namespace VisualRust.Build.Message.Json | ||
{ | ||
public static class RustcMessageJsonParser | ||
{ | ||
private static readonly JsonSerializer serializer = new JsonSerializer(); | ||
|
||
public static IEnumerable<RustcMessageJson> Parse(String output) | ||
{ | ||
var reader = new JsonTextReader(new StringReader(output)) {SupportMultipleContent = true}; | ||
|
||
while (reader.Read()) | ||
yield return serializer.Deserialize<RustcMessageJson>(reader); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace VisualRust.Build.Message | ||
{ | ||
public enum RustcMessageType | ||
{ | ||
Error, | ||
Warning, | ||
Note, | ||
Help | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I assume that the JSON deserialization keeps working if the format is changed (hopefully only backwards compatibly, i.e. by adding new fields), right?
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.
I dont markup any of JSON fields as "required", so deserializer probably "works" on any input. All new fileds will be skipped.