Support adding filename to diagnostic.
This commit is contained in:
@@ -4,19 +4,23 @@
|
||||
#include "../TextSpan.hpp"
|
||||
#include "DiagnosticLevel.hpp"
|
||||
#include "DiagnosticType.hpp"
|
||||
|
||||
namespace ElohimScript::Diagnostics {
|
||||
class Diagnostic {
|
||||
DiagnosticLevel _level;
|
||||
DiagnosticType _type;
|
||||
std::u8string_view _scriptName;
|
||||
TextSpan _span;
|
||||
|
||||
public:
|
||||
inline Diagnostic(DiagnosticLevel level, DiagnosticType type, TextSpan span)
|
||||
: _level(level), _type(type), _span(span) {}
|
||||
inline Diagnostic(DiagnosticLevel level, DiagnosticType type, const std::u8string_view& scriptName,
|
||||
TextSpan span)
|
||||
: _level(level), _type(type), _scriptName(scriptName), _span(span) {}
|
||||
|
||||
[[nodiscard]] inline DiagnosticLevel GetLevel() const noexcept { return _level; }
|
||||
[[nodiscard]] inline DiagnosticType GetType() const noexcept { return _type; }
|
||||
[[nodiscard]] inline const TextSpan& GetSpan() const noexcept { return _span; }
|
||||
[[nodiscard]] inline const std::u8string_view& GetScriptName() const noexcept { return _scriptName; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -9,14 +9,24 @@ namespace ElohimScript::Diagnostics {
|
||||
std::vector<Diagnostic> _messages;
|
||||
|
||||
public:
|
||||
inline void Log(DiagnosticLevel level, DiagnosticType type, TextSpan span) {
|
||||
_messages.emplace_back(level, type, span);
|
||||
inline void Log(DiagnosticLevel level, DiagnosticType type, std::u8string_view scriptName, TextSpan span) {
|
||||
_messages.emplace_back(level, type, scriptName, span);
|
||||
}
|
||||
inline void LogTrace(DiagnosticType type, std::u8string_view scriptName, TextSpan span) {
|
||||
Log(DiagnosticLevel::Trace, type, scriptName, span);
|
||||
}
|
||||
inline void LogInfo(DiagnosticType type, std::u8string_view scriptName, TextSpan span) {
|
||||
Log(DiagnosticLevel::Information, type, scriptName, span);
|
||||
}
|
||||
inline void LogWarning(DiagnosticType type, std::u8string_view scriptName, TextSpan span) {
|
||||
Log(DiagnosticLevel::Warning, type, scriptName, span);
|
||||
}
|
||||
inline void LogError(DiagnosticType type, std::u8string_view scriptName, TextSpan span) {
|
||||
Log(DiagnosticLevel::Error, type, scriptName, span);
|
||||
}
|
||||
inline void LogCritical(DiagnosticType type, std::u8string_view scriptName, TextSpan span) {
|
||||
Log(DiagnosticLevel::Critical, type, scriptName, span);
|
||||
}
|
||||
inline void LogTrace(DiagnosticType type, TextSpan span) { Log(DiagnosticLevel::Trace, type, span); }
|
||||
inline void LogInfo(DiagnosticType type, TextSpan span) { Log(DiagnosticLevel::Information, type, span); }
|
||||
inline void LogWarning(DiagnosticType type, TextSpan span) { Log(DiagnosticLevel::Warning, type, span); }
|
||||
inline void LogError(DiagnosticType type, TextSpan span) { Log(DiagnosticLevel::Error, type, span); }
|
||||
inline void LogCritical(DiagnosticType type, TextSpan span) { Log(DiagnosticLevel::Critical, type, span); }
|
||||
|
||||
[[nodiscard]] const std::vector<Diagnostic>& GetMessages() const noexcept { return _messages; }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user