diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/lsp_ext.rs | 1 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop/handlers.rs | 27 | ||||
-rw-r--r-- | crates/rust-analyzer/src/to_proto.rs | 34 |
3 files changed, 24 insertions, 38 deletions
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index 4b436c301..3b957534d 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs | |||
@@ -111,7 +111,6 @@ impl Request for ResolveCodeActionRequest { | |||
111 | pub struct ResolveCodeActionParams { | 111 | pub struct ResolveCodeActionParams { |
112 | pub code_action_params: lsp_types::CodeActionParams, | 112 | pub code_action_params: lsp_types::CodeActionParams, |
113 | pub id: String, | 113 | pub id: String, |
114 | pub label: String, | ||
115 | } | 114 | } |
116 | 115 | ||
117 | pub enum OnEnter {} | 116 | pub enum OnEnter {} |
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs index 3c4064441..fab82ff7e 100644 --- a/crates/rust-analyzer/src/main_loop/handlers.rs +++ b/crates/rust-analyzer/src/main_loop/handlers.rs | |||
@@ -756,9 +756,13 @@ pub fn handle_code_action( | |||
756 | handle_fixes(&world, ¶ms, &mut res)?; | 756 | handle_fixes(&world, ¶ms, &mut res)?; |
757 | 757 | ||
758 | if world.config.client_caps.resolve_code_action { | 758 | if world.config.client_caps.resolve_code_action { |
759 | for assist in world.analysis().unresolved_assists(&world.config.assist, frange)?.into_iter() | 759 | for (index, assist) in world |
760 | .analysis() | ||
761 | .unresolved_assists(&world.config.assist, frange)? | ||
762 | .into_iter() | ||
763 | .enumerate() | ||
760 | { | 764 | { |
761 | res.push(to_proto::unresolved_code_action(&world, assist)?); | 765 | res.push(to_proto::unresolved_code_action(&world, assist, index)?); |
762 | } | 766 | } |
763 | } else { | 767 | } else { |
764 | for assist in world.analysis().resolved_assists(&world.config.assist, frange)?.into_iter() { | 768 | for assist in world.analysis().resolved_assists(&world.config.assist, frange)?.into_iter() { |
@@ -773,24 +777,19 @@ pub fn handle_resolve_code_action( | |||
773 | world: WorldSnapshot, | 777 | world: WorldSnapshot, |
774 | params: lsp_ext::ResolveCodeActionParams, | 778 | params: lsp_ext::ResolveCodeActionParams, |
775 | ) -> Result<Option<lsp_ext::SnippetWorkspaceEdit>> { | 779 | ) -> Result<Option<lsp_ext::SnippetWorkspaceEdit>> { |
776 | if !world.config.client_caps.resolve_code_action { | ||
777 | return Ok(None); | ||
778 | } | ||
779 | |||
780 | let _p = profile("handle_resolve_code_action"); | 780 | let _p = profile("handle_resolve_code_action"); |
781 | let file_id = from_proto::file_id(&world, ¶ms.code_action_params.text_document.uri)?; | 781 | let file_id = from_proto::file_id(&world, ¶ms.code_action_params.text_document.uri)?; |
782 | let line_index = world.analysis().file_line_index(file_id)?; | 782 | let line_index = world.analysis().file_line_index(file_id)?; |
783 | let range = from_proto::text_range(&line_index, params.code_action_params.range); | 783 | let range = from_proto::text_range(&line_index, params.code_action_params.range); |
784 | let frange = FileRange { file_id, range }; | 784 | let frange = FileRange { file_id, range }; |
785 | let mut res: Vec<lsp_ext::CodeAction> = Vec::new(); | ||
786 | 785 | ||
787 | for assist in world.analysis().resolved_assists(&world.config.assist, frange)?.into_iter() { | 786 | let assists = world.analysis().resolved_assists(&world.config.assist, frange)?; |
788 | res.push(to_proto::resolved_code_action(&world, assist)?); | 787 | let id_components = params.id.split(":").collect::<Vec<&str>>(); |
789 | } | 788 | let index = id_components.last().unwrap().parse::<usize>().unwrap(); |
790 | Ok(res | 789 | let id_string = id_components.first().unwrap(); |
791 | .into_iter() | 790 | let assist = &assists[index]; |
792 | .find(|action| action.id.clone().unwrap() == params.id && action.title == params.label) | 791 | assert!(assist.assist.id.0 == *id_string); |
793 | .and_then(|action| action.edit)) | 792 | Ok(to_proto::resolved_code_action(&world, assist.clone())?.edit) |
794 | } | 793 | } |
795 | 794 | ||
796 | pub fn handle_code_lens( | 795 | pub fn handle_code_lens( |
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 3672b1a26..fb33bdd5f 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs | |||
@@ -622,17 +622,12 @@ fn main() <fold>{ | |||
622 | pub(crate) fn unresolved_code_action( | 622 | pub(crate) fn unresolved_code_action( |
623 | world: &WorldSnapshot, | 623 | world: &WorldSnapshot, |
624 | assist: Assist, | 624 | assist: Assist, |
625 | index: usize, | ||
625 | ) -> Result<lsp_ext::CodeAction> { | 626 | ) -> Result<lsp_ext::CodeAction> { |
626 | let res = lsp_ext::CodeAction { | 627 | let res = lsp_ext::CodeAction { |
627 | title: assist.label, | 628 | title: assist.label, |
628 | id: Some(assist.id.0.to_owned()), | 629 | id: Some(format!("{}:{}", assist.id.0.to_owned(), index.to_string())), |
629 | group: assist.group.and_then(|it| { | 630 | group: assist.group.filter(|_| world.config.client_caps.code_action_group).map(|gr| gr.0), |
630 | if world.config.client_caps.code_action_group { | ||
631 | None | ||
632 | } else { | ||
633 | Some(it.0) | ||
634 | } | ||
635 | }), | ||
636 | kind: Some(String::new()), | 631 | kind: Some(String::new()), |
637 | edit: None, | 632 | edit: None, |
638 | command: None, | 633 | command: None, |
@@ -644,21 +639,14 @@ pub(crate) fn resolved_code_action( | |||
644 | world: &WorldSnapshot, | 639 | world: &WorldSnapshot, |
645 | assist: ResolvedAssist, | 640 | assist: ResolvedAssist, |
646 | ) -> Result<lsp_ext::CodeAction> { | 641 | ) -> Result<lsp_ext::CodeAction> { |
647 | let res = lsp_ext::CodeAction { | 642 | let change = assist.source_change; |
648 | title: assist.assist.label, | 643 | unresolved_code_action(world, assist.assist, 0).and_then(|it| { |
649 | id: Some(assist.assist.id.0.to_owned()), | 644 | Ok(lsp_ext::CodeAction { |
650 | group: assist.assist.group.and_then(|it| { | 645 | id: None, |
651 | if world.config.client_caps.code_action_group { | 646 | edit: Some(snippet_workspace_edit(world, change)?), |
652 | None | 647 | ..it |
653 | } else { | 648 | }) |
654 | Some(it.0) | 649 | }) |
655 | } | ||
656 | }), | ||
657 | kind: Some(String::new()), | ||
658 | edit: Some(snippet_workspace_edit(world, assist.source_change)?), | ||
659 | command: None, | ||
660 | }; | ||
661 | Ok(res) | ||
662 | } | 650 | } |
663 | 651 | ||
664 | pub(crate) fn runnable( | 652 | pub(crate) fn runnable( |