diff --git a/crates/ide/src/call_hierarchy.rs b/crates/ide/src/call_hierarchy.rs index 654a1cd316..f7e5b40dde 100644 --- a/crates/ide/src/call_hierarchy.rs +++ b/crates/ide/src/call_hierarchy.rs @@ -19,13 +19,6 @@ pub struct CallItem { pub ranges: Vec, } -impl CallItem { - #[cfg(test)] - pub(crate) fn debug_render(&self) -> String { - format!("{} : {:?}", self.target.debug_render(), self.ranges) - } -} - pub(crate) fn call_hierarchy( db: &RootDatabase, position: FilePosition, @@ -159,6 +152,10 @@ mod tests { expected_incoming: Expect, expected_outgoing: Expect, ) { + fn debug_render(item: crate::CallItem) -> String { + format!("{} : {:?}", item.target.debug_render(), item.ranges) + } + let (analysis, pos) = fixture::position(ra_fixture); let mut navs = analysis.call_hierarchy(pos).unwrap().unwrap().info; @@ -169,12 +166,10 @@ mod tests { let item_pos = FilePosition { file_id: nav.file_id, offset: nav.focus_or_full_range().start() }; let incoming_calls = analysis.incoming_calls(item_pos).unwrap().unwrap(); - expected_incoming - .assert_eq(&incoming_calls.into_iter().map(|call| call.debug_render()).join("\n")); + expected_incoming.assert_eq(&incoming_calls.into_iter().map(debug_render).join("\n")); let outgoing_calls = analysis.outgoing_calls(item_pos).unwrap().unwrap(); - expected_outgoing - .assert_eq(&outgoing_calls.into_iter().map(|call| call.debug_render()).join("\n")); + expected_outgoing.assert_eq(&outgoing_calls.into_iter().map(debug_render).join("\n")); } #[test] diff --git a/crates/ide/src/syntax_highlighting/escape.rs b/crates/ide/src/syntax_highlighting/escape.rs index 2f387968c9..552ce9cd8c 100644 --- a/crates/ide/src/syntax_highlighting/escape.rs +++ b/crates/ide/src/syntax_highlighting/escape.rs @@ -28,7 +28,7 @@ pub(super) fn highlight_escape_string( pub(super) fn highlight_escape_char(stack: &mut Highlights, char: &Char, start: TextSize) { if char.value().is_err() { // We do not emit invalid escapes highlighting here. The lexer would likely be in a bad - // state and this token contains junks, since `'` is not a reliable delimiter (consider + // state and this token contains junk, since `'` is not a reliable delimiter (consider // lifetimes). Nonetheless, parser errors should already be emitted. return; } diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 98686f2cd5..e8504979be 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -968,8 +968,6 @@ macro_rules! try_or_def { }; } -type ParallelCachePrimingNumThreads = u8; - #[derive(Debug, Clone, Eq, PartialEq)] pub enum LinkedProject { ProjectManifest(ProjectManifest), @@ -2205,51 +2203,6 @@ macro_rules! create_bool_or_string_serde { create_bool_or_string_serde!(true_or_always); create_bool_or_string_serde!(false_or_never); -macro_rules! named_unit_variant { - ($variant:ident) => { - pub(super) mod $variant { - pub(in super::super) fn deserialize<'de, D>(deserializer: D) -> Result<(), D::Error> - where - D: serde::Deserializer<'de>, - { - struct V; - impl<'de> serde::de::Visitor<'de> for V { - type Value = (); - fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(concat!("\"", stringify!($variant), "\"")) - } - fn visit_str(self, value: &str) -> Result { - if value == stringify!($variant) { - Ok(()) - } else { - Err(E::invalid_value(serde::de::Unexpected::Str(value), &self)) - } - } - } - deserializer.deserialize_str(V) - } - pub(in super::super) fn serialize(serializer: S) -> Result - where - S: serde::Serializer, - { - serializer.serialize_str(stringify!($variant)) - } - } - }; -} - -mod unit_v { - named_unit_variant!(all); - named_unit_variant!(skip_trivial); - named_unit_variant!(mutable); - named_unit_variant!(reborrow); - named_unit_variant!(fieldless); - named_unit_variant!(with_block); - named_unit_variant!(decimal); - named_unit_variant!(hexadecimal); - named_unit_variant!(both); -} - #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] #[serde(rename_all = "snake_case")] #[derive(Default)] @@ -2364,10 +2317,10 @@ pub(crate) enum CallableCompletionDef { } #[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] enum CargoFeaturesDef { - #[serde(with = "unit_v::all")] All, + #[serde(untagged)] Selected(Vec), } @@ -2389,25 +2342,27 @@ enum InvocationLocation { } #[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] enum LifetimeElisionDef { + SkipTrivial, #[serde(with = "true_or_always")] + #[serde(untagged)] Always, #[serde(with = "false_or_never")] + #[serde(untagged)] Never, - #[serde(with = "unit_v::skip_trivial")] - SkipTrivial, } #[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] enum ClosureReturnTypeHintsDef { + WithBlock, #[serde(with = "true_or_always")] + #[serde(untagged)] Always, #[serde(with = "false_or_never")] + #[serde(untagged)] Never, - #[serde(with = "unit_v::with_block")] - WithBlock, } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -2420,36 +2375,39 @@ enum ClosureStyle { } #[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] enum ReborrowHintsDef { - #[serde(with = "true_or_always")] - Always, - #[serde(with = "false_or_never")] - Never, - #[serde(with = "unit_v::mutable")] Mutable, + #[serde(with = "true_or_always")] + #[serde(untagged)] + Always, + #[serde(with = "false_or_never")] + #[serde(untagged)] + Never, } #[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] enum AdjustmentHintsDef { + Reborrow, #[serde(with = "true_or_always")] + #[serde(untagged)] Always, #[serde(with = "false_or_never")] + #[serde(untagged)] Never, - #[serde(with = "unit_v::reborrow")] - Reborrow, } #[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(untagged)] +#[serde(rename_all = "snake_case")] enum DiscriminantHintsDef { + Fieldless, #[serde(with = "true_or_always")] + #[serde(untagged)] Always, #[serde(with = "false_or_never")] + #[serde(untagged)] Never, - #[serde(with = "unit_v::fieldless")] - Fieldless, } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -2473,9 +2431,11 @@ enum FilesWatcherDef { #[serde(rename_all = "snake_case")] enum ImportPrefixDef { Plain, - #[serde(alias = "self")] + #[serde(rename = "self")] + #[serde(alias = "by_self")] BySelf, - #[serde(alias = "crate")] + #[serde(rename = "crate")] + #[serde(alias = "by_crate")] ByCrate, } @@ -2502,13 +2462,9 @@ enum WorkspaceSymbolSearchKindDef { #[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq)] #[serde(rename_all = "snake_case")] -#[serde(untagged)] enum MemoryLayoutHoverRenderKindDef { - #[serde(with = "unit_v::decimal")] Decimal, - #[serde(with = "unit_v::hexadecimal")] Hexadecimal, - #[serde(with = "unit_v::both")] Both, } @@ -2533,10 +2489,10 @@ pub enum TargetDirectory { #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] #[serde(rename_all = "snake_case")] -#[serde(untagged)] pub enum NumThreads { Physical, Logical, + #[serde(untagged)] Concrete(usize), } @@ -2792,6 +2748,10 @@ impl FullConfigInput { ClientConfigInput::schema_fields(&mut fields); fields.sort_by_key(|&(x, ..)| x); fields + .iter() + .tuple_windows() + .for_each(|(a, b)| assert!(a.0 != b.0, "{a:?} duplicate field")); + fields } fn json_schema() -> serde_json::Value { @@ -3050,11 +3010,6 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json "Search for all symbols kinds." ], }, - "ParallelCachePrimingNumThreads" => set! { - "type": "number", - "minimum": 0, - "maximum": 255 - }, "LifetimeElisionDef" => set! { "type": "string", "enum": [ @@ -3276,13 +3231,12 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json }, ], }, - "Option" => set! { + "NumThreads" => set! { "anyOf": [ { - "type": "null" - }, - { - "type": "number" + "type": "number", + "minimum": 0, + "maximum": 255 }, { "type": "string", @@ -3294,7 +3248,27 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json }, ], }, - _ => panic!("missing entry for {ty}: {default}"), + "Option" => set! { + "anyOf": [ + { + "type": "null" + }, + { + "type": "number", + "minimum": 0, + "maximum": 255 + }, + { + "type": "string", + "enum": ["physical", "logical", ], + "enumDescriptions": [ + "Use the number of physical cores", + "Use the number of logical cores", + ], + }, + ], + }, + _ => panic!("missing entry for {ty}: {default} (field {field})"), } map.into() @@ -3375,7 +3349,7 @@ mod tests { .trim_start_matches('[') .trim_end_matches(']') .replace(" ", " ") - .replace('\n', "\n ") + .replace('\n', "\n ") .trim_start_matches('\n') .trim_end() .to_owned(); diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index 8993a46d2b..14aae91741 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc @@ -19,7 +19,7 @@ Term search fuel in "units of work" for assists (Defaults to 400). -- Warm up caches on project load. -- -[[rust-analyzer.cachePriming.numThreads]]rust-analyzer.cachePriming.numThreads (default: `0`):: +[[rust-analyzer.cachePriming.numThreads]]rust-analyzer.cachePriming.numThreads (default: `"physical"`):: + -- How many worker threads to handle priming caches. The default `0` means to pick automatically. diff --git a/editors/code/package.json b/editors/code/package.json index cd11b56d15..b447106d99 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -609,10 +609,25 @@ "properties": { "rust-analyzer.cachePriming.numThreads": { "markdownDescription": "How many worker threads to handle priming caches. The default `0` means to pick automatically.", - "default": 0, - "type": "number", - "minimum": 0, - "maximum": 255 + "default": "physical", + "anyOf": [ + { + "type": "number", + "minimum": 0, + "maximum": 255 + }, + { + "type": "string", + "enum": [ + "physical", + "logical" + ], + "enumDescriptions": [ + "Use the number of physical cores", + "Use the number of logical cores" + ] + } + ] } } }, @@ -2225,11 +2240,27 @@ "rust-analyzer.numThreads": { "markdownDescription": "How many worker threads in the main loop. The default `null` means to pick automatically.", "default": null, - "type": [ - "null", - "integer" - ], - "minimum": 0 + "anyOf": [ + { + "type": "null" + }, + { + "type": "number", + "minimum": 0, + "maximum": 255 + }, + { + "type": "string", + "enum": [ + "physical", + "logical" + ], + "enumDescriptions": [ + "Use the number of physical cores", + "Use the number of logical cores" + ] + } + ] } } },