aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/to_proto.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-02-14 16:36:44 +0000
committerAleksey Kladov <[email protected]>2021-02-14 16:36:44 +0000
commit9852537809a78b73a0e17eb2dfdf2ab5b07f5eae (patch)
tree42b14c7734070b99e9d625d7cfe3e901586de468 /crates/rust-analyzer/src/to_proto.rs
parentd50a37d3aa473937919030b39587df3d93f9bd8c (diff)
Make it clear which client-side commands we use
Diffstat (limited to 'crates/rust-analyzer/src/to_proto.rs')
-rw-r--r--crates/rust-analyzer/src/to_proto.rs119
1 files changed, 84 insertions, 35 deletions
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 29fac96fb..8a2b4d9bd 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -229,11 +229,7 @@ pub(crate) fn completion_item(
229 } 229 }
230 230
231 if completion_item.trigger_call_info() { 231 if completion_item.trigger_call_info() {
232 res.command = Some(lsp_types::Command { 232 res.command = Some(command::trigger_parameter_hints());
233 title: "triggerParameterHints".into(),
234 command: "editor.action.triggerParameterHints".into(),
235 arguments: None,
236 });
237 } 233 }
238 234
239 let mut all_results = match completion_item.ref_match() { 235 let mut all_results = match completion_item.ref_match() {
@@ -878,17 +874,10 @@ pub(crate) fn code_lens(
878 let r = runnable(&snap, run.nav.file_id, run)?; 874 let r = runnable(&snap, run.nav.file_id, run)?;
879 875
880 let command = if debug { 876 let command = if debug {
881 lsp_types::Command { 877 command::debug_single(&r)
882 title: action.run_title.to_string(),
883 command: "rust-analyzer.runSingle".into(),
884 arguments: Some(vec![to_value(r).unwrap()]),
885 }
886 } else { 878 } else {
887 lsp_types::Command { 879 let title = action.run_title.to_string();
888 title: "Debug".into(), 880 command::run_single(&r, &title)
889 command: "rust-analyzer.debugSingle".into(),
890 arguments: Some(vec![to_value(r).unwrap()]),
891 }
892 }; 881 };
893 882
894 Ok(lsp_types::CodeLens { range: annotation_range, command: Some(command), data: None }) 883 Ok(lsp_types::CodeLens { range: annotation_range, command: Some(command), data: None })
@@ -922,7 +911,7 @@ pub(crate) fn code_lens(
922 }) 911 })
923 .collect(); 912 .collect();
924 913
925 show_references_command( 914 command::show_references(
926 implementation_title(locations.len()), 915 implementation_title(locations.len()),
927 &url, 916 &url,
928 position, 917 position,
@@ -951,7 +940,12 @@ pub(crate) fn code_lens(
951 let locations: Vec<lsp_types::Location> = 940 let locations: Vec<lsp_types::Location> =
952 ranges.into_iter().filter_map(|range| location(snap, range).ok()).collect(); 941 ranges.into_iter().filter_map(|range| location(snap, range).ok()).collect();
953 942
954 show_references_command(reference_title(locations.len()), &url, position, locations) 943 command::show_references(
944 reference_title(locations.len()),
945 &url,
946 position,
947 locations,
948 )
955 }); 949 });
956 950
957 Ok(lsp_types::CodeLens { 951 Ok(lsp_types::CodeLens {
@@ -963,24 +957,79 @@ pub(crate) fn code_lens(
963 } 957 }
964} 958}
965 959
966pub(crate) fn show_references_command( 960pub(crate) mod command {
967 title: String, 961 use ide::{FileRange, NavigationTarget};
968 uri: &lsp_types::Url, 962 use serde_json::to_value;
969 position: lsp_types::Position, 963
970 locations: Vec<lsp_types::Location>, 964 use crate::{
971) -> lsp_types::Command { 965 global_state::GlobalStateSnapshot,
972 // We cannot use the 'editor.action.showReferences' command directly 966 lsp_ext,
973 // because that command requires vscode types which we convert in the handler 967 to_proto::{location, location_link},
974 // on the client side. 968 };
975 969
976 lsp_types::Command { 970 pub(crate) fn show_references(
977 title, 971 title: String,
978 command: "rust-analyzer.showReferences".into(), 972 uri: &lsp_types::Url,
979 arguments: Some(vec![ 973 position: lsp_types::Position,
980 to_value(uri).unwrap(), 974 locations: Vec<lsp_types::Location>,
981 to_value(position).unwrap(), 975 ) -> lsp_types::Command {
982 to_value(locations).unwrap(), 976 // We cannot use the 'editor.action.showReferences' command directly
983 ]), 977 // because that command requires vscode types which we convert in the handler
978 // on the client side.
979
980 lsp_types::Command {
981 title,
982 command: "rust-analyzer.showReferences".into(),
983 arguments: Some(vec![
984 to_value(uri).unwrap(),
985 to_value(position).unwrap(),
986 to_value(locations).unwrap(),
987 ]),
988 }
989 }
990
991 pub(crate) fn run_single(runnable: &lsp_ext::Runnable, title: &str) -> lsp_types::Command {
992 lsp_types::Command {
993 title: title.to_string(),
994 command: "rust-analyzer.runSingle".into(),
995 arguments: Some(vec![to_value(runnable).unwrap()]),
996 }
997 }
998
999 pub(crate) fn debug_single(runnable: &lsp_ext::Runnable) -> lsp_types::Command {
1000 lsp_types::Command {
1001 title: "Debug".into(),
1002 command: "rust-analyzer.debugSingle".into(),
1003 arguments: Some(vec![to_value(runnable).unwrap()]),
1004 }
1005 }
1006
1007 pub(crate) fn goto_location(
1008 snap: &GlobalStateSnapshot,
1009 nav: &NavigationTarget,
1010 ) -> Option<lsp_types::Command> {
1011 let value = if snap.config.location_link() {
1012 let link = location_link(snap, None, nav.clone()).ok()?;
1013 to_value(link).ok()?
1014 } else {
1015 let range = FileRange { file_id: nav.file_id, range: nav.focus_or_full_range() };
1016 let location = location(snap, range).ok()?;
1017 to_value(location).ok()?
1018 };
1019
1020 Some(lsp_types::Command {
1021 title: nav.name.to_string(),
1022 command: "rust-analyzer.gotoLocation".into(),
1023 arguments: Some(vec![value]),
1024 })
1025 }
1026
1027 pub(crate) fn trigger_parameter_hints() -> lsp_types::Command {
1028 lsp_types::Command {
1029 title: "triggerParameterHints".into(),
1030 command: "editor.action.triggerParameterHints".into(),
1031 arguments: None,
1032 }
984 } 1033 }
985} 1034}
986 1035