Skip to content

Commit ff54eb5

Browse files
VLanvinfacebook-github-bot
authored andcommitted
Add support for JSON input
Summary: Add support for JSON input in mini-elp, for commands `eqwalize` and `eqwalize-all`. ## Usage `elp eqwalize-all --project path/to/build_info.json` ## JSON file structure The `build_info.json` file is structured this way: ``` { "apps": [app list], "deps": [app list], // Defaults to [] "root": "path/to/root" // Defaults to "" } ``` Where an `app` is a map structured as follows: ``` // app { "name": "app_name", "dir": "path/to/app", // Relative to project root "src_dirs": ["path/to/src", ...], // Relative to app dir, defaults to ["src"] "extra_src_dirs": ["path/to/extra_src", ...], // Relative to app dir, defaults to [] "ebin": "path/to/ebin", // Relative to app dir, defaults to "ebin" "include_dirs": ["include", ...], // Relative to app dir, defaults to [] "macros": ["MACRO", ...], // Defaults to [] } ``` Reviewed By: ilya-klyuchnikov, michalmuskala Differential Revision: D40834799 fbshipit-source-id: 159a4c61d450fa5232eb356e2113a8709911b809
1 parent 8036d8a commit ff54eb5

File tree

7 files changed

+350
-59
lines changed

7 files changed

+350
-59
lines changed

mini-elp/Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mini-elp/crates/elp/src/bin/args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ COMMANDS:
8383
--offset-positions Emit positions as {StartByte, EndByte} rather than {Line, Col}
8484
--module Only process indicated module(s) (can be repeated)
8585
eqwalize <module> Eqwalize specified module
86-
--project Path to directory with rebar project (defaults to `.`)
86+
--project Path to directory with rebar project, or to a JSON file (defaults to `.`)
8787
--fast Refresh AST information for only the specified module
8888
--format FORMAT Specify format for the diagnostics. FORMAT can be `pretty` (default), `json` or `json-lsp`
8989
eqwalize-all Eqwalize all opted-in modules in a project (modules with `-typing([eqwalizer])`)
90-
--project Path to directory with rebar project (defaults to `.`)
90+
--project Path to directory with rebar project, or to a JSON file (defaults to `.`)
9191
--format FORMAT Specify format for the diagnostics. FORMAT can be `pretty` (default), `json` or `json-lsp`
9292
9393
ENV VARS:

mini-elp/crates/elp/src/bin/eqwalizer_cli.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,16 @@ struct EqwalizerInternalArgs<'a> {
3535
}
3636

3737
pub fn eqwalize_module(args: &Eqwalize, mut out: impl WriteColor) -> Result<()> {
38-
let profile = args.profile.clone().map(Profile).unwrap_or_default();
39-
let loaded = &load_rebar::load_project_with_caching_at(&args.project, &profile, args.fast)?;
38+
let loaded = &match args.project.extension() {
39+
None => {
40+
let profile = args.profile.clone().map(Profile).unwrap_or_default();
41+
load_rebar::load_project_with_caching_at(&args.project, &profile, args.fast)
42+
}
43+
Some(ext) => match ext.to_str() {
44+
Some("json") => load_rebar::load_json_project_at(&args.project),
45+
_ => panic!("Unknown file type for option --project"),
46+
},
47+
}?;
4048
let analysis = &loaded.analysis();
4149
let file_id = analysis
4250
.module_file_id(loaded.project_id, &args.module)?
@@ -57,8 +65,16 @@ pub fn eqwalize_module(args: &Eqwalize, mut out: impl WriteColor) -> Result<()>
5765
}
5866

5967
pub fn eqwalize_all(args: &EqwalizeAll, mut out: impl WriteColor) -> Result<()> {
60-
let profile = args.profile.clone().map(Profile).unwrap_or_default();
61-
let loaded = &load_rebar::load_project_at(&args.project, &profile)?;
68+
let loaded = &match args.project.extension() {
69+
None => {
70+
let profile = args.profile.clone().map(Profile).unwrap_or_default();
71+
load_rebar::load_project_at(&args.project, &profile)
72+
}
73+
Some(ext) => match ext.to_str() {
74+
Some("json") => load_rebar::load_json_project_at(&args.project),
75+
_ => panic!("Unknown file type for option --project"),
76+
},
77+
}?;
6278
let analysis = &loaded.analysis();
6379

6480
let mut reporter: Box<dyn reporting::Reporter> = match args.format {

mini-elp/crates/elp/src/bin/load_rebar.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ impl LoadResult {
8383
}
8484
}
8585

86+
pub fn load_json_project_at(json: &Path) -> Result<LoadResult> {
87+
let json_file = AbsPathBuf::assert(std::env::current_dir()?.join(json)).normalize();
88+
let manifest = ProjectManifest::from_json_file(json_file);
89+
90+
let pb = util::spinner("Loading JSON manifest", "Loaded JSON manifest");
91+
let project = Project::load(manifest)?;
92+
pb.finish();
93+
94+
load_project(project)
95+
}
96+
8697
pub fn load_project_at(root: &Path, project_profile: &Profile) -> Result<LoadResult> {
8798
let root = AbsPathBuf::assert(std::env::current_dir()?.join(root));
8899
let root = ProjectManifest::discover_single(&root, project_profile)?;

mini-elp/crates/elp/src/resources/test/help.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ COMMANDS:
1616
--offset-positions Emit positions as {StartByte, EndByte} rather than {Line, Col}
1717
--module Only process indicated module(s) (can be repeated)
1818
eqwalize <module> Eqwalize specified module
19-
--project Path to directory with rebar project (defaults to `.`)
19+
--project Path to directory with rebar project, or to a JSON file (defaults to `.`)
2020
--fast Refresh AST information for only the specified module
2121
--format FORMAT Specify format for the diagnostics. FORMAT can be `pretty` (default), `json` or `json-lsp`
2222
eqwalize-all Eqwalize all opted-in modules in a project (modules with `-typing([eqwalizer])`)
23-
--project Path to directory with rebar project (defaults to `.`)
23+
--project Path to directory with rebar project, or to a JSON file (defaults to `.`)
2424
--format FORMAT Specify format for the diagnostics. FORMAT can be `pretty` (default), `json` or `json-lsp`
2525

2626
ENV VARS:

mini-elp/crates/project_model/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ fxhash.workspace = true
1212
lazy_static.workspace = true
1313
log.workspace = true
1414
paths.workspace = true
15+
serde.workspace = true
16+
serde_json.workspace = true
1517
tempfile.workspace = true
1618
walkdir.workspace = true

0 commit comments

Comments
 (0)