forked from pr2502/ra-multiplex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
85 lines (74 loc) · 2.31 KB
/
main.rs
File metadata and controls
85 lines (74 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use std::env;
use anyhow::Result;
use clap::{Parser, Subcommand};
use ra_multiplex::config::Config;
use ra_multiplex::{ext, proxy, server};
use tracing::info;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Cli {
/// No command defaults to client
#[command(subcommand)]
command: Option<Cmd>,
}
#[derive(Subcommand, Debug)]
enum Cmd {
/// Connect to an ra-mux server [default]
Client {
/// Path to the LSP server executable
#[arg(
long = "server-path",
alias = "ra-mux-server",
env = "RA_MUX_SERVER",
default_value = "rust-analyzer",
name = "SERVER_PATH"
)]
server: String,
/// Arguments passed to the LSP server
#[arg(name = "SERVER_ARGS")]
args: Vec<String>,
},
/// Start a ra-mux server
Server {},
/// Print server status
Status {
/// Output data as machine readable JSON
#[clap(long = "json", default_value = "false")]
json: bool,
},
/// Print server configuration
Config {},
/// Reload workspace
///
/// For rust-analyzer send the `rust-analyzer/reloadWorkspace` extension request.
/// Do nothing for other language servers.
Reload {},
}
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
let cli = Cli::parse();
let config = match Config::try_load() {
Ok(config) => {
config.init_logger();
config
}
Err(err) => {
let config = Config::default();
config.init_logger();
// Log only after the logger has been initialized
info!(?err, "cannot load config file, continuing with defaults");
config
}
};
match cli.command {
Some(Cmd::Server {}) => server::run(&config).await,
Some(Cmd::Client { server, args }) => proxy::run(&config, server, args).await,
Some(Cmd::Status { json }) => ext::status(&config, json).await,
Some(Cmd::Config {}) => ext::config(&config).await,
Some(Cmd::Reload {}) => ext::reload(&config).await,
None => {
let server_path = env::var("RA_MUX_SERVER").unwrap_or_else(|_| "rust-analyzer".into());
proxy::run(&config, server_path, vec![]).await
}
}
}