Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/ide-db/src/prime_caches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 6 additions & 11 deletions crates/ide/src/call_hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ pub struct CallItem {
pub ranges: Vec<TextRange>,
}

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,
Expand Down Expand Up @@ -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;
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion crates/ide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl Analysis {
})
}

pub fn parallel_prime_caches<F>(&self, num_worker_threads: u8, cb: F) -> Cancellable<()>
pub fn parallel_prime_caches<F>(&self, num_worker_threads: usize, cb: F) -> Cancellable<()>
where
F: Fn(ParallelPrimeCachesProgress) + Sync + std::panic::UnwindSafe,
{
Expand Down
2 changes: 1 addition & 1 deletion crates/ide/src/syntax_highlighting/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub(super) fn highlight_escape_string<T: IsString>(
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;
}
Expand Down
176 changes: 92 additions & 84 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<usize> = None,
numThreads: Option<NumThreads> = None,

/// Expand attribute macros. Requires `#rust-analyzer.procMacro.enable#` to be set.
procMacro_attributes_enable: bool = true,
Expand Down Expand Up @@ -968,8 +968,6 @@ macro_rules! try_or_def {
};
}

type ParallelCachePrimingNumThreads = u8;

#[derive(Debug, Clone, Eq, PartialEq)]
pub enum LinkedProject {
ProjectManifest(ProjectManifest),
Expand Down Expand Up @@ -2095,15 +2093,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 {
Expand Down Expand Up @@ -2198,51 +2203,6 @@ macro_rules! create_bool_or_string_serde {
create_bool_or_string_serde!(true_or_always<true, "always">);
create_bool_or_string_serde!(false_or_never<false, "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<E: serde::de::Error>(self, value: &str) -> Result<Self::Value, E> {
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<S>(serializer: S) -> Result<S::Ok, S::Error>
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)]
Expand Down Expand Up @@ -2357,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<String>),
}

Expand All @@ -2382,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)]
Expand All @@ -2413,36 +2375,39 @@ enum ClosureStyle {
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(untagged)]
#[serde(rename_all = "snake_case")]
enum ReborrowHintsDef {
Mutable,
#[serde(with = "true_or_always")]
#[serde(untagged)]
Always,
#[serde(with = "false_or_never")]
#[serde(untagged)]
Never,
#[serde(with = "unit_v::mutable")]
Mutable,
}

#[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)]
Expand All @@ -2466,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,
}

Expand All @@ -2495,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,
}

Expand All @@ -2524,6 +2487,15 @@ pub enum TargetDirectory {
Directory(Utf8PathBuf),
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum NumThreads {
Physical,
Logical,
#[serde(untagged)]
Concrete(usize),
}

macro_rules! _default_val {
(@verbatim: $s:literal, $ty:ty) => {{
let default_: $ty = serde_json::from_str(&$s).unwrap();
Expand Down Expand Up @@ -2776,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 {
Expand Down Expand Up @@ -3034,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": [
Expand Down Expand Up @@ -3260,7 +3231,44 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
},
],
},
_ => panic!("missing entry for {ty}: {default}"),
"NumThreads" => set! {
"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",
],
},
],
},
"Option<NumThreads>" => 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()
Expand Down Expand Up @@ -3341,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();
Expand Down
Loading