diff --git a/crates/collab/src/tests/editor_tests.rs b/crates/collab/src/tests/editor_tests.rs index 458f347efb9f1f..813e2d1793ba69 100644 --- a/crates/collab/src/tests/editor_tests.rs +++ b/crates/collab/src/tests/editor_tests.rs @@ -532,35 +532,6 @@ async fn test_collaborating_with_code_actions( Ok(Some(vec![lsp::CodeActionOrCommand::CodeAction( lsp::CodeAction { title: "Inline into all callers".to_string(), - edit: Some(lsp::WorkspaceEdit { - changes: Some( - [ - ( - lsp::Url::from_file_path("/a/main.rs").unwrap(), - vec![lsp::TextEdit::new( - lsp::Range::new( - lsp::Position::new(1, 22), - lsp::Position::new(1, 34), - ), - "4".to_string(), - )], - ), - ( - lsp::Url::from_file_path("/a/other.rs").unwrap(), - vec![lsp::TextEdit::new( - lsp::Range::new( - lsp::Position::new(0, 0), - lsp::Position::new(0, 27), - ), - "".to_string(), - )], - ), - ] - .into_iter() - .collect(), - ), - ..Default::default() - }), data: Some(json!({ "codeActionParams": { "range": { diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 06baa7f709169e..dec35373629365 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -5134,14 +5134,20 @@ impl Project { let range = action.range.to_point_utf16(buffer); cx.spawn(move |this, mut cx| async move { - if let Some(lsp_range) = action - .lsp_action - .data - .as_mut() - .and_then(|d| d.get_mut("codeActionParams")) - .and_then(|d| d.get_mut("range")) - { - *lsp_range = serde_json::to_value(&range_to_lsp(range)).unwrap(); + if action.lsp_action.command.is_none() && action.lsp_action.edit.is_none() { + // Sync the range in the action with the range in the buffer + if let Some(lsp_range) = action.lsp_action.data.as_mut().and_then(|d| { + if d.get("codeActionParams").is_some() { + // rust-analyzer puts range in data.codeActionParams + d.get_mut("codeActionParams") + .and_then(|d| d.get_mut("range")) + } else { + // elm-language-server puts range in data + d.get_mut("range") + } + }) { + *lsp_range = serde_json::to_value(&range_to_lsp(range)).unwrap(); + } action.lsp_action = lang_server .request::(action.lsp_action) .await?;