File tree Expand file tree Collapse file tree 7 files changed +13
-9
lines changed Expand file tree Collapse file tree 7 files changed +13
-9
lines changed Original file line number Diff line number Diff 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 ( ) ,
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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,
Original file line number Diff line number Diff line change @@ -186,7 +186,7 @@ pub(super) struct MessageCodeFrame<'a> {
186186
187187impl 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 {
Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff 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) ) ;
Original file line number Diff line number Diff 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 ( )
You can’t perform that action at this time.
0 commit comments