Skip to content

Commit 7f22ec9

Browse files
committed
add launcher, socket and paths to healthcheck (fix #52, fix #53)
1 parent 4cac619 commit 7f22ec9

14 files changed

Lines changed: 84 additions & 56 deletions

File tree

crates/bridge/src/main.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ use std::{
33
path::{PathBuf, absolute},
44
};
55

6-
use anyhow::{Context, Result};
6+
use anyhow::Result;
77
use clap::{Parser, Subcommand};
88
use defold_nvim_core::{
99
editor,
1010
focus::{focus_game, focus_neovim},
11-
mobdap, neovide, project, script_api,
11+
mobdap, neovide, path, project, script_api,
1212
};
1313
use tracing::Level;
1414
use tracing_appender::rolling::never;
@@ -116,10 +116,7 @@ fn main() -> Result<()> {
116116
}
117117
};
118118

119-
let logs = dirs::cache_dir()
120-
.context("could not get cache dir")?
121-
.join("defold.nvim")
122-
.join("logs");
119+
let logs = path::cache_dir()?.join("logs");
123120

124121
fs::create_dir_all(&logs)?;
125122

crates/core/src/bridge.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use anyhow::{Context, Result};
1+
use anyhow::Result;
22
use std::{
33
fs::{self},
44
path::{Path, PathBuf},
55
};
66
use version_compare::Version;
77

8-
use crate::{release_downloader, utils};
8+
use crate::{path, release_downloader, utils};
99

1010
const EXECUTABLE_NAME: &str = "defold-nvim-bridge";
1111
const OWNER: &str = "atomicptr";
@@ -51,10 +51,7 @@ fn exe_name() -> String {
5151
}
5252

5353
fn local_path() -> Result<PathBuf> {
54-
let dir = dirs::data_dir()
55-
.context("could not get data dir")?
56-
.join("defold.nvim")
57-
.join("bin");
54+
let dir = path::data_dir()?.join("bin");
5855

5956
fs::create_dir_all(&dir)?;
6057

crates/core/src/cache.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
use crate::utils::sha3;
2-
use anyhow::{Context, Result};
1+
use crate::{path, utils::sha3};
2+
use anyhow::Result;
33
use std::{fs, path::PathBuf, time::Duration};
44

55
fn cache_dir() -> Result<PathBuf> {
6-
let dir = dirs::cache_dir()
7-
.context("could not get cache dir")?
8-
.join("defold.nvim")
9-
.join("cache");
6+
let dir = path::cache_dir()?.join("cache");
107

118
fs::create_dir_all(&dir)?;
129

crates/core/src/defold_annotations.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use anyhow::{Context, Result, bail};
88
use version_compare::Version;
99
use zip::ZipArchive;
1010

11-
use crate::{github, project, utils};
11+
use crate::{github, path, project, utils};
1212

1313
const OWNER: &str = "astrochili";
1414
const REPOSITORY: &str = "defold-annotations";
@@ -19,10 +19,7 @@ pub fn dir() -> Result<PathBuf> {
1919
}
2020

2121
fn version_path() -> Result<PathBuf> {
22-
let dir = dirs::data_dir()
23-
.context("could not get data dir")?
24-
.join("defold.nvim")
25-
.join("meta");
22+
let dir = path::data_dir()?.join("meta");
2623

2724
fs::create_dir_all(&dir)?;
2825

crates/core/src/editor_config.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55
path::{Path, PathBuf},
66
};
77

8-
use crate::{bridge, editor};
8+
use crate::{bridge, editor, path};
99

1010
#[derive(Debug, Deserialize)]
1111
pub enum LauncherType {
@@ -102,10 +102,7 @@ fn create_runner_script(
102102
plugin_root: &Path,
103103
launcher_settings: &LauncherSettings,
104104
) -> Result<PathBuf> {
105-
let dir = dirs::data_dir()
106-
.context("could not get data dir")?
107-
.join("defold.nvim")
108-
.join("bin");
105+
let dir = path::data_dir()?.join("bin");
109106
fs::create_dir_all(&dir)?;
110107

111108
let script_path = dir.join(format!("run.{SCRIPT_EXT}"));

crates/core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub mod github;
99
pub mod mobdap;
1010
pub mod neovide;
1111
pub mod nvim_server;
12+
pub mod path;
1213
pub mod project;
1314
mod release_downloader;
1415
pub mod script_api;

crates/core/src/neovide.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77

88
use anyhow::{Context, Result, bail};
99

10-
use crate::{release_downloader, utils};
10+
use crate::{path, release_downloader, utils};
1111

1212
const EXECUTABLE_NAME: &str = "neovide";
1313
const OWNER: &str = "neovide";
@@ -26,10 +26,7 @@ const ASSET_NAME: &str = "Neovide-aarch64-apple-darwin.dmg";
2626
const ASSET_NAME: &'static str = "neovide.exe.zip";
2727

2828
fn bin_dir() -> Result<PathBuf> {
29-
let dir = dirs::data_dir()
30-
.context("could not get data dir")?
31-
.join("defold.nvim")
32-
.join("bin");
29+
let dir = path::data_dir()?.join("bin");
3330

3431
Ok(dir)
3532
}

crates/core/src/nvim_server.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::project_id;
1+
use crate::{path, utils::project_id};
22
use anyhow::{Context, Result, bail};
33
use std::{
44
fs,
@@ -36,9 +36,7 @@ pub fn runtime_dir(root_dir: &Path) -> Result<PathBuf> {
3636
.to_str()
3737
.context("could not convert root dir to string")?;
3838

39-
let dir = dirs::cache_dir()
40-
.context("could not get cache dir")?
41-
.join("defold.nvim")
39+
let dir = path::cache_dir()?
4240
.join("runtime")
4341
.join(project_id(root_dir)?);
4442

crates/core/src/path.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use anyhow::{Context, Result};
2+
use std::path::PathBuf;
3+
4+
pub fn data_dir() -> Result<PathBuf> {
5+
dirs::data_dir()
6+
.context("could not get data dir")
7+
.map(|p| p.join("defold.nvim"))
8+
}
9+
10+
pub fn cache_dir() -> Result<PathBuf> {
11+
dirs::cache_dir()
12+
.context("could not get cache dir")
13+
.map(|p| p.join("defold.nvim"))
14+
}

crates/core/src/project.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77
use crate::{
88
defold_annotations,
99
game_project::GameProject,
10-
script_api,
10+
path, script_api,
1111
utils::{self, sha3},
1212
};
1313
use anyhow::{Context, Result, bail};
@@ -21,10 +21,7 @@ fn ident(string: &str) -> Result<String> {
2121
}
2222

2323
pub fn deps_root() -> Result<PathBuf> {
24-
let dir = dirs::data_dir()
25-
.context("could not get data dir")?
26-
.join("defold.nvim")
27-
.join("deps");
24+
let dir = path::data_dir()?.join("deps");
2825
fs::create_dir_all(&dir)?;
2926
Ok(dir)
3027
}

0 commit comments

Comments
 (0)