Skip to content

Commit

Permalink
feat: configuration handling across multiple files
Browse files Browse the repository at this point in the history
- add `debug` trait to `config` struct in `config.rs`
- implement `config` function in `ext.rs` that loads and prints a configuration
- add `config` command variant to the `cmd` enum in `main.rs`
  • Loading branch information
falcucci authored and pr2502 committed Mar 1, 2024
1 parent 5b16753 commit 1db8eb0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mod de {
}
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct Config {
#[serde(default = "default::instance_timeout")]
Expand Down
6 changes: 6 additions & 0 deletions src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ where
}
}

pub async fn config() -> Result<()> {
let config = Config::load_or_default().await;
println!("{:?}", config);
Ok(())
}

pub async fn status(json: bool) -> Result<()> {
let res = ext_request::<StatusResponse>(ext::Request::Status {}).await?;

Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ enum Cmd {
json: bool,
},

/// Print server configuration
Config {},

/// Reload workspace
///
/// For rust-analyzer send the `rust-analyzer/reloadWorkspace` extension request.
Expand All @@ -56,6 +59,7 @@ async fn main() -> anyhow::Result<()> {
server_args,
}) => proxy::run(server_path, server_args).await,
Some(Cmd::Status { json }) => ext::status(json).await,
Some(Cmd::Config {}) => ext::config().await,
Some(Cmd::Reload {}) => ext::reload().await,
None => {
let server_path = env::var("RA_MUX_SERVER").unwrap_or_else(|_| "rust-analyzer".into());
Expand Down

0 comments on commit 1db8eb0

Please sign in to comment.