aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Rakhmanov <[email protected]>2020-06-03 17:39:01 +0100
committerMikhail Rakhmanov <[email protected]>2020-06-03 17:39:01 +0100
commitbacd0428fa0fd744eb0aac6d5d7abd18c6c707b7 (patch)
tree54ceaaeec17255753cf886da1fffc640e50df254
parentcb482e6351c4005f29bb89d38c64c4e3f93d7a6d (diff)
Fix review comments
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs1
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs27
-rw-r--r--crates/rust-analyzer/src/to_proto.rs34
-rw-r--r--editors/code/src/client.ts2
-rw-r--r--editors/code/src/lsp_ext.ts1
5 files changed, 24 insertions, 41 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 {
111pub struct ResolveCodeActionParams { 111pub 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
117pub enum OnEnter {} 116pub 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, &params, &mut res)?; 756 handle_fixes(&world, &params, &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, &params.code_action_params.text_document.uri)?; 781 let file_id = from_proto::file_id(&world, &params.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
796pub fn handle_code_lens( 795pub 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>{
622pub(crate) fn unresolved_code_action( 622pub(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
664pub(crate) fn runnable( 652pub(crate) fn runnable(
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index a25091f79..40ad1e3cd 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -61,8 +61,6 @@ export function createClient(serverPath: string, cwd: string): lc.LanguageClient
61 const id = (item as any).id; 61 const id = (item as any).id;
62 const resolveParams: ra.ResolveCodeActionParams = { 62 const resolveParams: ra.ResolveCodeActionParams = {
63 id: id, 63 id: id,
64 // TODO: delete after discussions if needed
65 label: item.title,
66 codeActionParams: params 64 codeActionParams: params
67 }; 65 };
68 action.command = { 66 action.command = {
diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts
index 35d73ce31..9793b926c 100644
--- a/editors/code/src/lsp_ext.ts
+++ b/editors/code/src/lsp_ext.ts
@@ -35,7 +35,6 @@ export const parentModule = new lc.RequestType<lc.TextDocumentPositionParams, lc
35 35
36export interface ResolveCodeActionParams { 36export interface ResolveCodeActionParams {
37 id: string; 37 id: string;
38 label: string;
39 codeActionParams: lc.CodeActionParams; 38 codeActionParams: lc.CodeActionParams;
40} 39}
41export const resolveCodeAction = new lc.RequestType<ResolveCodeActionParams, lc.WorkspaceEdit, unknown>('experimental/resolveCodeAction'); 40export const resolveCodeAction = new lc.RequestType<ResolveCodeActionParams, lc.WorkspaceEdit, unknown>('experimental/resolveCodeAction');