diff options
| author | bors <bors@rust-lang.org> | 2022-04-22 15:46:30 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-04-22 15:46:30 +0000 |
| commit | 1894473b1973b366ee8d0cfa2c2a4459b1709b9c (patch) | |
| tree | 82147c6805aee561eeb8ad2d9c0f6b90e14ab194 | |
| parent | ebe6e30f0459ef3eedfb4fef9f02bd95db111d2d (diff) | |
| parent | b5a56c7d53c3b00df4b580e9d48c59fa7df48cf5 (diff) | |
| download | rust-1894473b1973b366ee8d0cfa2c2a4459b1709b9c.tar.gz rust-1894473b1973b366ee8d0cfa2c2a4459b1709b9c.zip | |
Auto merge of #12058 - jonas-schievink:one-thread-with-extra-stack-please, r=jonas-schievink
fix: Spawn a new thread with a larger stack for the LSP and proc-macro server This runs the server and proc-macro process in dedicated threads with 8 MB of stack space to paper over OS differences and fix occasional stack overflows. This hopefully resolves https://github.com/rust-lang/rust-analyzer/issues/11669
| -rw-r--r-- | crates/rust-analyzer/src/bin/main.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index 15ae0e64806..df61ba8eec8 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs @@ -77,9 +77,13 @@ fn try_main() -> Result<()> { println!("{}", flags::RustAnalyzer::HELP); return Ok(()); } - run_server()? + with_extra_thread("rust-analyzer server thread", run_server)?; + } + flags::RustAnalyzerCmd::ProcMacro(flags::ProcMacro) => { + with_extra_thread("rust-analyzer proc-macro expander", || { + proc_macro_srv::cli::run().map_err(Into::into) + })?; } - flags::RustAnalyzerCmd::ProcMacro(flags::ProcMacro) => proc_macro_srv::cli::run()?, flags::RustAnalyzerCmd::Parse(cmd) => cmd.run()?, flags::RustAnalyzerCmd::Symbols(cmd) => cmd.run()?, flags::RustAnalyzerCmd::Highlight(cmd) => cmd.run()?, @@ -128,6 +132,23 @@ fn setup_logging(log_file: Option<&Path>) -> Result<()> { Ok(()) } +const STACK_SIZE: usize = 1024 * 1024 * 8; + +/// Parts of rust-analyzer can use a lot of stack space, and some operating systems only give us +/// 1 MB by default (eg. Windows), so this spawns a new thread with hopefully sufficient stack +/// space. +fn with_extra_thread( + thread_name: impl Into<String>, + f: impl FnOnce() -> Result<()> + Send + 'static, +) -> Result<()> { + let handle = + std::thread::Builder::new().name(thread_name.into()).stack_size(STACK_SIZE).spawn(f)?; + match handle.join() { + Ok(res) => res, + Err(panic) => std::panic::resume_unwind(panic), + } +} + fn run_server() -> Result<()> { tracing::info!("server version {} will start", env!("REV")); |
