mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Spawn a new thread with a larger stack for the server
This commit is contained in:
parent
b6b5214c66
commit
b5a56c7d53
1 changed files with 23 additions and 2 deletions
|
@ -77,9 +77,13 @@ fn try_main() -> Result<()> {
|
||||||
println!("{}", flags::RustAnalyzer::HELP);
|
println!("{}", flags::RustAnalyzer::HELP);
|
||||||
return Ok(());
|
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::Parse(cmd) => cmd.run()?,
|
||||||
flags::RustAnalyzerCmd::Symbols(cmd) => cmd.run()?,
|
flags::RustAnalyzerCmd::Symbols(cmd) => cmd.run()?,
|
||||||
flags::RustAnalyzerCmd::Highlight(cmd) => cmd.run()?,
|
flags::RustAnalyzerCmd::Highlight(cmd) => cmd.run()?,
|
||||||
|
@ -128,6 +132,23 @@ fn setup_logging(log_file: Option<&Path>) -> Result<()> {
|
||||||
Ok(())
|
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<()> {
|
fn run_server() -> Result<()> {
|
||||||
tracing::info!("server version {} will start", env!("REV"));
|
tracing::info!("server version {} will start", env!("REV"));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue