diff options
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index a592f0a12..8e43f0575 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -3,6 +3,7 @@ | |||
3 | 3 | ||
4 | use std::{fmt::Write as _, io::Write as _}; | 4 | use std::{fmt::Write as _, io::Write as _}; |
5 | 5 | ||
6 | use either::Either; | ||
6 | use lsp_server::ErrorCode; | 7 | use lsp_server::ErrorCode; |
7 | use lsp_types::{ | 8 | use lsp_types::{ |
8 | CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem, | 9 | CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem, |
@@ -644,7 +645,6 @@ pub fn handle_code_action( | |||
644 | let line_index = world.analysis().file_line_index(file_id)?; | 645 | let line_index = world.analysis().file_line_index(file_id)?; |
645 | let range = params.range.conv_with(&line_index); | 646 | let range = params.range.conv_with(&line_index); |
646 | 647 | ||
647 | let assists = world.analysis().assists(FileRange { file_id, range })?.into_iter(); | ||
648 | let diagnostics = world.analysis().diagnostics(file_id)?; | 648 | let diagnostics = world.analysis().diagnostics(file_id)?; |
649 | let mut res = CodeActionResponse::default(); | 649 | let mut res = CodeActionResponse::default(); |
650 | 650 | ||
@@ -681,10 +681,12 @@ pub fn handle_code_action( | |||
681 | continue; | 681 | continue; |
682 | } | 682 | } |
683 | 683 | ||
684 | let edits = vec![TextEdit::new(fix.location.range, fix.replacement.clone())]; | 684 | let edit = { |
685 | let mut edit_map = std::collections::HashMap::new(); | 685 | let edits = vec![TextEdit::new(fix.location.range, fix.replacement.clone())]; |
686 | edit_map.insert(fix.location.uri.clone(), edits); | 686 | let mut edit_map = std::collections::HashMap::new(); |
687 | let edit = WorkspaceEdit::new(edit_map); | 687 | edit_map.insert(fix.location.uri.clone(), edits); |
688 | WorkspaceEdit::new(edit_map) | ||
689 | }; | ||
688 | 690 | ||
689 | let action = CodeAction { | 691 | let action = CodeAction { |
690 | title: fix.title.clone(), | 692 | title: fix.title.clone(), |
@@ -697,19 +699,32 @@ pub fn handle_code_action( | |||
697 | res.push(action.into()); | 699 | res.push(action.into()); |
698 | } | 700 | } |
699 | 701 | ||
700 | for assist in assists { | 702 | for assist in world.analysis().assists(FileRange { file_id, range })?.into_iter() { |
701 | let title = assist.change.label.clone(); | 703 | let title = assist.label.clone(); |
702 | let edit = assist.change.try_conv_with(&world)?; | ||
703 | 704 | ||
704 | let command = Command { | 705 | let command = match assist.change_data { |
705 | title, | 706 | Either::Left(change) => Command { |
706 | command: "rust-analyzer.applySourceChange".to_string(), | 707 | title, |
707 | arguments: Some(vec![to_value(edit).unwrap()]), | 708 | command: "rust-analyzer.applySourceChange".to_string(), |
709 | arguments: Some(vec![to_value(change.try_conv_with(&world)?)?]), | ||
710 | }, | ||
711 | Either::Right(changes) => Command { | ||
712 | title, | ||
713 | command: "rust-analyzer.selectAndApplySourceChange".to_string(), | ||
714 | arguments: Some(vec![to_value( | ||
715 | changes | ||
716 | .into_iter() | ||
717 | .map(|change| change.try_conv_with(&world)) | ||
718 | .collect::<Result<Vec<_>>>()?, | ||
719 | )?]), | ||
720 | }, | ||
708 | }; | 721 | }; |
722 | |||
709 | let action = CodeAction { | 723 | let action = CodeAction { |
710 | title: command.title.clone(), | 724 | title: command.title.clone(), |
711 | kind: match assist.id { | 725 | kind: match assist.id { |
712 | AssistId("introduce_variable") => Some("refactor.extract.variable".to_string()), | 726 | AssistId("introduce_variable") => Some("refactor.extract.variable".to_string()), |
727 | AssistId("add_custom_impl") => Some("refactor.rewrite.add_custom_impl".to_string()), | ||
713 | _ => None, | 728 | _ => None, |
714 | }, | 729 | }, |
715 | diagnostics: None, | 730 | diagnostics: None, |
@@ -952,6 +967,7 @@ pub fn handle_inlay_hints( | |||
952 | range: api_type.range.conv_with(&line_index), | 967 | range: api_type.range.conv_with(&line_index), |
953 | kind: match api_type.kind { | 968 | kind: match api_type.kind { |
954 | ra_ide::InlayKind::TypeHint => InlayKind::TypeHint, | 969 | ra_ide::InlayKind::TypeHint => InlayKind::TypeHint, |
970 | ra_ide::InlayKind::ParameterHint => InlayKind::ParameterHint, | ||
955 | }, | 971 | }, |
956 | }) | 972 | }) |
957 | .collect()) | 973 | .collect()) |