private IEnumerable <Diagnostic> ExtractRelatedInformationOfAnError(PhysicalFile file, DiagnosticElement e) { List <Diagnostic> relatedInformations = new List <Diagnostic>(); foreach (ErrorInformation.AuxErrorInfo aux in e.Aux) { if (aux.Category == "Execution trace") { continue; } string auxmessage = aux.Msg; int auxline = aux.Tok.line - 1; int auxcol = aux.Tok.col - 1; int auxlength = file.GetLengthOfLine(auxline) - auxcol; Range auxrange = CreateRange(auxline, auxcol, auxlength); string src = file.FileName; Diagnostic relatedDiagnostic = new Diagnostic { Message = auxmessage, Range = auxrange, Severity = DiagnosticSeverity.Information, Source = src }; relatedInformations.Add(relatedDiagnostic); } return(relatedInformations); }
public void LineNegativeThrows() { var f = new PhysicalFile() { Sourcecode = "a\nabc\na" }; Assert.Throws <ArgumentException>(() => f.GetLengthOfLine(-1)); }
public void SimpleTest2() { var f = new PhysicalFile() { Sourcecode = "a\nabc\na" }; int result = f.GetLengthOfLine(0); Assert.AreEqual(1, result); }
private void AddPosition(CounterExample ce, string stateCapturedStateName) { const string regex = @".*dfy\((\d+),(\d+)\)"; //anything, then dfy(00,00) var r = new Regex(regex, RegexOptions.IgnoreCase | RegexOptions.Singleline); var m = r.Match(stateCapturedStateName); if (m.Success) { var lineStr = m.Groups[1].ToString(); int line = int.Parse(lineStr); ce.Line = line; ce.Col = PhysicalFile.GetLengthOfLine(line); } else { ce.Line = 0; ce.Col = 0; } }
private Diagnostic ConvertErrorToDiagnostic(PhysicalFile file, DiagnosticElement e) { int line = e.Tok.line - 1; int col = e.Tok.col - 1; int length = file.GetLengthOfLine(line) - col; var range = this.CreateRange(line, col, length); if (e.Msg.EndsWith(".")) { e.Msg = e.Msg.Substring(0, e.Msg.Length - 1); } string msg; if (e.Tok.val == "anything so that it is nonnull" || e.Tok.val == null) { msg = e.Msg; } else if (e.Tok.val.Equals("{") && _fileRepository.SymbolTableManager != null) { ISymbolInformation wrappingSymbol = _fileRepository.SymbolTableManager.GetSymbolWrapperForCurrentScope(file.Uri, line, col); range = CreateRange(wrappingSymbol.Position.BodyStartToken, wrappingSymbol.Position.BodyEndToken); msg = e.Msg + $"\n at {wrappingSymbol.Name}"; } else { msg = e.Msg + $" \n at {e.Tok.val}\n "; } string src = file.Filepath.Split('/').Last(); DiagnosticSeverity severity; switch (e.Severity) { case ErrorLevel.Error: severity = DiagnosticSeverity.Error; break; case ErrorLevel.Warning: severity = DiagnosticSeverity.Warning; break; case ErrorLevel.Info: severity = DiagnosticSeverity.Information; break; default: severity = DiagnosticSeverity.Error; break; } Diagnostic d = new Diagnostic { Message = msg, Range = range, Severity = severity, Source = src }; return(d); }