aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/main_loop/handlers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rust-analyzer/src/main_loop/handlers.rs')
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs41
1 files changed, 21 insertions, 20 deletions
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index 410c654ab..7fd691764 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -23,7 +23,6 @@ use ra_ide::{
23use ra_prof::profile; 23use ra_prof::profile;
24use ra_project_model::TargetKind; 24use ra_project_model::TargetKind;
25use ra_syntax::{AstNode, SyntaxKind, TextRange, TextSize}; 25use ra_syntax::{AstNode, SyntaxKind, TextRange, TextSize};
26use rustc_hash::FxHashMap;
27use serde::{Deserialize, Serialize}; 26use serde::{Deserialize, Serialize};
28use serde_json::to_value; 27use serde_json::to_value;
29use stdx::format_to; 28use stdx::format_to;
@@ -401,7 +400,7 @@ pub fn handle_runnables(
401 let cargo_spec = CargoTargetSpec::for_file(&world, file_id)?; 400 let cargo_spec = CargoTargetSpec::for_file(&world, file_id)?;
402 for runnable in world.analysis().runnables(file_id)? { 401 for runnable in world.analysis().runnables(file_id)? {
403 if let Some(offset) = offset { 402 if let Some(offset) = offset {
404 if !runnable.range.contains_inclusive(offset) { 403 if !runnable.nav.full_range().contains_inclusive(offset) {
405 continue; 404 continue;
406 } 405 }
407 } 406 }
@@ -422,25 +421,31 @@ pub fn handle_runnables(
422 Some(spec) => { 421 Some(spec) => {
423 for &cmd in ["check", "test"].iter() { 422 for &cmd in ["check", "test"].iter() {
424 res.push(lsp_ext::Runnable { 423 res.push(lsp_ext::Runnable {
425 range: Default::default(),
426 label: format!("cargo {} -p {}", cmd, spec.package), 424 label: format!("cargo {} -p {}", cmd, spec.package),
425 location: None,
427 kind: lsp_ext::RunnableKind::Cargo, 426 kind: lsp_ext::RunnableKind::Cargo,
428 args: vec![cmd.to_string(), "--package".to_string(), spec.package.clone()], 427 args: lsp_ext::CargoRunnable {
429 extra_args: Vec::new(), 428 workspace_root: workspace_root.map(|root| root.to_owned()),
430 env: FxHashMap::default(), 429 cargo_args: vec![
431 cwd: workspace_root.map(|root| root.to_owned()), 430 cmd.to_string(),
431 "--package".to_string(),
432 spec.package.clone(),
433 ],
434 executable_args: Vec::new(),
435 },
432 }) 436 })
433 } 437 }
434 } 438 }
435 None => { 439 None => {
436 res.push(lsp_ext::Runnable { 440 res.push(lsp_ext::Runnable {
437 range: Default::default(),
438 label: "cargo check --workspace".to_string(), 441 label: "cargo check --workspace".to_string(),
442 location: None,
439 kind: lsp_ext::RunnableKind::Cargo, 443 kind: lsp_ext::RunnableKind::Cargo,
440 args: vec!["check".to_string(), "--workspace".to_string()], 444 args: lsp_ext::CargoRunnable {
441 extra_args: Vec::new(), 445 workspace_root: workspace_root.map(|root| root.to_owned()),
442 env: FxHashMap::default(), 446 cargo_args: vec!["check".to_string(), "--workspace".to_string()],
443 cwd: workspace_root.map(|root| root.to_owned()), 447 executable_args: Vec::new(),
448 },
444 }); 449 });
445 } 450 }
446 } 451 }
@@ -782,10 +787,11 @@ pub fn handle_code_lens(
782 } 787 }
783 }; 788 };
784 789
785 let mut r = to_proto::runnable(&world, file_id, runnable)?; 790 let range = to_proto::range(&line_index, runnable.nav.range());
791 let r = to_proto::runnable(&world, file_id, runnable)?;
786 if world.config.lens.run { 792 if world.config.lens.run {
787 let lens = CodeLens { 793 let lens = CodeLens {
788 range: r.range, 794 range,
789 command: Some(Command { 795 command: Some(Command {
790 title: run_title.to_string(), 796 title: run_title.to_string(),
791 command: "rust-analyzer.runSingle".into(), 797 command: "rust-analyzer.runSingle".into(),
@@ -797,13 +803,8 @@ pub fn handle_code_lens(
797 } 803 }
798 804
799 if debugee && world.config.lens.debug { 805 if debugee && world.config.lens.debug {
800 if r.args[0] == "run" {
801 r.args[0] = "build".into();
802 } else {
803 r.args.push("--no-run".into());
804 }
805 let debug_lens = CodeLens { 806 let debug_lens = CodeLens {
806 range: r.range, 807 range,
807 command: Some(Command { 808 command: Some(Command {
808 title: "Debug".into(), 809 title: "Debug".into(),
809 command: "rust-analyzer.debugSingle".into(), 810 command: "rust-analyzer.debugSingle".into(),