From 918addee2380d778b0998fc197c7037c0b09a0fa Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 8 Aug 2019 22:23:05 +0300 Subject: Show backtraces in lens runnables --- crates/ra_lsp_server/src/main_loop/handlers.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'crates/ra_lsp_server/src') diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 686ee5d12..d854b0156 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -713,7 +713,11 @@ pub fn handle_code_lens( label: Default::default(), bin: "cargo".into(), args, - env: Default::default(), + env: { + let mut m = FxHashMap::default(); + m.insert("RUST_BACKTRACE".to_string(), "short".to_string()); + m + }, cwd: workspace_root.map(|root| root.to_string_lossy().to_string()), }; -- cgit v1.2.3 From 726535a44e2b5d6a6efb1b220edf7b82cdf27d32 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 9 Aug 2019 22:18:47 +0300 Subject: Extract common logic --- crates/ra_lsp_server/src/main_loop/handlers.rs | 97 +++++++++++--------------- 1 file changed, 42 insertions(+), 55 deletions(-) (limited to 'crates/ra_lsp_server/src') 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::{ TextEdit, WorkspaceEdit, }; use ra_ide_api::{ - AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, + AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, Runnable, RunnableKind, }; use ra_prof::profile; use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; @@ -325,27 +325,13 @@ pub fn handle_runnables( continue; } } - - let args = runnable_args(&world, file_id, &runnable.kind)?; - - let r = req::Runnable { - range: runnable.range.conv_with(&line_index), - label: match &runnable.kind { - RunnableKind::Test { name } => format!("test {}", name), - RunnableKind::TestMod { path } => format!("test-mod {}", path), - RunnableKind::Bench { name } => format!("bench {}", name), - RunnableKind::Bin => "run binary".to_string(), - }, - bin: "cargo".to_string(), - args, - env: { - let mut m = FxHashMap::default(); - m.insert("RUST_BACKTRACE".to_string(), "short".to_string()); - m - }, - cwd: workspace_root.map(|root| root.to_string_lossy().to_string()), + let label = match &runnable.kind { + RunnableKind::Test { name } => format!("test {}", name), + RunnableKind::TestMod { path } => format!("test-mod {}", path), + RunnableKind::Bench { name } => format!("bench {}", name), + RunnableKind::Bin => "run binary".to_string(), }; - res.push(r); + res.push(to_lsp_runnable(&world, file_id, runnable, label)?); } let mut check_args = vec!["check".to_string()]; let label; @@ -693,46 +679,26 @@ pub fn handle_code_lens( let line_index = world.analysis().file_line_index(file_id)?; let mut lenses: Vec = Default::default(); - let workspace_root = world.workspace_root_for(file_id); // Gather runnables for runnable in world.analysis().runnables(file_id)? { let title = match &runnable.kind { - RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => Some("▶️Run Test"), - RunnableKind::Bench { .. } => Some("Run Bench"), - RunnableKind::Bin => Some("️Run"), + RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => "▶️Run Test", + RunnableKind::Bench { .. } => "Run Bench", + RunnableKind::Bin => "Run", + }; + let r = to_lsp_runnable(&world, file_id, runnable, title.to_string())?; + let lens = CodeLens { + range: r.range, + command: Some(Command { + title: title.to_string(), + command: "rust-analyzer.runSingle".into(), + arguments: Some(vec![to_value(r).unwrap()]), + }), + data: None, }; - if let Some(title) = title { - let args = runnable_args(&world, file_id, &runnable.kind)?; - let range = runnable.range.conv_with(&line_index); - - // This represents the actual command that will be run. - let r: req::Runnable = req::Runnable { - range, - label: Default::default(), - bin: "cargo".into(), - args, - env: { - let mut m = FxHashMap::default(); - m.insert("RUST_BACKTRACE".to_string(), "short".to_string()); - m - }, - cwd: workspace_root.map(|root| root.to_string_lossy().to_string()), - }; - - let lens = CodeLens { - range, - command: Some(Command { - title: title.into(), - command: "rust-analyzer.runSingle".into(), - arguments: Some(vec![to_value(r).unwrap()]), - }), - data: None, - }; - - lenses.push(lens); - } + lenses.push(lens); } // Handle impls @@ -860,6 +826,27 @@ pub fn publish_decorations( Ok(req::PublishDecorationsParams { uri, decorations: highlight(&world, file_id)? }) } +fn to_lsp_runnable( + world: &WorldSnapshot, + file_id: FileId, + runnable: Runnable, + label: String, +) -> Result { + let args = runnable_args(world, file_id, &runnable.kind)?; + let line_index = world.analysis().file_line_index(file_id)?; + Ok(req::Runnable { + range: runnable.range.conv_with(&line_index), + label, + bin: "cargo".to_string(), + args, + env: { + let mut m = FxHashMap::default(); + m.insert("RUST_BACKTRACE".to_string(), "short".to_string()); + m + }, + cwd: world.workspace_root_for(file_id).map(|root| root.to_string_lossy().to_string()), + }) +} fn highlight(world: &WorldSnapshot, file_id: FileId) -> Result> { let line_index = world.analysis().file_line_index(file_id)?; let res = world -- cgit v1.2.3 From 2c5c35bdae374b655489477280906b76fffc6a2a Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 9 Aug 2019 23:34:14 +0300 Subject: Always set the runnable name --- crates/ra_lsp_server/src/main_loop/handlers.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'crates/ra_lsp_server/src') diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index fca5700a6..4ac051c96 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -325,13 +325,7 @@ pub fn handle_runnables( continue; } } - let label = match &runnable.kind { - RunnableKind::Test { name } => format!("test {}", name), - RunnableKind::TestMod { path } => format!("test-mod {}", path), - RunnableKind::Bench { name } => format!("bench {}", name), - RunnableKind::Bin => "run binary".to_string(), - }; - res.push(to_lsp_runnable(&world, file_id, runnable, label)?); + res.push(to_lsp_runnable(&world, file_id, runnable)?); } let mut check_args = vec!["check".to_string()]; let label; @@ -686,12 +680,13 @@ pub fn handle_code_lens( RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => "▶️Run Test", RunnableKind::Bench { .. } => "Run Bench", RunnableKind::Bin => "Run", - }; - let r = to_lsp_runnable(&world, file_id, runnable, title.to_string())?; + } + .to_string(); + let r = to_lsp_runnable(&world, file_id, runnable)?; let lens = CodeLens { range: r.range, command: Some(Command { - title: title.to_string(), + title, command: "rust-analyzer.runSingle".into(), arguments: Some(vec![to_value(r).unwrap()]), }), @@ -830,10 +825,15 @@ fn to_lsp_runnable( world: &WorldSnapshot, file_id: FileId, runnable: Runnable, - label: String, ) -> Result { let args = runnable_args(world, file_id, &runnable.kind)?; let line_index = world.analysis().file_line_index(file_id)?; + let label = match &runnable.kind { + RunnableKind::Test { name } => format!("test {}", name), + RunnableKind::TestMod { path } => format!("test-mod {}", path), + RunnableKind::Bench { name } => format!("bench {}", name), + RunnableKind::Bin => "run binary".to_string(), + }; Ok(req::Runnable { range: runnable.range.conv_with(&line_index), label, -- cgit v1.2.3