Skip to content

Commit

Permalink
fix: cannot run if vscode didn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
shiipou committed Sep 5, 2024
1 parent 7f6dd76 commit f919ed9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clone-project-manager"
version = "0.0.0"
version = "2.0.0"
edition = "2021"
include = [
"**/*.rs",
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ impl Default for AppConfig {
let win_user_home_path = format!("/mnt/c/Users/{}", username);
let wsl_user_home_path =
std::env::var("HOME").expect("'HOME' environment variable must be set.");
let wsl_distro_name = std::env::var("WSL_DISTRO_NAME").expect(
"'WSL_DISTRO_NAME' environment variable must be set in WSL environment.",
);

AppConfig {
workspaces_dir: format!("{}/workspaces", wsl_user_home_path).into(),
workspaces_dir: format!("vscode-remote://wsl+{}{}/workspaces", wsl_distro_name, wsl_user_home_path).into(),
nvim_projectmanager_path: format!("{}/.local/share/nvim/lazy/projectmgr.nvim/projects.json", wsl_user_home_path).into(),
vscode_projectmanager_path: format!("{}/AppData/Roaming/Code/User/globalStorage/alefragnani.project-manager/projects.json", win_user_home_path).into(),
regex: DEFAULT_REGEX.to_string()
Expand Down
3 changes: 2 additions & 1 deletion src/projectmanager/nvim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ pub fn add_project(
debug: bool,
) {
// Read the JSON file
let json_data = fs::read_to_string(&target_path).expect("Unable to read file");
let json_data = fs::read_to_string(&target_path).unwrap_or("[]".to_string());

let mut entries: Vec<Entry> =
serde_json::from_str(&json_data).expect("JSON was not well-formed");
let must_add = !entries.iter().any(|e| e.path == workspace);
Expand Down
2 changes: 1 addition & 1 deletion src/projectmanager/vscode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn add_project(
debug: bool,
) {
// Read the JSON file
let json_data = fs::read_to_string(&target_path).expect("Unable to read file");
let json_data = fs::read_to_string(&target_path).unwrap_or("[]".to_string());
let mut entries: Vec<Entry> =
serde_json::from_str(&json_data).expect("JSON was not well-formed");
let must_add = !entries.iter().any(|e| e.root_path == workspace);
Expand Down

0 comments on commit f919ed9

Please sign in to comment.