Skip to content

Commit 12226e3

Browse files
committed
Diagnostic::suggestion -> first_help_text, update docs
1 parent a167803 commit 12226e3

File tree

7 files changed

+13
-9
lines changed

7 files changed

+13
-9
lines changed

crates/ruff/src/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ impl LintCacheData {
454454
CacheMessage {
455455
rule,
456456
body: msg.body().to_string(),
457-
suggestion: msg.suggestion().map(ToString::to_string),
457+
suggestion: msg.first_help_text().map(ToString::to_string),
458458
range: msg.expect_range(),
459459
parent: msg.parent(),
460460
fix: msg.fix().cloned(),

crates/ruff_db/src/diagnostic/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,14 @@ impl Diagnostic {
384384
self.primary_message()
385385
}
386386

387-
/// Returns the fix suggestion for the violation.
388-
pub fn suggestion(&self) -> Option<&str> {
387+
/// Returns the message of the first sub-diagnostic with a `Help` severity.
388+
///
389+
/// Note that this is used as the fix title/suggestion for some of Ruff's output formats, but in
390+
/// general this is not the guaranteed meaning of such a message.
391+
pub fn first_help_text(&self) -> Option<&str> {
389392
self.sub_diagnostics()
390-
.first()
393+
.iter()
394+
.find(|sub| matches!(sub.inner.severity, Severity::Help))
391395
.map(|sub| sub.inner.message.as_str())
392396
}
393397

crates/ruff_db/src/diagnostic/render/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub(super) fn diagnostic_to_json<'a>(
8787

8888
let fix = diagnostic.fix().map(|fix| JsonFix {
8989
applicability: fix.applicability(),
90-
message: diagnostic.suggestion(),
90+
message: diagnostic.first_help_text(),
9191
edits: ExpandedEdits {
9292
edits: fix.edits(),
9393
notebook_index,

crates/ruff_linter/src/message/text.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub(super) struct MessageCodeFrame<'a> {
186186

187187
impl Display for MessageCodeFrame<'_> {
188188
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
189-
let suggestion = self.message.suggestion();
189+
let suggestion = self.message.first_help_text();
190190
let footers = if let Some(suggestion) = suggestion {
191191
vec![Level::Help.title(suggestion)]
192192
} else {

crates/ruff_linter/src/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ Either ensure you always emit a fix or change `Violation::FIX_AVAILABILITY` to e
272272
}
273273

274274
assert!(
275-
!(fixable && diagnostic.suggestion().is_none()),
275+
!(fixable && diagnostic.first_help_text().is_none()),
276276
"Diagnostic emitted by {rule:?} is fixable but \
277277
`Violation::fix_title` returns `None`"
278278
);

crates/ruff_server/src/lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn to_lsp_diagnostic(
238238
let name = diagnostic.name();
239239
let body = diagnostic.body().to_string();
240240
let fix = diagnostic.fix();
241-
let suggestion = diagnostic.suggestion();
241+
let suggestion = diagnostic.first_help_text();
242242
let code = diagnostic.secondary_code();
243243

244244
let fix = fix.and_then(|fix| fix.applies(Applicability::Unsafe).then_some(fix));

crates/ruff_wasm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl Workspace {
234234
start_location: source_code.line_column(msg.expect_range().start()).into(),
235235
end_location: source_code.line_column(msg.expect_range().end()).into(),
236236
fix: msg.fix().map(|fix| ExpandedFix {
237-
message: msg.suggestion().map(ToString::to_string),
237+
message: msg.first_help_text().map(ToString::to_string),
238238
edits: fix
239239
.edits()
240240
.iter()

0 commit comments

Comments
 (0)