use num_format

This commit is contained in:
Milo 2021-06-19 08:12:46 +01:00
parent d2f7e0fea4
commit 664cc8c754
5 changed files with 38 additions and 8 deletions

33
Cargo.lock generated
View File

@ -47,6 +47,15 @@ version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344"
[[package]]
name = "arrayvec"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9"
dependencies = [
"nodrop",
]
[[package]]
name = "arrayvec"
version = "0.7.0"
@ -459,7 +468,7 @@ dependencies = [
name = "hir"
version = "0.0.0"
dependencies = [
"arrayvec",
"arrayvec 0.7.0",
"base_db",
"cfg",
"either",
@ -529,7 +538,7 @@ dependencies = [
name = "hir_ty"
version = "0.0.0"
dependencies = [
"arrayvec",
"arrayvec 0.7.0",
"base_db",
"chalk-ir",
"chalk-recursive",
@ -582,6 +591,7 @@ dependencies = [
"indexmap",
"itertools",
"log",
"num-format",
"oorandom",
"profile",
"pulldown-cmark",
@ -934,6 +944,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "nodrop"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
[[package]]
name = "notify"
version = "5.0.0-pre.9"
@ -960,6 +976,16 @@ dependencies = [
"winapi",
]
[[package]]
name = "num-format"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bafe4179722c2894288ee77a9f044f02811c86af699344c498b0840c698a2465"
dependencies = [
"arrayvec 0.4.12",
"itoa",
]
[[package]]
name = "num_cpus"
version = "1.13.0"
@ -1317,6 +1343,7 @@ dependencies = [
"lsp-types",
"mbe",
"mimalloc",
"num-format",
"oorandom",
"parking_lot",
"proc_macro_srv",
@ -1560,7 +1587,7 @@ dependencies = [
name = "syntax"
version = "0.0.0"
dependencies = [
"arrayvec",
"arrayvec 0.7.0",
"cov-mark",
"expect-test",
"indexmap",

View File

@ -21,7 +21,7 @@ pulldown-cmark-to-cmark = "6.0.0"
pulldown-cmark = { version = "0.8.0", default-features = false }
url = "2.1.1"
dot = "0.1.4"
num-format = "0.4.0"
stdx = { path = "../stdx", version = "0.0.0" }
syntax = { path = "../syntax", version = "0.0.0" }
text_edit = { path = "../text_edit", version = "0.0.0" }

View File

@ -10,6 +10,7 @@ use ide_db::{
RootDatabase,
};
use itertools::Itertools;
use num_format::{Buffer, Locale};
use profile::{memory_usage, Bytes};
use rustc_hash::FxHashMap;
use stdx::format_to;
@ -109,7 +110,8 @@ pub(crate) struct SyntaxTreeStats {
impl fmt::Display for SyntaxTreeStats {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{} trees, {} preserved", self.total, self.retained)
let buf = Buffer::default().write_formatted(&self.total, &Locale::en);
write!(fmt, "{} trees, {} preserved", buf.to_string(), self.retained)
}
}

View File

@ -38,7 +38,7 @@ tracing = "0.1"
tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] }
tracing-tree = { version = "0.1.4" }
always-assert = "0.1"
num-format = "0.4.0"
stdx = { path = "../stdx", version = "0.0.0" }
flycheck = { path = "../flycheck", version = "0.0.0" }
ide = { path = "../ide", version = "0.0.0" }

View File

@ -25,6 +25,7 @@ use lsp_types::{
SemanticTokensRangeResult, SemanticTokensResult, SymbolInformation, SymbolTag,
TextDocumentIdentifier, TextDocumentPositionParams, Url, WorkspaceEdit,
};
use num_format::{Locale, ToFormattedString};
use project_model::TargetKind;
use serde::{Deserialize, Serialize};
use serde_json::{json, to_value};
@ -66,8 +67,8 @@ pub(crate) fn handle_analyzer_status(
format_to!(
buf,
"Loaded {:?} packages across {} workspace{}.\n",
snap.workspaces.iter().map(|w| w.n_packages()).sum::<usize>(),
snap.workspaces.len(),
snap.workspaces.iter().map(|w| w.n_packages()).sum::<usize>().to_formatted_string(&Locale::en),
snap.workspaces.len().to_formatted_string(&Locale::en),
if snap.workspaces.len() == 1 { "" } else { "s" }
);
}