aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs97
1 files changed, 42 insertions, 55 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index d854b0156..fca5700a6 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -9,7 +9,7 @@ use lsp_types::{
9 TextEdit, WorkspaceEdit, 9 TextEdit, WorkspaceEdit,
10}; 10};
11use ra_ide_api::{ 11use ra_ide_api::{
12 AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, 12 AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, Runnable, RunnableKind,
13}; 13};
14use ra_prof::profile; 14use ra_prof::profile;
15use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; 15use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
@@ -325,27 +325,13 @@ pub fn handle_runnables(
325 continue; 325 continue;
326 } 326 }
327 } 327 }
328 328 let label = match &runnable.kind {
329 let args = runnable_args(&world, file_id, &runnable.kind)?; 329 RunnableKind::Test { name } => format!("test {}", name),
330 330 RunnableKind::TestMod { path } => format!("test-mod {}", path),
331 let r = req::Runnable { 331 RunnableKind::Bench { name } => format!("bench {}", name),
332 range: runnable.range.conv_with(&line_index), 332 RunnableKind::Bin => "run binary".to_string(),
333 label: match &runnable.kind {
334 RunnableKind::Test { name } => format!("test {}", name),
335 RunnableKind::TestMod { path } => format!("test-mod {}", path),
336 RunnableKind::Bench { name } => format!("bench {}", name),
337 RunnableKind::Bin => "run binary".to_string(),
338 },
339 bin: "cargo".to_string(),
340 args,
341 env: {
342 let mut m = FxHashMap::default();
343 m.insert("RUST_BACKTRACE".to_string(), "short".to_string());
344 m
345 },
346 cwd: workspace_root.map(|root| root.to_string_lossy().to_string()),
347 }; 333 };
348 res.push(r); 334 res.push(to_lsp_runnable(&world, file_id, runnable, label)?);
349 } 335 }
350 let mut check_args = vec!["check".to_string()]; 336 let mut check_args = vec!["check".to_string()];
351 let label; 337 let label;
@@ -693,46 +679,26 @@ pub fn handle_code_lens(
693 let line_index = world.analysis().file_line_index(file_id)?; 679 let line_index = world.analysis().file_line_index(file_id)?;
694 680
695 let mut lenses: Vec<CodeLens> = Default::default(); 681 let mut lenses: Vec<CodeLens> = Default::default();
696 let workspace_root = world.workspace_root_for(file_id);
697 682
698 // Gather runnables 683 // Gather runnables
699 for runnable in world.analysis().runnables(file_id)? { 684 for runnable in world.analysis().runnables(file_id)? {
700 let title = match &runnable.kind { 685 let title = match &runnable.kind {
701 RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => Some("▶️Run Test"), 686 RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => "▶️Run Test",
702 RunnableKind::Bench { .. } => Some("Run Bench"), 687 RunnableKind::Bench { .. } => "Run Bench",
703 RunnableKind::Bin => Some("️Run"), 688 RunnableKind::Bin => "Run",
689 };
690 let r = to_lsp_runnable(&world, file_id, runnable, title.to_string())?;
691 let lens = CodeLens {
692 range: r.range,
693 command: Some(Command {
694 title: title.to_string(),
695 command: "rust-analyzer.runSingle".into(),
696 arguments: Some(vec![to_value(r).unwrap()]),
697 }),
698 data: None,
704 }; 699 };
705 700
706 if let Some(title) = title { 701 lenses.push(lens);
707 let args = runnable_args(&world, file_id, &runnable.kind)?;
708 let range = runnable.range.conv_with(&line_index);
709
710 // This represents the actual command that will be run.
711 let r: req::Runnable = req::Runnable {
712 range,
713 label: Default::default(),
714 bin: "cargo".into(),
715 args,
716 env: {
717 let mut m = FxHashMap::default();
718 m.insert("RUST_BACKTRACE".to_string(), "short".to_string());
719 m
720 },
721 cwd: workspace_root.map(|root| root.to_string_lossy().to_string()),
722 };
723
724 let lens = CodeLens {
725 range,
726 command: Some(Command {
727 title: title.into(),
728 command: "rust-analyzer.runSingle".into(),
729 arguments: Some(vec![to_value(r).unwrap()]),
730 }),
731 data: None,
732 };
733
734 lenses.push(lens);
735 }
736 } 702 }
737 703
738 // Handle impls 704 // Handle impls
@@ -860,6 +826,27 @@ pub fn publish_decorations(
860 Ok(req::PublishDecorationsParams { uri, decorations: highlight(&world, file_id)? }) 826 Ok(req::PublishDecorationsParams { uri, decorations: highlight(&world, file_id)? })
861} 827}
862 828
829fn to_lsp_runnable(
830 world: &WorldSnapshot,
831 file_id: FileId,
832 runnable: Runnable,
833 label: String,
834) -> Result<req::Runnable> {
835 let args = runnable_args(world, file_id, &runnable.kind)?;
836 let line_index = world.analysis().file_line_index(file_id)?;
837 Ok(req::Runnable {
838 range: runnable.range.conv_with(&line_index),
839 label,
840 bin: "cargo".to_string(),
841 args,
842 env: {
843 let mut m = FxHashMap::default();
844 m.insert("RUST_BACKTRACE".to_string(), "short".to_string());
845 m
846 },
847 cwd: world.workspace_root_for(file_id).map(|root| root.to_string_lossy().to_string()),
848 })
849}
863fn highlight(world: &WorldSnapshot, file_id: FileId) -> Result<Vec<Decoration>> { 850fn highlight(world: &WorldSnapshot, file_id: FileId) -> Result<Vec<Decoration>> {
864 let line_index = world.analysis().file_line_index(file_id)?; 851 let line_index = world.analysis().file_line_index(file_id)?;
865 let res = world 852 let res = world