@@ -46,34 +46,43 @@ 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
+ static constexpr std::string_view extractorName = " swift" ;
58
+
49
59
std::string_view id;
50
60
std::string_view name;
51
- static constexpr std::string_view extractorName = " swift" ;
52
- Format format;
53
61
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
62
63
+ Format format{Format::markdown};
59
64
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{" " };
60
70
61
71
std::optional<SwiftDiagnosticsLocation> location{};
62
72
63
73
// notice help links are really required only for plaintext messages, otherwise they should be
64
74
// 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>
65
79
constexpr SwiftDiagnostic (std::string_view id,
66
80
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
+ }
77
86
78
87
// create a JSON diagnostics for this source with the given `timestamp` and `message`
79
88
// Depending on format, either a plaintextMessage or markdownMessage is used that includes both
@@ -97,6 +106,11 @@ struct SwiftDiagnostic {
97
106
98
107
private:
99
108
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; }
100
114
};
101
115
102
116
inline constexpr SwiftDiagnostic::Visibility operator |(SwiftDiagnostic::Visibility lhs,
@@ -114,9 +128,12 @@ inline constexpr SwiftDiagnostic::Visibility operator&(SwiftDiagnostic::Visibili
114
128
constexpr SwiftDiagnostic internalError{
115
129
" internal-error" ,
116
130
" 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,
121
138
};
122
139
} // namespace codeql
0 commit comments