@@ -73,7 +73,7 @@ config_data! {
7373 /// Warm up caches on project load.
7474 cachePriming_enable: bool = true ,
7575 /// How many worker threads to handle priming caches. The default `0` means to pick automatically.
76- cachePriming_numThreads: ParallelCachePrimingNumThreads = 0u8 ,
76+ cachePriming_numThreads: NumThreads = NumThreads :: Physical ,
7777
7878 /// Pass `--all-targets` to cargo invocation.
7979 cargo_allTargets: bool = true ,
@@ -583,7 +583,7 @@ config_data! {
583583 notifications_unindexedProject: bool = false ,
584584
585585 /// How many worker threads in the main loop. The default `null` means to pick automatically.
586- numThreads: Option <usize > = None ,
586+ numThreads: Option <NumThreads > = None ,
587587
588588 /// Expand attribute macros. Requires `#rust-analyzer.procMacro.enable#` to be set.
589589 procMacro_attributes_enable: bool = true ,
@@ -968,8 +968,6 @@ macro_rules! try_or_def {
968968 } ;
969969}
970970
971- type ParallelCachePrimingNumThreads = u8 ;
972-
973971#[ derive( Debug , Clone , Eq , PartialEq ) ]
974972pub enum LinkedProject {
975973 ProjectManifest ( ProjectManifest ) ,
@@ -2095,15 +2093,22 @@ impl Config {
20952093 }
20962094 }
20972095
2098- pub fn prime_caches_num_threads ( & self ) -> u8 {
2099- match * self . cachePriming_numThreads ( ) {
2100- 0 => num_cpus:: get_physical ( ) . try_into ( ) . unwrap_or ( u8:: MAX ) ,
2101- n => n,
2096+ pub fn prime_caches_num_threads ( & self ) -> usize {
2097+ match self . cachePriming_numThreads ( ) {
2098+ NumThreads :: Concrete ( 0 ) | NumThreads :: Physical => num_cpus:: get_physical ( ) ,
2099+ & NumThreads :: Concrete ( n) => n,
2100+ NumThreads :: Logical => num_cpus:: get ( ) ,
21022101 }
21032102 }
21042103
21052104 pub fn main_loop_num_threads ( & self ) -> usize {
2106- self . numThreads ( ) . unwrap_or ( num_cpus:: get_physical ( ) )
2105+ match self . numThreads ( ) {
2106+ Some ( NumThreads :: Concrete ( 0 ) ) | None | Some ( NumThreads :: Physical ) => {
2107+ num_cpus:: get_physical ( )
2108+ }
2109+ & Some ( NumThreads :: Concrete ( n) ) => n,
2110+ Some ( NumThreads :: Logical ) => num_cpus:: get ( ) ,
2111+ }
21072112 }
21082113
21092114 pub fn typing_autoclose_angle ( & self ) -> bool {
@@ -2198,51 +2203,6 @@ macro_rules! create_bool_or_string_serde {
21982203create_bool_or_string_serde ! ( true_or_always<true , "always" >) ;
21992204create_bool_or_string_serde ! ( false_or_never<false , "never" >) ;
22002205
2201- macro_rules! named_unit_variant {
2202- ( $variant: ident) => {
2203- pub ( super ) mod $variant {
2204- pub ( in super :: super ) fn deserialize<' de, D >( deserializer: D ) -> Result <( ) , D :: Error >
2205- where
2206- D : serde:: Deserializer <' de>,
2207- {
2208- struct V ;
2209- impl <' de> serde:: de:: Visitor <' de> for V {
2210- type Value = ( ) ;
2211- fn expecting( & self , f: & mut std:: fmt:: Formatter <' _>) -> std:: fmt:: Result {
2212- f. write_str( concat!( "\" " , stringify!( $variant) , "\" " ) )
2213- }
2214- fn visit_str<E : serde:: de:: Error >( self , value: & str ) -> Result <Self :: Value , E > {
2215- if value == stringify!( $variant) {
2216- Ok ( ( ) )
2217- } else {
2218- Err ( E :: invalid_value( serde:: de:: Unexpected :: Str ( value) , & self ) )
2219- }
2220- }
2221- }
2222- deserializer. deserialize_str( V )
2223- }
2224- pub ( in super :: super ) fn serialize<S >( serializer: S ) -> Result <S :: Ok , S :: Error >
2225- where
2226- S : serde:: Serializer ,
2227- {
2228- serializer. serialize_str( stringify!( $variant) )
2229- }
2230- }
2231- } ;
2232- }
2233-
2234- mod unit_v {
2235- named_unit_variant ! ( all) ;
2236- named_unit_variant ! ( skip_trivial) ;
2237- named_unit_variant ! ( mutable) ;
2238- named_unit_variant ! ( reborrow) ;
2239- named_unit_variant ! ( fieldless) ;
2240- named_unit_variant ! ( with_block) ;
2241- named_unit_variant ! ( decimal) ;
2242- named_unit_variant ! ( hexadecimal) ;
2243- named_unit_variant ! ( both) ;
2244- }
2245-
22462206#[ derive( Serialize , Deserialize , Debug , Clone , Copy , PartialEq ) ]
22472207#[ serde( rename_all = "snake_case" ) ]
22482208#[ derive( Default ) ]
@@ -2357,10 +2317,10 @@ pub(crate) enum CallableCompletionDef {
23572317}
23582318
23592319#[ derive( Serialize , Deserialize , Debug , Clone ) ]
2360- #[ serde( untagged ) ]
2320+ #[ serde( rename_all = "snake_case" ) ]
23612321enum CargoFeaturesDef {
2362- #[ serde( with = "unit_v::all" ) ]
23632322 All ,
2323+ #[ serde( untagged) ]
23642324 Selected ( Vec < String > ) ,
23652325}
23662326
@@ -2382,25 +2342,27 @@ enum InvocationLocation {
23822342}
23832343
23842344#[ derive( Serialize , Deserialize , Debug , Clone ) ]
2385- #[ serde( untagged ) ]
2345+ #[ serde( rename_all = "snake_case" ) ]
23862346enum LifetimeElisionDef {
2347+ SkipTrivial ,
23872348 #[ serde( with = "true_or_always" ) ]
2349+ #[ serde( untagged) ]
23882350 Always ,
23892351 #[ serde( with = "false_or_never" ) ]
2352+ #[ serde( untagged) ]
23902353 Never ,
2391- #[ serde( with = "unit_v::skip_trivial" ) ]
2392- SkipTrivial ,
23932354}
23942355
23952356#[ derive( Serialize , Deserialize , Debug , Clone ) ]
2396- #[ serde( untagged ) ]
2357+ #[ serde( rename_all = "snake_case" ) ]
23972358enum ClosureReturnTypeHintsDef {
2359+ WithBlock ,
23982360 #[ serde( with = "true_or_always" ) ]
2361+ #[ serde( untagged) ]
23992362 Always ,
24002363 #[ serde( with = "false_or_never" ) ]
2364+ #[ serde( untagged) ]
24012365 Never ,
2402- #[ serde( with = "unit_v::with_block" ) ]
2403- WithBlock ,
24042366}
24052367
24062368#[ derive( Serialize , Deserialize , Debug , Clone ) ]
@@ -2413,36 +2375,39 @@ enum ClosureStyle {
24132375}
24142376
24152377#[ derive( Serialize , Deserialize , Debug , Clone ) ]
2416- #[ serde( untagged ) ]
2378+ #[ serde( rename_all = "snake_case" ) ]
24172379enum ReborrowHintsDef {
2380+ Mutable ,
24182381 #[ serde( with = "true_or_always" ) ]
2382+ #[ serde( untagged) ]
24192383 Always ,
24202384 #[ serde( with = "false_or_never" ) ]
2385+ #[ serde( untagged) ]
24212386 Never ,
2422- #[ serde( with = "unit_v::mutable" ) ]
2423- Mutable ,
24242387}
24252388
24262389#[ derive( Serialize , Deserialize , Debug , Clone ) ]
2427- #[ serde( untagged ) ]
2390+ #[ serde( rename_all = "snake_case" ) ]
24282391enum AdjustmentHintsDef {
2392+ Reborrow ,
24292393 #[ serde( with = "true_or_always" ) ]
2394+ #[ serde( untagged) ]
24302395 Always ,
24312396 #[ serde( with = "false_or_never" ) ]
2397+ #[ serde( untagged) ]
24322398 Never ,
2433- #[ serde( with = "unit_v::reborrow" ) ]
2434- Reborrow ,
24352399}
24362400
24372401#[ derive( Serialize , Deserialize , Debug , Clone ) ]
2438- #[ serde( untagged ) ]
2402+ #[ serde( rename_all = "snake_case" ) ]
24392403enum DiscriminantHintsDef {
2404+ Fieldless ,
24402405 #[ serde( with = "true_or_always" ) ]
2406+ #[ serde( untagged) ]
24412407 Always ,
24422408 #[ serde( with = "false_or_never" ) ]
2409+ #[ serde( untagged) ]
24432410 Never ,
2444- #[ serde( with = "unit_v::fieldless" ) ]
2445- Fieldless ,
24462411}
24472412
24482413#[ derive( Serialize , Deserialize , Debug , Clone ) ]
@@ -2466,9 +2431,11 @@ enum FilesWatcherDef {
24662431#[ serde( rename_all = "snake_case" ) ]
24672432enum ImportPrefixDef {
24682433 Plain ,
2469- #[ serde( alias = "self" ) ]
2434+ #[ serde( rename = "self" ) ]
2435+ #[ serde( alias = "by_self" ) ]
24702436 BySelf ,
2471- #[ serde( alias = "crate" ) ]
2437+ #[ serde( rename = "crate" ) ]
2438+ #[ serde( alias = "by_crate" ) ]
24722439 ByCrate ,
24732440}
24742441
@@ -2495,13 +2462,9 @@ enum WorkspaceSymbolSearchKindDef {
24952462
24962463#[ derive( Serialize , Deserialize , Debug , Copy , Clone , PartialEq ) ]
24972464#[ serde( rename_all = "snake_case" ) ]
2498- #[ serde( untagged) ]
24992465enum MemoryLayoutHoverRenderKindDef {
2500- #[ serde( with = "unit_v::decimal" ) ]
25012466 Decimal ,
2502- #[ serde( with = "unit_v::hexadecimal" ) ]
25032467 Hexadecimal ,
2504- #[ serde( with = "unit_v::both" ) ]
25052468 Both ,
25062469}
25072470
@@ -2524,6 +2487,15 @@ pub enum TargetDirectory {
25242487 Directory ( Utf8PathBuf ) ,
25252488}
25262489
2490+ #[ derive( Serialize , Deserialize , Debug , Clone , PartialEq ) ]
2491+ #[ serde( rename_all = "snake_case" ) ]
2492+ pub enum NumThreads {
2493+ Physical ,
2494+ Logical ,
2495+ #[ serde( untagged) ]
2496+ Concrete ( usize ) ,
2497+ }
2498+
25272499macro_rules! _default_val {
25282500 ( @verbatim: $s: literal, $ty: ty) => { {
25292501 let default_: $ty = serde_json:: from_str( & $s) . unwrap( ) ;
@@ -2776,6 +2748,10 @@ impl FullConfigInput {
27762748 ClientConfigInput :: schema_fields ( & mut fields) ;
27772749 fields. sort_by_key ( |& ( x, ..) | x) ;
27782750 fields
2751+ . iter ( )
2752+ . tuple_windows ( )
2753+ . for_each ( |( a, b) | assert ! ( a. 0 != b. 0 , "{a:?} duplicate field" ) ) ;
2754+ fields
27792755 }
27802756
27812757 fn json_schema ( ) -> serde_json:: Value {
@@ -3034,11 +3010,6 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
30343010 "Search for all symbols kinds."
30353011 ] ,
30363012 } ,
3037- "ParallelCachePrimingNumThreads" => set ! {
3038- "type" : "number" ,
3039- "minimum" : 0 ,
3040- "maximum" : 255
3041- } ,
30423013 "LifetimeElisionDef" => set ! {
30433014 "type" : "string" ,
30443015 "enum" : [
@@ -3260,7 +3231,44 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
32603231 } ,
32613232 ] ,
32623233 } ,
3263- _ => panic ! ( "missing entry for {ty}: {default}" ) ,
3234+ "NumThreads" => set ! {
3235+ "anyOf" : [
3236+ {
3237+ "type" : "number" ,
3238+ "minimum" : 0 ,
3239+ "maximum" : 255
3240+ } ,
3241+ {
3242+ "type" : "string" ,
3243+ "enum" : [ "physical" , "logical" , ] ,
3244+ "enumDescriptions" : [
3245+ "Use the number of physical cores" ,
3246+ "Use the number of logical cores" ,
3247+ ] ,
3248+ } ,
3249+ ] ,
3250+ } ,
3251+ "Option<NumThreads>" => set ! {
3252+ "anyOf" : [
3253+ {
3254+ "type" : "null"
3255+ } ,
3256+ {
3257+ "type" : "number" ,
3258+ "minimum" : 0 ,
3259+ "maximum" : 255
3260+ } ,
3261+ {
3262+ "type" : "string" ,
3263+ "enum" : [ "physical" , "logical" , ] ,
3264+ "enumDescriptions" : [
3265+ "Use the number of physical cores" ,
3266+ "Use the number of logical cores" ,
3267+ ] ,
3268+ } ,
3269+ ] ,
3270+ } ,
3271+ _ => panic ! ( "missing entry for {ty}: {default} (field {field})" ) ,
32643272 }
32653273
32663274 map. into ( )
@@ -3341,7 +3349,7 @@ mod tests {
33413349 . trim_start_matches ( '[' )
33423350 . trim_end_matches ( ']' )
33433351 . replace ( " " , " " )
3344- . replace ( '\n' , "\n " )
3352+ . replace ( '\n' , "\n " )
33453353 . trim_start_matches ( '\n' )
33463354 . trim_end ( )
33473355 . to_owned ( ) ;
0 commit comments