aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/bin/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rust-analyzer/src/bin/main.rs')
-rw-r--r--crates/rust-analyzer/src/bin/main.rs85
1 files changed, 59 insertions, 26 deletions
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs
index 89482b952..288847980 100644
--- a/crates/rust-analyzer/src/bin/main.rs
+++ b/crates/rust-analyzer/src/bin/main.rs
@@ -1,14 +1,20 @@
1//! Driver for rust-analyzer. 1//! Driver for rust-analyzer.
2//! 2//!
3//! Based on cli flags, either spawns an LSP server, or runs a batch analysis 3//! Based on cli flags, either spawns an LSP server, or runs a batch analysis
4mod args; 4mod flags;
5mod logger; 5mod logger;
6 6
7use std::{convert::TryFrom, env, fs, path::PathBuf, process}; 7use std::{convert::TryFrom, env, fs, path::Path, process};
8 8
9use lsp_server::Connection; 9use lsp_server::Connection;
10use project_model::ProjectManifest; 10use project_model::ProjectManifest;
11use rust_analyzer::{cli, config::Config, from_json, lsp_ext::supports_utf8, Result}; 11use rust_analyzer::{
12 cli::{self, AnalysisStatsCmd, BenchCmd},
13 config::Config,
14 from_json,
15 lsp_ext::supports_utf8,
16 Result,
17};
12use vfs::AbsPathBuf; 18use vfs::AbsPathBuf;
13 19
14#[cfg(all(feature = "mimalloc"))] 20#[cfg(all(feature = "mimalloc"))]
@@ -28,10 +34,10 @@ fn main() {
28} 34}
29 35
30fn try_main() -> Result<()> { 36fn try_main() -> Result<()> {
31 let args = args::Args::parse()?; 37 let flags = flags::RustAnalyzer::from_env()?;
32 38
33 #[cfg(debug_assertions)] 39 #[cfg(debug_assertions)]
34 if args.wait_dbg || env::var("RA_WAIT_DBG").is_ok() { 40 if flags.wait_dbg || env::var("RA_WAIT_DBG").is_ok() {
35 #[allow(unused_mut)] 41 #[allow(unused_mut)]
36 let mut d = 4; 42 let mut d = 4;
37 while d == 4 { 43 while d == 4 {
@@ -39,35 +45,62 @@ fn try_main() -> Result<()> {
39 } 45 }
40 } 46 }
41 47
42 setup_logging(args.log_file, args.no_buffering)?; 48 setup_logging(flags.log_file.as_deref(), flags.no_log_buffering)?;
43 match args.command { 49 let verbosity = flags.verbosity();
44 args::Command::RunServer => run_server()?, 50
45 args::Command::PrintConfigSchema => { 51 match flags.subcommand {
46 println!("{:#}", Config::json_schema()); 52 flags::RustAnalyzerCmd::LspServer(cmd) => {
53 if cmd.print_config_schema {
54 println!("{:#}", Config::json_schema());
55 return Ok(());
56 }
57 if cmd.version {
58 println!("rust-analyzer {}", env!("REV"));
59 return Ok(());
60 }
61 if cmd.help {
62 println!("{}", flags::RustAnalyzer::HELP);
63 return Ok(());
64 }
65 run_server()?
47 } 66 }
48 args::Command::ProcMacro => proc_macro_srv::cli::run()?, 67 flags::RustAnalyzerCmd::ProcMacro(_) => proc_macro_srv::cli::run()?,
49 68 flags::RustAnalyzerCmd::Parse(cmd) => cli::parse(cmd.no_dump)?,
50 args::Command::Parse { no_dump } => cli::parse(no_dump)?, 69 flags::RustAnalyzerCmd::Symbols(_) => cli::symbols()?,
51 args::Command::Symbols => cli::symbols()?, 70 flags::RustAnalyzerCmd::Highlight(cmd) => cli::highlight(cmd.rainbow)?,
52 args::Command::Highlight { rainbow } => cli::highlight(rainbow)?, 71 flags::RustAnalyzerCmd::AnalysisStats(cmd) => AnalysisStatsCmd {
53 args::Command::AnalysisStats(cmd) => cmd.run(args.verbosity)?, 72 randomize: cmd.randomize,
54 args::Command::Bench(cmd) => cmd.run(args.verbosity)?, 73 parallel: cmd.parallel,
55 args::Command::Diagnostics { path, load_output_dirs, with_proc_macro } => { 74 memory_usage: cmd.memory_usage,
56 cli::diagnostics(path.as_ref(), load_output_dirs, with_proc_macro)? 75 only: cmd.only,
76 with_deps: cmd.with_deps,
77 path: cmd.path,
78 load_output_dirs: cmd.load_output_dirs,
79 with_proc_macro: cmd.with_proc_macro,
57 } 80 }
58 args::Command::Ssr { rules } => { 81 .run(verbosity)?,
59 cli::apply_ssr_rules(rules)?; 82 flags::RustAnalyzerCmd::AnalysisBench(cmd) => {
83 let what = cmd.what();
84 BenchCmd {
85 memory_usage: cmd.memory_usage,
86 path: cmd.path,
87 load_output_dirs: cmd.load_output_dirs,
88 with_proc_macro: cmd.with_proc_macro,
89 what,
90 }
91 .run(verbosity)?
60 } 92 }
61 args::Command::StructuredSearch { patterns, debug_snippet } => { 93
62 cli::search_for_patterns(patterns, debug_snippet)?; 94 flags::RustAnalyzerCmd::Diagnostics(cmd) => {
95 cli::diagnostics(&cmd.path, cmd.load_output_dirs, cmd.with_proc_macro)?
63 } 96 }
64 args::Command::Version => println!("rust-analyzer {}", env!("REV")), 97 flags::RustAnalyzerCmd::Ssr(cmd) => cli::apply_ssr_rules(cmd.rule)?,
65 args::Command::Help => {} 98 flags::RustAnalyzerCmd::Search(cmd) => cli::search_for_patterns(cmd.pattern, cmd.debug)?,
66 } 99 }
67 Ok(()) 100 Ok(())
68} 101}
69 102
70fn setup_logging(log_file: Option<PathBuf>, no_buffering: bool) -> Result<()> { 103fn setup_logging(log_file: Option<&Path>, no_buffering: bool) -> Result<()> {
71 env::set_var("RUST_BACKTRACE", "short"); 104 env::set_var("RUST_BACKTRACE", "short");
72 105
73 let log_file = match log_file { 106 let log_file = match log_file {