@@ -10,7 +10,7 @@ extern crate rustc_driver as _;
10
10
11
11
mod rustc_wrapper;
12
12
13
- use std:: { env, fs, path:: PathBuf , process:: ExitCode , sync:: Arc } ;
13
+ use std:: { env, fs, path:: PathBuf , process:: ExitCode , sync:: Arc , thread :: sleep } ;
14
14
15
15
use anyhow:: Context ;
16
16
use lsp_server:: Connection ;
@@ -44,11 +44,7 @@ fn actual_main() -> anyhow::Result<ExitCode> {
44
44
45
45
#[ cfg( debug_assertions) ]
46
46
if flags. wait_dbg || env:: var ( "RA_WAIT_DBG" ) . is_ok ( ) {
47
- #[ allow( unused_mut) ]
48
- let mut d = 4 ;
49
- while d == 4 {
50
- d = 4 ;
51
- }
47
+ wait_for_debugger ( ) ;
52
48
}
53
49
54
50
if let Err ( e) = setup_logging ( flags. log_file . clone ( ) ) {
@@ -96,6 +92,28 @@ fn actual_main() -> anyhow::Result<ExitCode> {
96
92
Ok ( ExitCode :: SUCCESS )
97
93
}
98
94
95
+ #[ cfg( debug_assertions) ]
96
+ fn wait_for_debugger ( ) {
97
+ #[ cfg( target_os = "windows" ) ]
98
+ {
99
+ use windows_sys:: Win32 :: System :: Diagnostics :: Debug :: IsDebuggerPresent ;
100
+ // SAFETY: WinAPI generated code that is defensively marked `unsafe` but
101
+ // in practice can not be used in an unsafe way.
102
+ while unsafe { IsDebuggerPresent ( ) } == 0 {
103
+ sleep ( std:: time:: Duration :: from_millis ( 100 ) ) ;
104
+ }
105
+ }
106
+ #[ cfg( not( target_os = "windows" ) ) ]
107
+ {
108
+ #[ allow( unused_mut) ]
109
+ let mut d = 4 ;
110
+ while d == 4 {
111
+ d = 4 ;
112
+ sleep ( std:: time:: Duration :: from_millis ( 100 ) ) ;
113
+ }
114
+ }
115
+ }
116
+
99
117
fn setup_logging ( log_file_flag : Option < PathBuf > ) -> anyhow:: Result < ( ) > {
100
118
if cfg ! ( windows) {
101
119
// This is required so that windows finds our pdb that is placed right beside the exe.
0 commit comments