diff options
author | vsrs <[email protected]> | 2021-01-24 15:04:47 +0000 |
---|---|---|
committer | vsrs <[email protected]> | 2021-01-25 14:46:03 +0000 |
commit | 8c843d1dac0151e9251cddd2b36e940b5b1c7661 (patch) | |
tree | 86cb39845e8b2b634869aa70d44d662c0a411054 /crates | |
parent | 98d7512e93ea66f1a259623f9f534bee4a922a81 (diff) |
Add the ability to wait for a debugger.
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/bin/args.rs | 39 | ||||
-rw-r--r-- | crates/rust-analyzer/src/bin/main.rs | 13 |
2 files changed, 45 insertions, 7 deletions
diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs index 32d7836ff..abc00d03b 100644 --- a/crates/rust-analyzer/src/bin/args.rs +++ b/crates/rust-analyzer/src/bin/args.rs | |||
@@ -16,6 +16,7 @@ pub(crate) struct Args { | |||
16 | pub(crate) log_file: Option<PathBuf>, | 16 | pub(crate) log_file: Option<PathBuf>, |
17 | pub(crate) no_buffering: bool, | 17 | pub(crate) no_buffering: bool, |
18 | pub(crate) command: Command, | 18 | pub(crate) command: Command, |
19 | pub(crate) wait_dbg: bool, | ||
19 | } | 20 | } |
20 | 21 | ||
21 | pub(crate) enum Command { | 22 | pub(crate) enum Command { |
@@ -51,6 +52,8 @@ FLAGS: | |||
51 | --log-file <PATH> Log to the specified file instead of stderr | 52 | --log-file <PATH> Log to the specified file instead of stderr |
52 | --no-buffering Flush log records to the file immediately | 53 | --no-buffering Flush log records to the file immediately |
53 | 54 | ||
55 | --wait-dbg Wait until a debugger is attached to | ||
56 | |||
54 | ENVIRONMENTAL VARIABLES: | 57 | ENVIRONMENTAL VARIABLES: |
55 | RA_LOG Set log filter in env_logger format | 58 | RA_LOG Set log filter in env_logger format |
56 | RA_PROFILE Enable hierarchical profiler | 59 | RA_PROFILE Enable hierarchical profiler |
@@ -117,6 +120,7 @@ impl Args { | |||
117 | log_file: None, | 120 | log_file: None, |
118 | command: Command::Version, | 121 | command: Command::Version, |
119 | no_buffering: false, | 122 | no_buffering: false, |
123 | wait_dbg: false, | ||
120 | }); | 124 | }); |
121 | } | 125 | } |
122 | 126 | ||
@@ -134,21 +138,40 @@ impl Args { | |||
134 | }; | 138 | }; |
135 | let log_file = matches.opt_value_from_str("--log-file")?; | 139 | let log_file = matches.opt_value_from_str("--log-file")?; |
136 | let no_buffering = matches.contains("--no-buffering"); | 140 | let no_buffering = matches.contains("--no-buffering"); |
141 | let wait_dbg = matches.contains("--wait-dbg"); | ||
137 | 142 | ||
138 | if matches.contains(["-h", "--help"]) { | 143 | if matches.contains(["-h", "--help"]) { |
139 | eprintln!("{}", HELP); | 144 | eprintln!("{}", HELP); |
140 | return Ok(Args { verbosity, log_file: None, command: Command::Help, no_buffering }); | 145 | return Ok(Args { |
146 | verbosity, | ||
147 | log_file: None, | ||
148 | command: Command::Help, | ||
149 | no_buffering, | ||
150 | wait_dbg, | ||
151 | }); | ||
141 | } | 152 | } |
142 | 153 | ||
143 | if matches.contains("--print-config-schema") { | 154 | if matches.contains("--print-config-schema") { |
144 | return Ok(Args { verbosity, log_file, command: Command::PrintConfigSchema, no_buffering }, ); | 155 | return Ok(Args { |
156 | verbosity, | ||
157 | log_file, | ||
158 | command: Command::PrintConfigSchema, | ||
159 | no_buffering, | ||
160 | wait_dbg, | ||
161 | }); | ||
145 | } | 162 | } |
146 | 163 | ||
147 | let subcommand = match matches.subcommand()? { | 164 | let subcommand = match matches.subcommand()? { |
148 | Some(it) => it, | 165 | Some(it) => it, |
149 | None => { | 166 | None => { |
150 | finish_args(matches)?; | 167 | finish_args(matches)?; |
151 | return Ok(Args { verbosity, log_file, command: Command::RunServer, no_buffering }); | 168 | return Ok(Args { |
169 | verbosity, | ||
170 | log_file, | ||
171 | command: Command::RunServer, | ||
172 | no_buffering, | ||
173 | wait_dbg, | ||
174 | }); | ||
152 | } | 175 | } |
153 | }; | 176 | }; |
154 | let command = match subcommand.as_str() { | 177 | let command = match subcommand.as_str() { |
@@ -223,11 +246,17 @@ impl Args { | |||
223 | }, | 246 | }, |
224 | _ => { | 247 | _ => { |
225 | eprintln!("{}", HELP); | 248 | eprintln!("{}", HELP); |
226 | return Ok(Args { verbosity, log_file: None, command: Command::Help, no_buffering }); | 249 | return Ok(Args { |
250 | verbosity, | ||
251 | log_file: None, | ||
252 | command: Command::Help, | ||
253 | no_buffering, | ||
254 | wait_dbg, | ||
255 | }); | ||
227 | } | 256 | } |
228 | }; | 257 | }; |
229 | finish_args(matches)?; | 258 | finish_args(matches)?; |
230 | Ok(Args { verbosity, log_file, command, no_buffering }) | 259 | Ok(Args { verbosity, log_file, command, no_buffering, wait_dbg }) |
231 | } | 260 | } |
232 | } | 261 | } |
233 | 262 | ||
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index 9a54193f6..0cddfecb5 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs | |||
@@ -21,6 +21,7 @@ static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; | |||
21 | 21 | ||
22 | fn main() { | 22 | fn main() { |
23 | if let Err(err) = try_main() { | 23 | if let Err(err) = try_main() { |
24 | log::error!("Unexpected error: {}", err); | ||
24 | eprintln!("{}", err); | 25 | eprintln!("{}", err); |
25 | process::exit(101); | 26 | process::exit(101); |
26 | } | 27 | } |
@@ -28,6 +29,14 @@ fn main() { | |||
28 | 29 | ||
29 | fn try_main() -> Result<()> { | 30 | fn try_main() -> Result<()> { |
30 | let args = args::Args::parse()?; | 31 | let args = args::Args::parse()?; |
32 | if args.wait_dbg { | ||
33 | #[allow(unused_mut)] | ||
34 | let mut d = 4; | ||
35 | while d == 4 { | ||
36 | d = 4; | ||
37 | } | ||
38 | } | ||
39 | |||
31 | setup_logging(args.log_file, args.no_buffering)?; | 40 | setup_logging(args.log_file, args.no_buffering)?; |
32 | match args.command { | 41 | match args.command { |
33 | args::Command::RunServer => run_server()?, | 42 | args::Command::RunServer => run_server()?, |
@@ -56,7 +65,7 @@ fn try_main() -> Result<()> { | |||
56 | Ok(()) | 65 | Ok(()) |
57 | } | 66 | } |
58 | 67 | ||
59 | fn setup_logging(log_file: Option<PathBuf>, flush_file: bool) -> Result<()> { | 68 | fn setup_logging(log_file: Option<PathBuf>, no_buffering: bool) -> Result<()> { |
60 | env::set_var("RUST_BACKTRACE", "short"); | 69 | env::set_var("RUST_BACKTRACE", "short"); |
61 | 70 | ||
62 | let log_file = match log_file { | 71 | let log_file = match log_file { |
@@ -69,7 +78,7 @@ fn setup_logging(log_file: Option<PathBuf>, flush_file: bool) -> Result<()> { | |||
69 | None => None, | 78 | None => None, |
70 | }; | 79 | }; |
71 | let filter = env::var("RA_LOG").ok(); | 80 | let filter = env::var("RA_LOG").ok(); |
72 | logger::Logger::new(log_file, flush_file, filter.as_deref()).install(); | 81 | logger::Logger::new(log_file, no_buffering, filter.as_deref()).install(); |
73 | 82 | ||
74 | tracing_setup::setup_tracing()?; | 83 | tracing_setup::setup_tracing()?; |
75 | 84 | ||