diff --git a/src/tools/rust-analyzer/crates/ide-db/src/prime_caches.rs b/src/tools/rust-analyzer/crates/ide-db/src/prime_caches.rs index 1ca52060118a..b4486d150269 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/prime_caches.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/prime_caches.rs @@ -29,7 +29,7 @@ pub struct ParallelPrimeCachesProgress { pub fn parallel_prime_caches( db: &RootDatabase, - num_worker_threads: u8, + num_worker_threads: usize, cb: &(dyn Fn(ParallelPrimeCachesProgress) + Sync), ) { let _p = tracing::info_span!("parallel_prime_caches").entered(); diff --git a/src/tools/rust-analyzer/crates/ide/src/lib.rs b/src/tools/rust-analyzer/crates/ide/src/lib.rs index e9408bf89766..a2ac62341df9 100644 --- a/src/tools/rust-analyzer/crates/ide/src/lib.rs +++ b/src/tools/rust-analyzer/crates/ide/src/lib.rs @@ -284,7 +284,7 @@ impl Analysis { }) } - pub fn parallel_prime_caches(&self, num_worker_threads: u8, cb: F) -> Cancellable<()> + pub fn parallel_prime_caches(&self, num_worker_threads: usize, cb: F) -> Cancellable<()> where F: Fn(ParallelPrimeCachesProgress) + Sync + std::panic::UnwindSafe, { diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs index 497fd67e92a7..98686f2cd53a 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs @@ -73,7 +73,7 @@ config_data! { /// Warm up caches on project load. cachePriming_enable: bool = true, /// How many worker threads to handle priming caches. The default `0` means to pick automatically. - cachePriming_numThreads: ParallelCachePrimingNumThreads = 0u8, + cachePriming_numThreads: NumThreads = NumThreads::Physical, /// Pass `--all-targets` to cargo invocation. cargo_allTargets: bool = true, @@ -583,7 +583,7 @@ config_data! { notifications_unindexedProject: bool = false, /// How many worker threads in the main loop. The default `null` means to pick automatically. - numThreads: Option = None, + numThreads: Option = None, /// Expand attribute macros. Requires `#rust-analyzer.procMacro.enable#` to be set. procMacro_attributes_enable: bool = true, @@ -2095,15 +2095,22 @@ impl Config { } } - pub fn prime_caches_num_threads(&self) -> u8 { - match *self.cachePriming_numThreads() { - 0 => num_cpus::get_physical().try_into().unwrap_or(u8::MAX), - n => n, + pub fn prime_caches_num_threads(&self) -> usize { + match self.cachePriming_numThreads() { + NumThreads::Concrete(0) | NumThreads::Physical => num_cpus::get_physical(), + &NumThreads::Concrete(n) => n, + NumThreads::Logical => num_cpus::get(), } } pub fn main_loop_num_threads(&self) -> usize { - self.numThreads().unwrap_or(num_cpus::get_physical()) + match self.numThreads() { + Some(NumThreads::Concrete(0)) | None | Some(NumThreads::Physical) => { + num_cpus::get_physical() + } + &Some(NumThreads::Concrete(n)) => n, + Some(NumThreads::Logical) => num_cpus::get(), + } } pub fn typing_autoclose_angle(&self) -> bool { @@ -2524,6 +2531,15 @@ pub enum TargetDirectory { Directory(Utf8PathBuf), } +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(rename_all = "snake_case")] +#[serde(untagged)] +pub enum NumThreads { + Physical, + Logical, + Concrete(usize), +} + macro_rules! _default_val { (@verbatim: $s:literal, $ty:ty) => {{ let default_: $ty = serde_json::from_str(&$s).unwrap(); @@ -3260,6 +3276,24 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json }, ], }, + "Option" => set! { + "anyOf": [ + { + "type": "null" + }, + { + "type": "number" + }, + { + "type": "string", + "enum": ["physical", "logical", ], + "enumDescriptions": [ + "Use the number of physical cores", + "Use the number of logical cores", + ], + }, + ], + }, _ => panic!("missing entry for {ty}: {default}"), }