]> git.lizzy.rs Git - rust.git/commitdiff
Add the ability to wait for a debugger.
authorvsrs <vit@conrlab.com>
Sun, 24 Jan 2021 15:04:47 +0000 (18:04 +0300)
committervsrs <vit@conrlab.com>
Mon, 25 Jan 2021 14:46:03 +0000 (17:46 +0300)
crates/rust-analyzer/src/bin/args.rs
crates/rust-analyzer/src/bin/main.rs

index 32d7836ff546f5d011bd4a76805c2a831f513783..abc00d03bb6fed32de140ccc6f8e4bdc844fe2e1 100644 (file)
@@ -16,6 +16,7 @@ pub(crate) struct Args {
     pub(crate) log_file: Option<PathBuf>,
     pub(crate) no_buffering: bool,
     pub(crate) command: Command,
+    pub(crate) wait_dbg: bool,
 }
 
 pub(crate) enum Command {
@@ -51,6 +52,8 @@ pub(crate) enum Command {
     --log-file <PATH> Log to the specified file instead of stderr
     --no-buffering    Flush log records to the file immediately
 
+    --wait-dbg        Wait until a debugger is attached to
+
 ENVIRONMENTAL VARIABLES:
     RA_LOG            Set log filter in env_logger format
     RA_PROFILE        Enable hierarchical profiler
@@ -117,6 +120,7 @@ pub(crate) fn parse() -> Result<Args> {
                 log_file: None,
                 command: Command::Version,
                 no_buffering: false,
+                wait_dbg: false,
             });
         }
 
@@ -134,21 +138,40 @@ pub(crate) fn parse() -> Result<Args> {
         };
         let log_file = matches.opt_value_from_str("--log-file")?;
         let no_buffering = matches.contains("--no-buffering");
+        let wait_dbg = matches.contains("--wait-dbg");
 
         if matches.contains(["-h", "--help"]) {
             eprintln!("{}", HELP);
-            return Ok(Args { verbosity, log_file: None, command: Command::Help, no_buffering });
+            return Ok(Args {
+                verbosity,
+                log_file: None,
+                command: Command::Help,
+                no_buffering,
+                wait_dbg,
+            });
         }
 
         if matches.contains("--print-config-schema") {
-            return Ok(Args { verbosity, log_file, command: Command::PrintConfigSchema, no_buffering }, );
+            return Ok(Args {
+                verbosity,
+                log_file,
+                command: Command::PrintConfigSchema,
+                no_buffering,
+                wait_dbg,
+            });
         }
 
         let subcommand = match matches.subcommand()? {
             Some(it) => it,
             None => {
                 finish_args(matches)?;
-                return Ok(Args { verbosity, log_file, command: Command::RunServer, no_buffering });
+                return Ok(Args {
+                    verbosity,
+                    log_file,
+                    command: Command::RunServer,
+                    no_buffering,
+                    wait_dbg,
+                });
             }
         };
         let command = match subcommand.as_str() {
@@ -223,11 +246,17 @@ pub(crate) fn parse() -> Result<Args> {
             },
             _ => {
                 eprintln!("{}", HELP);
-                return Ok(Args { verbosity, log_file: None, command: Command::Help, no_buffering });
+                return Ok(Args {
+                    verbosity,
+                    log_file: None,
+                    command: Command::Help,
+                    no_buffering,
+                    wait_dbg,
+                });
             }
         };
         finish_args(matches)?;
-        Ok(Args { verbosity, log_file, command, no_buffering })
+        Ok(Args { verbosity, log_file, command, no_buffering, wait_dbg })
     }
 }
 
index 9a54193f60f6468c5771f354e98a6049161cae16..0cddfecb57b333f4e010db46384e21666097f4c8 100644 (file)
@@ -21,6 +21,7 @@
 
 fn main() {
     if let Err(err) = try_main() {
+        log::error!("Unexpected error: {}", err);
         eprintln!("{}", err);
         process::exit(101);
     }
@@ -28,6 +29,14 @@ fn main() {
 
 fn try_main() -> Result<()> {
     let args = args::Args::parse()?;
+    if args.wait_dbg {
+        #[allow(unused_mut)]
+        let mut d = 4;
+        while d == 4 {
+            d = 4;
+        }
+    }
+
     setup_logging(args.log_file, args.no_buffering)?;
     match args.command {
         args::Command::RunServer => run_server()?,
@@ -56,7 +65,7 @@ fn try_main() -> Result<()> {
     Ok(())
 }
 
-fn setup_logging(log_file: Option<PathBuf>, flush_file: bool) -> Result<()> {
+fn setup_logging(log_file: Option<PathBuf>, no_buffering: bool) -> Result<()> {
     env::set_var("RUST_BACKTRACE", "short");
 
     let log_file = match log_file {
@@ -69,7 +78,7 @@ fn setup_logging(log_file: Option<PathBuf>, flush_file: bool) -> Result<()> {
         None => None,
     };
     let filter = env::var("RA_LOG").ok();
-    logger::Logger::new(log_file, flush_file, filter.as_deref()).install();
+    logger::Logger::new(log_file, no_buffering, filter.as_deref()).install();
 
     tracing_setup::setup_tracing()?;