aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_env/src
diff options
context:
space:
mode:
authorCraig Disselkoen <[email protected]>2020-05-06 00:09:39 +0100
committerCraig Disselkoen <[email protected]>2020-05-06 00:12:56 +0100
commit1b76b4281e90292922455a9192f82a2b6b80d279 (patch)
treefa54e6d62deeec040de8b3eb4512ebe3d282c23b /crates/ra_env/src
parentc9b395be2bfcd67e045c1031143b7e8c27a6d3fb (diff)
simplify some code using early returns
Diffstat (limited to 'crates/ra_env/src')
-rw-r--r--crates/ra_env/src/lib.rs41
1 files changed, 17 insertions, 24 deletions
diff --git a/crates/ra_env/src/lib.rs b/crates/ra_env/src/lib.rs
index c7b49e997..8d6aa9268 100644
--- a/crates/ra_env/src/lib.rs
+++ b/crates/ra_env/src/lib.rs
@@ -33,31 +33,24 @@ pub fn get_path_for_executable(executable_name: impl AsRef<str>) -> Result<Strin
33 ))) 33 )))
34 } 34 }
35 } else { 35 } else {
36 let final_path: Option<String> = if is_valid_executable(executable_name) { 36 if is_valid_executable(executable_name) {
37 Some(executable_name.to_owned()) 37 return Ok(executable_name.to_owned());
38 } else { 38 }
39 if let Some(mut path) = dirs::home_dir() { 39 if let Some(mut path) = dirs::home_dir() {
40 path.push(".cargo"); 40 path.push(".cargo");
41 path.push("bin"); 41 path.push("bin");
42 path.push(executable_name); 42 path.push(executable_name);
43 if is_valid_executable(&path) { 43 if is_valid_executable(&path) {
44 Some(path.into_os_string().into_string().expect("Invalid Unicode in path")) 44 return Ok(path.into_os_string().into_string().expect("Invalid Unicode in path"));
45 } else {
46 None
47 }
48 } else {
49 None
50 } 45 }
51 }; 46 }
52 final_path.ok_or( 47 // This error message may also be caused by $PATH or $CARGO/$RUSTC/etc not being set correctly
53 // This error message may also be caused by $PATH or $CARGO/$RUSTC/etc not being set correctly 48 // for VSCode, even if they are set correctly in a terminal.
54 // for VSCode, even if they are set correctly in a terminal. 49 // On macOS in particular, launching VSCode from terminal with `code <dirname>` causes VSCode
55 // On macOS in particular, launching VSCode from terminal with `code <dirname>` causes VSCode 50 // to inherit environment variables including $PATH, $CARGO, $RUSTC, etc from that terminal;
56 // to inherit environment variables including $PATH, $CARGO, $RUSTC, etc from that terminal; 51 // but launching VSCode from Dock does not inherit environment variables from a terminal.
57 // but launching VSCode from Dock does not inherit environment variables from a terminal. 52 // For more discussion, see #3118.
58 // For more discussion, see #3118. 53 Err(Error::msg(format!("Failed to find `{}` executable. Make sure `{}` is in `$PATH`, or set `${}` to point to a valid executable.", executable_name, executable_name, env_var)))
59 Error::msg(format!("Failed to find `{}` executable. Make sure `{}` is in `$PATH`, or set `${}` to point to a valid executable.", executable_name, executable_name, env_var))
60 )
61 } 54 }
62} 55}
63 56