Skip to content

Commit

Permalink
Make config.rs a single source of truth for configuration.
Browse files Browse the repository at this point in the history
Configuration is editor-independent. For this reason, we pick
JSON-schema as the repr of the source of truth. We do specify it using
rust-macros and some quick&dirty hackery though.

The idea for syncing truth with package.json is to just do that
manually, but there's a test to check that they are actually synced.

There's CLI to print config's json schema:

    $ rust-analyzer --print-config-schema

We go with a CLI rather than LSP request/response to make it easier to
incorporate the thing into extension's static config. This is roughtly
how we put the thing in package.json.
  • Loading branch information
matklad committed Dec 8, 2020
1 parent e2e6b70 commit 2544abb
Show file tree
Hide file tree
Showing 7 changed files with 659 additions and 432 deletions.
1 change: 1 addition & 0 deletions 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 crates/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pico-args = "0.3.1"
oorandom = "11.1.2"
rustc-hash = "1.1.0"
serde = { version = "1.0.106", features = ["derive"] }
serde_json = "1.0.48"
serde_json = { version = "1.0.48", features = ["preserve_order"] }
threadpool = "1.7.1"
rayon = "1.5"
mimalloc = { version = "0.1.19", default-features = false, optional = true }
Expand Down
5 changes: 5 additions & 0 deletions crates/rust-analyzer/src/bin/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub(crate) enum Command {
StructuredSearch { debug_snippet: Option<String>, patterns: Vec<SsrPattern> },
ProcMacro,
RunServer,
PrintConfigSchema,
Version,
Help,
}
Expand Down Expand Up @@ -135,6 +136,10 @@ impl Args {
return Ok(Args { verbosity, log_file: None, command: Command::Help });
}

if matches.contains("--print-config-schema") {
return Ok(Args { verbosity, log_file, command: Command::PrintConfigSchema });
}

let subcommand = match matches.subcommand()? {
Some(it) => it,
None => {
Expand Down
3 changes: 3 additions & 0 deletions crates/rust-analyzer/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ fn try_main() -> Result<()> {
setup_logging(args.log_file)?;
match args.command {
args::Command::RunServer => run_server()?,
args::Command::PrintConfigSchema => {
println!("{:#}", Config::json_schema());
}
args::Command::ProcMacro => proc_macro_srv::cli::run()?,

args::Command::Parse { no_dump } => cli::parse(no_dump)?,
Expand Down
Loading

0 comments on commit 2544abb

Please sign in to comment.