Skip to content

Commit

Permalink
fix: create log folder if it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
alesbrelih committed Apr 5, 2024
1 parent d55381c commit 354020a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use lsp_types::{

use std::collections::HashMap;
use std::error::Error;
use std::fs;
use std::path::Path;
use std::process::exit;

mod gitlab_ci_ls_parser;
Expand All @@ -24,6 +26,9 @@ struct InitializationOptions {

#[serde(default = "default_log_path")]
log_path: String,

#[serde(rename = "cache", default = "default_cache_path")]
cache_path: String,
}

#[derive(Serialize, Deserialize, Debug)]
Expand All @@ -43,6 +48,13 @@ fn default_log_path() -> String {
"/dev/null".to_string()
}

fn default_cache_path() -> String {
format!(
"{}/.gitlab-ci-ls/cache/",
std::env::var("HOME").unwrap_or_default()
)
}

// TODO: refactor and remove the next line :)
#[allow(clippy::too_many_lines)]
fn main() -> Result<(), Box<dyn Error + Sync + Send>> {
Expand Down Expand Up @@ -105,13 +117,19 @@ fn main() -> Result<(), Box<dyn Error + Sync + Send>> {
InitializationParams {
root_path: String::new(),
initialization_options: InitializationOptions {
log_path: String::from("/dev/null"),
log_path: default_log_path(),
package_map: HashMap::new(),
cache_path: default_cache_path(),
},
}
}
};

let path = Path::new(&init_params.initialization_options.log_path);
if let Some(dir_path) = path.parent() {
fs::create_dir_all(dir_path)?;
}

simple_logging::log_to_file(
&init_params.initialization_options.log_path,
LevelFilter::Warn,
Expand All @@ -131,7 +149,7 @@ fn main() -> Result<(), Box<dyn Error + Sync + Send>> {

let lsp_events =
gitlab_ci_ls_parser::handlers::LSPHandlers::new(gitlab_ci_ls_parser::LSPConfig {
cache_path: format!("{}/.gitlab-ci-ls/cache/", std::env::var("HOME")?),
cache_path: init_params.initialization_options.cache_path,
package_map: init_params.initialization_options.package_map,
remote_urls,
root_dir: init_params.root_path,
Expand Down

0 comments on commit 354020a

Please sign in to comment.