diff options
Diffstat (limited to 'crates/tools/src')
-rw-r--r-- | crates/tools/src/main.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs index 4a1b2ff9a..484858a1e 100644 --- a/crates/tools/src/main.rs +++ b/crates/tools/src/main.rs | |||
@@ -63,3 +63,57 @@ fn verify_installed_extensions() -> Result<()> { | |||
63 | } | 63 | } |
64 | Ok(()) | 64 | Ok(()) |
65 | } | 65 | } |
66 | |||
67 | #[cfg(target_os = "macos")] | ||
68 | mod vscode_path_helpers { | ||
69 | use super::Result; | ||
70 | use std::{path::{PathBuf}, env}; | ||
71 | use failure::bail; | ||
72 | |||
73 | pub(crate) fn append_vscode_path() -> Result<()> { | ||
74 | let vars = match env::var_os("PATH") { | ||
75 | Some(path) => path, | ||
76 | None => bail!("Could not get PATH variable from env."), | ||
77 | }; | ||
78 | |||
79 | let vscode_path = get_vscode_path()?; | ||
80 | let mut paths = env::split_paths(&vars).collect::<Vec<_>>(); | ||
81 | paths.push(vscode_path); | ||
82 | let new_paths = env::join_paths(paths)?; | ||
83 | env::set_var("PATH", &new_paths); | ||
84 | |||
85 | Ok(()) | ||
86 | } | ||
87 | |||
88 | fn get_vscode_path() -> Result<PathBuf> { | ||
89 | const COMMON_APP_PATH: &str = | ||
90 | r"/Applications/Visual Studio Code.app/Contents/Resources/app/bin"; | ||
91 | const ROOT_DIR: &str = ""; | ||
92 | let home_dir = match env::var("HOME") { | ||
93 | Ok(home) => home, | ||
94 | Err(e) => bail!("Failed getting HOME from environment with error: {}.", e), | ||
95 | }; | ||
96 | |||
97 | for dir in [ROOT_DIR, &home_dir].iter() { | ||
98 | let path = String::from(dir.clone()) + COMMON_APP_PATH; | ||
99 | let path = PathBuf::from(path); | ||
100 | if path.exists() { | ||
101 | return Ok(path); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | bail!( | ||
106 | "Could not find Visual Studio Code application. Please make sure you \ | ||
107 | have Visual Studio Code installed and try again or install extension \ | ||
108 | manually." | ||
109 | ) | ||
110 | } | ||
111 | } | ||
112 | |||
113 | #[cfg(not(target_os = "macos"))] | ||
114 | mod vscode_path_helpers { | ||
115 | use super::Result; | ||
116 | pub(crate) fn append_vscode_path() -> Result<()> { | ||
117 | Ok(()) | ||
118 | } | ||
119 | } | ||