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 4d28e57
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ 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 4d28e57

Please sign in to comment.