mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:26 +00:00
Inline DiagnosticKind
into other diagnostic types (#18074)
## Summary This PR deletes the `DiagnosticKind` type by inlining its three fields (`name`, `body`, and `suggestion`) into three other diagnostic types: `Diagnostic`, `DiagnosticMessage`, and `CacheMessage`. Instead of deferring to an internal `DiagnosticKind`, both `Diagnostic` and `DiagnosticMessage` now have their own macro-generated `AsRule` implementations. This should make both https://github.com/astral-sh/ruff/pull/18051 and another follow-up PR changing the type of `name` on `CacheMessage` easier since its type will be able to change separately from `Diagnostic` and `DiagnosticMessage`. ## Test Plan Existing tests
This commit is contained in:
parent
b35bf8ae07
commit
e2c5b83fe1
41 changed files with 604 additions and 621 deletions
|
@ -210,26 +210,34 @@ impl Workspace {
|
|||
let messages: Vec<ExpandedMessage> = messages
|
||||
.into_iter()
|
||||
.map(|message| match message {
|
||||
Message::Diagnostic(DiagnosticMessage {
|
||||
kind, range, fix, ..
|
||||
}) => ExpandedMessage {
|
||||
code: Some(kind.rule().noqa_code().to_string()),
|
||||
message: kind.body,
|
||||
start_location: source_code.line_column(range.start()).into(),
|
||||
end_location: source_code.line_column(range.end()).into(),
|
||||
fix: fix.map(|fix| ExpandedFix {
|
||||
message: kind.suggestion,
|
||||
edits: fix
|
||||
.edits()
|
||||
.iter()
|
||||
.map(|edit| ExpandedEdit {
|
||||
location: source_code.line_column(edit.start()).into(),
|
||||
end_location: source_code.line_column(edit.end()).into(),
|
||||
content: edit.content().map(ToString::to_string),
|
||||
})
|
||||
.collect(),
|
||||
}),
|
||||
},
|
||||
Message::Diagnostic(m) => {
|
||||
let rule = m.rule();
|
||||
let DiagnosticMessage {
|
||||
body,
|
||||
suggestion,
|
||||
range,
|
||||
fix,
|
||||
..
|
||||
} = m;
|
||||
ExpandedMessage {
|
||||
code: Some(rule.noqa_code().to_string()),
|
||||
message: body,
|
||||
start_location: source_code.line_column(range.start()).into(),
|
||||
end_location: source_code.line_column(range.end()).into(),
|
||||
fix: fix.map(|fix| ExpandedFix {
|
||||
message: suggestion,
|
||||
edits: fix
|
||||
.edits()
|
||||
.iter()
|
||||
.map(|edit| ExpandedEdit {
|
||||
location: source_code.line_column(edit.start()).into(),
|
||||
end_location: source_code.line_column(edit.end()).into(),
|
||||
content: edit.content().map(ToString::to_string),
|
||||
})
|
||||
.collect(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
Message::SyntaxError(_) => ExpandedMessage {
|
||||
code: None,
|
||||
message: message.body().to_string(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue