Skip to content

Commit

Permalink
Fix resolve code action for elm-language-server
Browse files Browse the repository at this point in the history
Co-authored-by: Jared M. Smith <absynce@gmail.com>
  • Loading branch information
w0rm and absynce committed Feb 9, 2024
1 parent 04e1641 commit 1a9a5eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 37 deletions.
29 changes: 0 additions & 29 deletions crates/collab/src/tests/editor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
22 changes: 14 additions & 8 deletions crates/project/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<lsp::request::CodeActionResolveRequest>(action.lsp_action)
.await?;
Expand Down

0 comments on commit 1a9a5eb

Please sign in to comment.