Create entry point to get diagnostic string message
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
6bcedaf743
commit
7958576b6a
|
@ -97,25 +97,30 @@ const string PrettyDiagnostic ( const char * format, vector<string> arguments)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DiagnosticsHolder::GetFullErrorMessage(Diagnostic diagnostic) {
|
std::string DiagnosticsHolder::GetFullDiagnostic(Diagnostic* diagnostic) {
|
||||||
stringstream stream;
|
stringstream stream;
|
||||||
stream << "[" << SeverityToString(diagnostic.GetSeverity()) << "] ";
|
stream << "[" << SeverityToString(diagnostic->GetSeverity()) << "] ";
|
||||||
auto startPos = diagnostic.GetStartPosition();
|
auto startPos = diagnostic->GetStartPosition();
|
||||||
auto line = this -> GetLineFromPosition(startPos);
|
auto line = this -> GetLineFromPosition(startPos);
|
||||||
auto linePos = startPos - this ->GetStartPositionForLine(line);
|
auto linePos = startPos - this ->GetStartPositionForLine(line);
|
||||||
stream << " (" << line + 1 << ", " << linePos + 1 << ") ";
|
stream << " (" << line + 1 << ", " << linePos + 1 << ") ";
|
||||||
auto unformatted = ErrorMessages.find(diagnostic.GetCode());
|
auto unformatted = ErrorMessages.find(diagnostic->GetCode());
|
||||||
if (unformatted != ErrorMessages.end()){
|
if (unformatted != ErrorMessages.end()){
|
||||||
stream << PrettyDiagnostic(unformatted->second, diagnostic.GetArguments());
|
stream << PrettyDiagnostic(unformatted->second, diagnostic->GetArguments());
|
||||||
}
|
}
|
||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int GetDiagnosticsCount (DiagnosticsHolder* diagnostics){
|
extern "C" {
|
||||||
return diagnostics->DiagnosticsCount();
|
int GetDiagnosticsCount (DiagnosticsHolder* diagnostics){
|
||||||
}
|
return diagnostics->DiagnosticsCount();
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" Diagnostic* GetDiagnosticAt(DiagnosticsHolder* diagnostics, int position){
|
Diagnostic* GetDiagnosticAt(DiagnosticsHolder* diagnostics, int position){
|
||||||
return diagnostics->GetDiagnosticAt(position);
|
return diagnostics->GetDiagnosticAt(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* GetFullDiagnostic(DiagnosticsHolder* diagnostics, Diagnostic* diag){
|
||||||
|
return diagnostics ->GetFullDiagnostic(diag).c_str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ namespace Porygon::Diagnostics {
|
||||||
return _lineStarts[i];
|
return _lineStarts[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetFullErrorMessage(Diagnostic diagnostic);
|
std::string GetFullDiagnostic(Diagnostic* diagnostic);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ TEST_CASE( "Get full diagnostic message", "[integration]" ) {
|
||||||
)");
|
)");
|
||||||
REQUIRE(script->Diagnostics -> HasErrors());
|
REQUIRE(script->Diagnostics -> HasErrors());
|
||||||
auto diags = script->Diagnostics -> GetDiagnostics();
|
auto diags = script->Diagnostics -> GetDiagnostics();
|
||||||
auto msg = script -> Diagnostics -> GetFullErrorMessage(diags[0]);
|
auto msg = script->Diagnostics->GetFullDiagnostic(&diags[0]);
|
||||||
REQUIRE(msg == "[Error] (2, 2) '\\x' is not a valid control character.");
|
REQUIRE(msg == "[Error] (2, 2) '\\x' is not a valid control character.");
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue