@@ -46,34 +46,48 @@ 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+ // 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+
4964 std::string_view id;
5065 std::string_view name;
51- static constexpr std::string_view extractorName = " swift" ;
52- Format format;
5366 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
5867
68+ Format format{Format::markdown};
5969 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{" " };
6075
6176 std::optional<SwiftDiagnosticsLocation> location{};
6277
6378 // notice help links are really required only for plaintext messages, otherwise they should be
6479 // 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>
6584 constexpr SwiftDiagnostic (std::string_view id,
6685 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+ }
7791
7892 // create a JSON diagnostics for this source with the given `timestamp` and `message`
7993 // Depending on format, either a plaintextMessage or markdownMessage is used that includes both
@@ -97,6 +111,15 @@ struct SwiftDiagnostic {
97111
98112 private:
99113 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);
100123};
101124
102125inline constexpr SwiftDiagnostic::Visibility operator |(SwiftDiagnostic::Visibility lhs,
@@ -114,9 +137,12 @@ inline constexpr SwiftDiagnostic::Visibility operator&(SwiftDiagnostic::Visibili
114137constexpr SwiftDiagnostic internalError{
115138 " internal-error" ,
116139 " 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,
121147};
122148} // namespace codeql
0 commit comments