Skip to content

Add message to Fix constructor #4276

@MichaReiser

Description

@MichaReiser

Depends on #4183

Add a, for now, optional title or message field to Fix that will be used to replace the DiagnosticKind::autofix_title.

The motivation is that a diagnostic can have multiple potential fixes. For example, the unused variable diagnostic can recommend to either:

  • Prefix the variable with an underscore, to intentionally mark it as "this is ok"
  • Remove the variable
  • Add a noqa suppression comment.

Adding the title to the Fix instead of specifying it on the DiagnosticKind will allow us to model the different diagnostics.

It also has the advantage that the Rust compiler can enforce the requirement that each fixable DiagnosticKind has a message, because it is not stored as part of the Fix.

Tasks

  • Add new title or message field to Fix (Option<String>).
  • Change the constructor methods to take message: String as first argument, except for unspecified*, to avoid having to refactor all calls at once
  • Serialize the title/message as part of the Fix in the JSON Emitter
  • Change the MessageCodeFrame implementation to show DiagnosticKind::suggestion if present, or fall back to Fix::title if the Diagnostic has one Fix.

Metadata

Metadata

Assignees

Labels

help wantedContributions especially welcomeinternalAn internal refactor or improvement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions