@@ -18,8 +18,8 @@ use lsp_types::{
1818 TextDocumentIdentifier , Url , WorkspaceEdit ,
1919} ;
2020use ra_ide:: {
21- FileId , FilePosition , FileRange , HoverAction , Query , RangeInfo , Runnable , RunnableKind , SearchScope ,
22- TextEdit ,
21+ FileId , FilePosition , FileRange , HoverAction , Query , RangeInfo , Runnable , RunnableKind ,
22+ SearchScope , TextEdit ,
2323} ;
2424use ra_prof:: profile;
2525use ra_project_model:: TargetKind ;
@@ -403,12 +403,12 @@ pub fn handle_runnables(
403403 if !runnable. nav . full_range ( ) . contains_inclusive ( offset) {
404404 continue ;
405405 }
406- }
406+ }
407407 if is_lib_target ( & runnable, cargo_spec. as_ref ( ) ) {
408408 continue ;
409409 }
410410
411- res. push ( to_proto:: runnable ( & snap, file_id, runnable) ?) ;
411+ res. push ( to_proto:: runnable ( & snap, file_id, & runnable) ?) ;
412412 }
413413
414414 // Add `cargo check` and `cargo test` for the whole package
@@ -550,7 +550,7 @@ pub fn handle_hover(
550550 } ) ,
551551 range : Some ( range) ,
552552 } ,
553- actions : prepare_hover_actions ( & snap, info. info . actions ( ) ) ,
553+ actions : prepare_hover_actions ( & snap, position . file_id , info. info . actions ( ) ) ,
554554 } ;
555555
556556 Ok ( Some ( hover) )
@@ -818,7 +818,7 @@ pub fn handle_code_lens(
818818
819819 let action = runnable. action ( ) ;
820820 let range = to_proto:: range ( & line_index, runnable. nav . range ( ) ) ;
821- let r = to_proto:: runnable ( & snap, file_id, runnable) ?;
821+ let r = to_proto:: runnable ( & snap, file_id, & runnable) ?;
822822 if snap. config . lens . run {
823823 let lens = CodeLens {
824824 range,
@@ -829,11 +829,8 @@ pub fn handle_code_lens(
829829 }
830830
831831 if action. debugee && snap. config . lens . debug {
832- let debug_lens = CodeLens {
833- range,
834- command : Some ( debug_single_command ( r) ) ,
835- data : None ,
836- } ;
832+ let debug_lens =
833+ CodeLens { range, command : Some ( debug_single_command ( r) ) , data : None } ;
837834 lenses. push ( debug_lens) ;
838835 }
839836 }
@@ -1183,8 +1180,33 @@ fn show_impl_command_link(
11831180 None
11841181}
11851182
1183+ fn to_runnable_action (
1184+ snap : & GlobalStateSnapshot ,
1185+ file_id : FileId ,
1186+ runnable : & Runnable ,
1187+ ) -> Option < lsp_ext:: CommandLinkGroup > {
1188+ to_proto:: runnable ( snap, file_id, runnable) . ok ( ) . map ( |r| {
1189+ let mut group = lsp_ext:: CommandLinkGroup :: default ( ) ;
1190+
1191+ let action = runnable. action ( ) ;
1192+ if snap. config . hover . run {
1193+ let run_command = run_single_command ( & r, action. run_title ) ;
1194+ group. commands . push ( to_command_link ( run_command, r. label . clone ( ) ) ) ;
1195+ }
1196+
1197+ if snap. config . hover . debug {
1198+ let hint = r. label . clone ( ) ;
1199+ let dbg_command = debug_single_command ( r) ;
1200+ group. commands . push ( to_command_link ( dbg_command, hint) ) ;
1201+ }
1202+
1203+ group
1204+ } )
1205+ }
1206+
11861207fn prepare_hover_actions (
11871208 snap : & GlobalStateSnapshot ,
1209+ file_id : FileId ,
11881210 actions : & [ HoverAction ] ,
11891211) -> Vec < lsp_ext:: CommandLinkGroup > {
11901212 if snap. config . hover . none ( ) || !snap. config . client_caps . hover_actions {
@@ -1195,6 +1217,7 @@ fn prepare_hover_actions(
11951217 . iter ( )
11961218 . filter_map ( |it| match it {
11971219 HoverAction :: Implementaion ( position) => show_impl_command_link ( snap, position) ,
1220+ HoverAction :: Runnable ( r) => to_runnable_action ( snap, file_id, r) ,
11981221 } )
11991222 . collect ( )
12001223}
@@ -1205,10 +1228,10 @@ fn is_lib_target(runnable: &Runnable, cargo_spec: Option<&CargoTargetSpec>) -> b
12051228 if let Some ( spec) = cargo_spec {
12061229 match spec. target_kind {
12071230 TargetKind :: Bin => return true ,
1208- _ => ( )
1231+ _ => ( ) ,
12091232 }
12101233 }
12111234 }
12121235
12131236 false
1214- }
1237+ }
0 commit comments