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

View file

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

View file

@ -10,6 +10,7 @@ use ide_db::{
RootDatabase, RootDatabase,
}; };
use itertools::Itertools; use itertools::Itertools;
use num_format::{Buffer, Locale};
use profile::{memory_usage, Bytes}; use profile::{memory_usage, Bytes};
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use stdx::format_to; use stdx::format_to;
@ -109,7 +110,8 @@ pub(crate) struct SyntaxTreeStats {
impl fmt::Display for SyntaxTreeStats { impl fmt::Display for SyntaxTreeStats {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { 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-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] }
tracing-tree = { version = "0.1.4" } tracing-tree = { version = "0.1.4" }
always-assert = "0.1" always-assert = "0.1"
num-format = "0.4.0"
stdx = { path = "../stdx", version = "0.0.0" } stdx = { path = "../stdx", version = "0.0.0" }
flycheck = { path = "../flycheck", version = "0.0.0" } flycheck = { path = "../flycheck", version = "0.0.0" }
ide = { path = "../ide", version = "0.0.0" } ide = { path = "../ide", version = "0.0.0" }

View file

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