Skip to content

Commit 6db8735

Browse files
committed
emmylua_check: support multiple --config
If multiple configs are given, use the workspace directory as the root for processing the configuration. Resolves #509
1 parent 01820c5 commit 6db8735

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

crates/emmylua_check/src/cmd_args.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use structopt::StructOpt;
44
#[derive(Debug, StructOpt, Clone)]
55
#[structopt(name = "emmylua-check", about = "EmmyLua Check")]
66
pub struct CmdArgs {
7-
/// Specify configuration file path.
7+
/// Configuration file paths.
88
/// If not provided, both ".emmyrc.json" and ".luarc.json" will be searched in the workspace
99
/// directory
10-
#[structopt(short, long, parse(from_os_str))]
11-
pub config: Option<std::path::PathBuf>,
10+
#[structopt(short, long, use_delimiter = true, parse(from_os_str))]
11+
pub config: Option<Vec<std::path::PathBuf>>,
1212

1313
/// Path to the workspace directory
1414
#[structopt(parse(from_os_str))]

crates/emmylua_check/src/init.rs

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,30 @@ use emmylua_code_analysis::{
44
load_configs, load_workspace_files, update_code_style, EmmyLuaAnalysis, Emmyrc, LuaFileInfo,
55
};
66

7+
fn root_from_configs(config_paths: &Vec<PathBuf>, fallback: &PathBuf) -> PathBuf {
8+
if config_paths.len() > 1 {
9+
fallback.clone()
10+
} else {
11+
let config_path = &config_paths[0];
12+
// Need to convert to canonical path to ensure parent() is not an empty
13+
// string in the case the path is a relative basename.
14+
match config_path.canonicalize() {
15+
Ok(path) => path.parent().unwrap().to_path_buf(),
16+
Err(err) => {
17+
log::error!(
18+
"Failed to canonicalize config path: \"{:?}\": {}",
19+
config_path,
20+
err
21+
);
22+
fallback.clone()
23+
}
24+
}
25+
}
26+
}
27+
728
pub fn load_workspace(
829
workspace_folder: PathBuf,
9-
config_path: Option<PathBuf>,
30+
config_paths: Option<Vec<PathBuf>>,
1031
ignore: Option<Vec<String>>,
1132
) -> Option<EmmyLuaAnalysis> {
1233
let mut analysis = EmmyLuaAnalysis::new();
@@ -18,22 +39,27 @@ pub fn load_workspace(
1839
}
1940

2041
let main_path = workspace_folders.first()?.clone();
21-
let (config_files, config_root) = if let Some(config_path) = config_path {
22-
(
23-
vec![config_path.clone()],
24-
config_path.parent().unwrap().to_path_buf(),
25-
)
26-
} else {
27-
(
28-
vec![
29-
main_path.join(".luarc.json"),
30-
main_path.join(".emmyrc.json"),
31-
],
32-
main_path.clone(),
33-
)
34-
};
42+
let (config_files, config_root): (Vec<PathBuf>, PathBuf) =
43+
if let Some(config_paths) = config_paths {
44+
(
45+
config_paths.clone(),
46+
root_from_configs(&config_paths, &main_path),
47+
)
48+
} else {
49+
(
50+
vec![
51+
main_path.join(".luarc.json"),
52+
main_path.join(".emmyrc.json"),
53+
],
54+
main_path.clone(),
55+
)
56+
};
3557

3658
let mut emmyrc = load_configs(config_files, None);
59+
log::info!(
60+
"Pre processing configurations using root: \"{}\"",
61+
config_root.display()
62+
);
3763
emmyrc.pre_process_emmyrc(&config_root);
3864

3965
for root in &emmyrc.workspace.workspace_roots {

0 commit comments

Comments
 (0)