@@ -46,34 +46,43 @@ struct SwiftDiagnostic {
4646 all = 0b111 ,
4747 };
4848
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+ static constexpr std::string_view extractorName = " swift" ;
58+
4959 std::string_view id;
5060 std::string_view name;
51- static constexpr std::string_view extractorName = " swift" ;
52- Format format;
5361 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
5862
63+ Format format{Format::markdown};
5964 Visibility visibility{Visibility::all};
65+ Severity severity{Severity::error};
66+
67+ // space separated if more than 1. Not a vector to allow constexpr
68+ // TODO(C++20) with vector going constexpr this can be turned to `std::vector<std::string_view>`
69+ std::string_view helpLinks{" " };
6070
6171 std::optional<SwiftDiagnosticsLocation> location{};
6272
6373 // notice help links are really required only for plaintext messages, otherwise they should be
6474 // directly embedded in the markdown message
75+ // optional arguments can be any of
76+ // * std::string_view for setting helpLinks
77+ // * Severity, Visibility or Format to set the corresponding field
78+ template <typename ... OptionalArgs>
6579 constexpr SwiftDiagnostic (std::string_view id,
6680 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} {}
81+ std::string_view action,
82+ OptionalArgs... optionalArgs)
83+ : id{id}, name{name}, action{action} {
84+ (setOptionalArg (optionalArgs), ...);
85+ }
7786
7887 // create a JSON diagnostics for this source with the given `timestamp` and `message`
7988 // Depending on format, either a plaintextMessage or markdownMessage is used that includes both
@@ -97,6 +106,11 @@ struct SwiftDiagnostic {
97106
98107 private:
99108 bool has (Visibility v) const ;
109+
110+ constexpr void setOptionalArg (std::string_view h) { helpLinks = h; }
111+ constexpr void setOptionalArg (Format f) { format = f; }
112+ constexpr void setOptionalArg (Visibility v) { visibility = v; }
113+ constexpr void setOptionalArg (Severity s) { severity = s; }
100114};
101115
102116inline constexpr SwiftDiagnostic::Visibility operator |(SwiftDiagnostic::Visibility lhs,
@@ -114,9 +128,12 @@ inline constexpr SwiftDiagnostic::Visibility operator&(SwiftDiagnostic::Visibili
114128constexpr SwiftDiagnostic internalError{
115129 " internal-error" ,
116130 " Internal error" ,
117- SwiftDiagnostic::Format::plaintext,
118- /* action=*/ " " ,
119- /* helpLinks=*/ " " ,
120- SwiftDiagnostic::Visibility::telemetry,
131+ " Some or all of the Swift analysis may have failed.\n "
132+ " \n "
133+ " If the error persists, contact support, quoting the error message and describing what "
134+ " happened, or [open an issue in our open source repository][1].\n "
135+ " \n "
136+ " [1]: https://github.com/github/codeql/issues/new?labels=bug&template=ql---general.md" ,
137+ SwiftDiagnostic::Severity::warning,
121138};
122139} // namespace codeql
0 commit comments