示例#1
0
 public bool TryMergeWithFollowing(RustcParsedMessage other)
 {
     if (other.Type == RustcParsedMessageType.Note && other.File == this.File &&
         other.LineNumber == this.LineNumber && other.ColumnNumber == this.ColumnNumber &&
         other.EndLineNumber == this.EndLineNumber && other.EndColumnNumber == this.EndColumnNumber)
     {
         this.Message += "\nnote: " + other.Message;
         return(true);
     }
     else
     {
         return(false);
     }
 }
 public bool TryMergeWithFollowing(RustcParsedMessage other)
 {
     if ((other.Type == RustcParsedMessageType.Note || other.Type == RustcParsedMessageType.Help) &&
         other.File == this.File && other.LineNumber == this.LineNumber && other.ColumnNumber == this.ColumnNumber &&
         other.EndLineNumber == this.EndLineNumber && other.EndColumnNumber == this.EndColumnNumber)
     {
         var prefix = other.Type == RustcParsedMessageType.Note ? "\nnote: " : "\nhelp: ";
         this.Message += prefix + other.Message;
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#3
0
 private void LogRustcMessage(RustcParsedMessage msg)
 {
     if (msg.Type == RustcParsedMessageType.Warning)
     {
         this.Log.LogWarning(null, msg.ErrorCode, null, msg.File, msg.LineNumber, msg.ColumnNumber, msg.EndLineNumber, msg.EndColumnNumber, msg.Message);
     }
     else if (msg.Type == RustcParsedMessageType.Note)
     {
         this.Log.LogWarning(null, msg.ErrorCode, null, msg.File, msg.LineNumber, msg.ColumnNumber, msg.EndLineNumber, msg.EndColumnNumber, "note: " + msg.Message);
     }
     else
     {
         this.Log.LogError(null, msg.ErrorCode, null, msg.File, msg.LineNumber, msg.ColumnNumber, msg.EndLineNumber, msg.EndColumnNumber, msg.Message);
     }
 }
示例#4
0
 public bool TryMergeWithFollowing(RustcParsedMessage other)
 {
     if ((other.Type == RustcParsedMessageType.Note || other.Type == RustcParsedMessageType.Help)
         && other.File == this.File && other.LineNumber == this.LineNumber && other.ColumnNumber == this.ColumnNumber &&
         other.EndLineNumber == this.EndLineNumber && other.EndColumnNumber == this.EndColumnNumber)
     {
         var prefix = other.Type == RustcParsedMessageType.Note ? "\nnote: " : "\nhelp: ";
         this.Message += prefix + other.Message;
         return true;
     }
     else
     {
         return false;
     }
 }
示例#5
0
        private IEnumerable <RustcParsedMessage> ParseOutput(string output)
        {
            MatchCollection errorMatches = defectRegex.Matches(output);

            RustcParsedMessage 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, System.Globalization.NumberStyles.None);
                int    col          = Int32.Parse(match.Groups[3].Value, System.Globalization.NumberStyles.None);
                int    endLine      = Int32.Parse(match.Groups[4].Value, System.Globalization.NumberStyles.None);
                int    endCol       = Int32.Parse(match.Groups[5].Value, System.Globalization.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 RustcParsedMessage(RustcParsedMessageType.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: ") ? RustcParsedMessageType.Note : RustcParsedMessageType.Help;
                    RustcParsedMessage note = new RustcParsedMessage(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 RustcParsedMessage(RustcParsedMessageType.Error, msg, errorCode, match.Groups[1].Value,
                                                      line, col, endLine, endCol);
                }
            }

            if (previous != null)
            {
                yield return(previous);
            }
        }
示例#6
0
        private IEnumerable<RustcParsedMessage> ParseOutput(string output)
        {
            MatchCollection errorMatches = defectRegex.Matches(output);

            RustcParsedMessage 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, System.Globalization.NumberStyles.None);
                int col = Int32.Parse(match.Groups[3].Value, System.Globalization.NumberStyles.None);
                int endLine = Int32.Parse(match.Groups[4].Value, System.Globalization.NumberStyles.None);
                int endCol = Int32.Parse(match.Groups[5].Value, System.Globalization.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 RustcParsedMessage(RustcParsedMessageType.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: ") ? RustcParsedMessageType.Note : RustcParsedMessageType.Help;
                    RustcParsedMessage note = new RustcParsedMessage(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 RustcParsedMessage(RustcParsedMessageType.Error, msg, errorCode, match.Groups[1].Value,
                        line, col, endLine, endCol);
                }
            }

            if (previous != null) yield return previous;
        }
示例#7
0
 private void LogRustcMessage(RustcParsedMessage msg)
 {
     if (msg.Type == RustcParsedMessageType.Warning)
     {
         this.Log.LogWarning(null, msg.ErrorCode, null, msg.File, msg.LineNumber, msg.ColumnNumber, msg.EndLineNumber, msg.EndColumnNumber, msg.Message);
     }
     else if (msg.Type == RustcParsedMessageType.Note)
     {
         this.Log.LogWarning(null, msg.ErrorCode, null, msg.File, msg.LineNumber, msg.ColumnNumber, msg.EndLineNumber, msg.EndColumnNumber, "note: " + msg.Message);
     }
     else
     {
         this.Log.LogError(null, msg.ErrorCode, null, msg.File, msg.LineNumber, msg.ColumnNumber, msg.EndLineNumber, msg.EndColumnNumber, msg.Message);
     }
 }
示例#8
0
        private IEnumerable <RustcParsedMessage> ParseOutput(string output)
        {
            MatchCollection errorMatches = defectRegex.Matches(output);

            RustcParsedMessage previous = null;

            foreach (Match match in errorMatches)
            {
                Match  errorMatch = errorCodeRegex.Match(match.Groups[6].Value);
                string errorCode  = errorMatch.Success ? errorMatch.Groups[1].Value : null;
                int    line       = Int32.Parse(match.Groups[2].Value, System.Globalization.NumberStyles.None);
                int    col        = Int32.Parse(match.Groups[3].Value, System.Globalization.NumberStyles.None);
                int    endLine    = Int32.Parse(match.Groups[4].Value, System.Globalization.NumberStyles.None);
                int    endCol     = Int32.Parse(match.Groups[5].Value, System.Globalization.NumberStyles.None);

                if (match.Groups[6].Value.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 RustcParsedMessage(RustcParsedMessageType.Warning, msg, errorCode, match.Groups[1].Value,
                                                      line, col, endLine, endCol);
                }
                else if (match.Groups[6].Value.StartsWith("note: "))
                {
                    string             msg  = match.Groups[6].Value.Substring(6, match.Groups[6].Value.Length - 6 - (errorCode != null ? 8 : 0));
                    RustcParsedMessage note = new RustcParsedMessage(RustcParsedMessageType.Note, msg, errorCode, match.Groups[1].Value,
                                                                     line, col, endLine, endCol);

                    if (previous != null)
                    {
                        // try to merge notes 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 = match.Groups[6].Value.StartsWith("error: ");
                    string msg             = match.Groups[6].Value.Substring((startsWithError ? 7 : 0), match.Groups[6].Value.Length - (startsWithError ? 7 : 0) - (errorCode != null ? 8 : 0));
                    if (previous != null)
                    {
                        yield return(previous);
                    }
                    previous = new RustcParsedMessage(RustcParsedMessageType.Error, msg, errorCode, match.Groups[1].Value,
                                                      line, col, endLine, endCol);
                }
            }

            if (previous != null)
            {
                yield return(previous);
            }
        }