Skip to content

Commit

Permalink
Ensure that a code action to be resolved maps to exactly one supporte…
Browse files Browse the repository at this point in the history
…d code action
  • Loading branch information
snowsignal committed Apr 16, 2024
1 parent c3d69f7 commit e5c43ec
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions crates/ruff_server/src/server/api/requests/code_action_resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,23 @@ impl super::BackgroundDocumentRequestHandler for CodeActionResolve {
) -> Result<types::CodeAction> {
let document = snapshot.document();

let action_kind = SupportedCodeAction::from_kind(
let code_actions = SupportedCodeAction::from_kind(
action
.kind
.clone()
.ok_or(anyhow::anyhow!("No kind was given for code action"))
.with_failure_code(ErrorCode::InvalidParams)?,
)
.next()
.ok_or(anyhow::anyhow!("Code action was of an invalid kind"))
.with_failure_code(ErrorCode::InvalidParams)?;
.collect::<Vec<_>>();

// Ensure that the code action maps to _exactly one_ supported code action
let [action_kind] = code_actions.as_slice() else {
return Err(anyhow::anyhow!(
"Code action resolver did not expect code action kind {:?}",
action.kind.as_ref().unwrap()
))
.with_failure_code(ErrorCode::InvalidParams);
};

action.edit = match action_kind {
SupportedCodeAction::SourceFixAll => Some(
Expand Down

0 comments on commit e5c43ec

Please sign in to comment.