@@ -46,34 +46,48 @@ struct SwiftDiagnostic {
46
46
all = 0b111 ,
47
47
};
48
48
49
+ // Notice that Tool Status Page severity is not necessarily the same as log severity, as the
50
+ // scope is different: TSP's scope is the whole analysis, log's scope is a single run
51
+ enum class Severity {
52
+ note,
53
+ warning,
54
+ error,
55
+ };
56
+
57
+ // wrapper for passing optional help links to constructor
58
+ struct HelpLinks {
59
+ std::string_view value;
60
+ };
61
+
62
+ static constexpr std::string_view extractorName = " swift" ;
63
+
49
64
std::string_view id;
50
65
std::string_view name;
51
- static constexpr std::string_view extractorName = " swift" ;
52
- Format format;
53
66
std::string_view action;
54
- // space separated if more than 1. Not a vector to allow constexpr
55
- // TODO(C++20) with vector going constexpr this can be turned to `std::vector<std::string_view>`
56
- std::string_view helpLinks;
57
- // for the moment, we only output errors, so no need to store the severity
58
67
68
+ Format format{Format::markdown};
59
69
Visibility visibility{Visibility::all};
70
+ Severity severity{Severity::error};
71
+
72
+ // space separated if more than 1. Not a vector to allow constexpr
73
+ // TODO(C++20) with vector going constexpr this can be turned to `std::vector<std::string_view>`
74
+ std::string_view helpLinks{" " };
60
75
61
76
std::optional<SwiftDiagnosticsLocation> location{};
62
77
63
78
// notice help links are really required only for plaintext messages, otherwise they should be
64
79
// directly embedded in the markdown message
80
+ // optional arguments can be any of HelpLinks, Severity, Visibility or Format to set the
81
+ // corresponding field
82
+ // TODO(C++20) this constructor won't really be necessary anymore with designated initializers
83
+ template <typename ... OptionalArgs>
65
84
constexpr SwiftDiagnostic (std::string_view id,
66
85
std::string_view name,
67
- Format format,
68
- std::string_view action = " " ,
69
- std::string_view helpLinks = " " ,
70
- Visibility visibility = Visibility::all)
71
- : id{id},
72
- name{name},
73
- format{format},
74
- action{action},
75
- helpLinks{helpLinks},
76
- visibility{visibility} {}
86
+ std::string_view action,
87
+ OptionalArgs... optionalArgs)
88
+ : id{id}, name{name}, action{action} {
89
+ (setOptionalArg (optionalArgs), ...);
90
+ }
77
91
78
92
// create a JSON diagnostics for this source with the given `timestamp` and `message`
79
93
// Depending on format, either a plaintextMessage or markdownMessage is used that includes both
@@ -97,6 +111,15 @@ struct SwiftDiagnostic {
97
111
98
112
private:
99
113
bool has (Visibility v) const ;
114
+
115
+ constexpr void setOptionalArg (HelpLinks h) { helpLinks = h.value ; }
116
+ constexpr void setOptionalArg (Format f) { format = f; }
117
+ constexpr void setOptionalArg (Visibility v) { visibility = v; }
118
+ constexpr void setOptionalArg (Severity s) { severity = s; }
119
+
120
+ // intentionally left undefined
121
+ template <typename T>
122
+ constexpr void setOptionalArg (T);
100
123
};
101
124
102
125
inline constexpr SwiftDiagnostic::Visibility operator |(SwiftDiagnostic::Visibility lhs,
@@ -114,9 +137,12 @@ inline constexpr SwiftDiagnostic::Visibility operator&(SwiftDiagnostic::Visibili
114
137
constexpr SwiftDiagnostic internalError{
115
138
" internal-error" ,
116
139
" Internal error" ,
117
- SwiftDiagnostic::Format::plaintext,
118
- /* action=*/ " " ,
119
- /* helpLinks=*/ " " ,
120
- SwiftDiagnostic::Visibility::telemetry,
140
+ " Some or all of the Swift analysis may have failed.\n "
141
+ " \n "
142
+ " If the error persists, contact support, quoting the error message and describing what "
143
+ " happened, or [open an issue in our open source repository][1].\n "
144
+ " \n "
145
+ " [1]: https://github.com/github/codeql/issues/new?labels=bug&template=ql---general.md" ,
146
+ SwiftDiagnostic::Severity::warning,
121
147
};
122
148
} // namespace codeql
0 commit comments