示例#1
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);
     }
 }
示例#2
0
 public static void LogRustcMessage(RustcParsedMessage msg, TaskLoggingHelper log)
 {
     Debug.WriteLine(msg.ToString());
     if (msg.Type == RustcParsedMessageType.Warning)
     {
         log.LogWarning(null, msg.ErrorCode, null, msg.File, msg.LineNumber, msg.ColumnNumber, msg.EndLineNumber, msg.EndColumnNumber, msg.Message);
     }
     else if (msg.Type == RustcParsedMessageType.Note)
     {
         log.LogWarning(null, msg.ErrorCode, null, msg.File, msg.LineNumber, msg.ColumnNumber, msg.EndLineNumber, msg.EndColumnNumber, "note: " + msg.Message);
     }
     else
     {
         log.LogError(null, msg.ErrorCode, null, msg.File, msg.LineNumber, msg.ColumnNumber, msg.EndLineNumber, msg.EndColumnNumber, msg.Message);
     }
 }
示例#3
0
        public static 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);
            }
        }