refactor: use `std::sync::Mutex` instead of `parking_lot::Mutex`
MODIFY
Cargo.lock
Cargo.lock
@@ -1500,7 +1500,6 @@ dependencies = [
"hdrhistogram",
"insta",
"lazy_static",
- "parking_lot 0.12.1",
"pico-args",
"rayon",
"rome_bin",
@@ -1642,7 +1641,6 @@ dependencies = [
"ctor",
"iai",
"insta",
- "parking_lot 0.12.1",
"quickcheck",
"quickcheck_macros",
"rome_diagnostics",
@@ -1728,7 +1726,6 @@ dependencies = [
"anyhow",
"futures",
"indexmap",
- "parking_lot 0.12.1",
"rome_analyze",
"rome_console",
"rome_diagnostics",

MODIFY
crates/rome_cli/Cargo.toml
crates/rome_cli/Cargo.toml
@@ -18,7 +18,6 @@ rome_console = { path = "../rome_console" }
pico-args = { version ="0.5.0", features=["eq-separator"] }
tracing = { version = "0.1.31", default-features = false, features = ["std"] }
tracing-subscriber = "0.3.6"
-parking_lot = "0.12.0"
lazy_static = "1.4.0"
hdrhistogram = { version = "7.5.0", default-features = false }
crossbeam = "0.8.1"

MODIFY
crates/rome_cli/src/metrics.rs
crates/rome_cli/src/metrics.rs
@@ -8,7 +8,7 @@ use std::{
};
use hdrhistogram::Histogram;
-use parking_lot::{Mutex, RwLock};
+use std::sync::{Mutex, RwLock};
use tracing::{span, subscriber::Interest, Level, Metadata, Subscriber};
use tracing_subscriber::{
layer::Context,
@@ -170,6 +170,7 @@ where
METRICS
.write()
+ .unwrap()
.insert(CallsiteKey(metadata), Mutex::new(entry));
Interest::always()
@@ -238,12 +239,12 @@ where
// Acquire a read lock on the metrics storage, access the metrics entry
// associated with this call site and acquire a write lock on it
- let metrics = METRICS.read();
+ let metrics = METRICS.read().unwrap();
let entry = metrics
.get(&CallsiteKey(span.metadata()))
.expect("callsite not found, it should have been registered in register_callsite");
- let mut entry = entry.lock();
+ let mut entry = entry.lock().unwrap();
timing.record(now, &mut entry);
}
}
@@ -257,10 +258,10 @@ pub fn init_metrics() {
/// Flush and print the recorded metrics to the console
pub fn print_metrics() {
- let mut histograms: Vec<_> = METRICS
- .write()
+ let mut write_guard = METRICS.write().unwrap();
+ let mut histograms: Vec<_> = write_guard
.drain()
- .flat_map(|(key, entry)| entry.into_inner().into_histograms(key.0.name()))
+ .flat_map(|(key, entry)| entry.into_inner().unwrap().into_histograms(key.0.name()))
.collect();
histograms.sort_unstable_by(|(a, _), (b, _)| a.cmp(b));
@@ -395,13 +396,13 @@ mod tests {
};
let entry = {
- let mut metrics = METRICS.write();
+ let mut metrics = METRICS.write().unwrap();
metrics.remove(&CallsiteKey(key))
};
let entry = entry.expect("callsite does not exist in metrics storage");
- let entry = entry.into_inner();
+ let entry = entry.into_inner().unwrap();
let histograms = entry.into_histograms(key.name());
for (_, histogram) in histograms {

MODIFY
crates/rome_fs/src/interner.rs
crates/rome_fs/src/interner.rs
@@ -9,7 +9,7 @@ use std::{
use crossbeam::channel::{unbounded, Receiver, Sender};
use indexmap::IndexSet;
-use parking_lot::RwLock;
+use std::sync::RwLock;
pub type FileId = usize;
@@ -23,7 +23,7 @@ pub struct IndexSetInterner {
impl PathInterner for IndexSetInterner {
fn intern_path(&self, path: PathBuf) -> FileId {
- let (index, _) = self.storage.write().insert_full(path);
+ let (index, _) = self.storage.write().unwrap().insert_full(path);
index
}
}

MODIFY
crates/rome_js_formatter/Cargo.toml
crates/rome_js_formatter/Cargo.toml
@@ -29,7 +29,6 @@ tests_macros = { path = "../tests_macros" }
insta = { version="1.18.2", features = ["glob"] }
rome_diagnostics = { path = "../rome_diagnostics" }
countme = { version = "3.0.0", features = ["enable"] }
-parking_lot = "0.12.0"
similar = "2.1.0"
similar-asserts = "1.2.0"
ctor = "0.1.21"

MODIFY
crates/rome_js_formatter/tests/prettier_tests.rs
crates/rome_js_formatter/tests/prettier_tests.rs
-use parking_lot::{const_mutex, Mutex};
use rome_rowan::{TextRange, TextSize};
use similar::{utils::diff_lines, Algorithm, ChangeTag, TextDiff};
use std::fs::remove_file;
+use std::sync::Mutex;
use std::{
env,
ffi::OsStr,
@@ -364,7 +364,7 @@ struct DiffReport {
impl DiffReport {
fn get() -> &'static Self {
static REPORTER: DiffReport = DiffReport {
- state: const_mutex(Vec::new()),
+ state: Mutex::new(Vec::new()),
};
// Use an atomic Once to register an exit callback the first time any
@@ -400,7 +400,7 @@ impl DiffReport {
match env::var("REPORT_PRETTIER") {
Ok(value) if value == "1" => {
if !Self::is_ignored(file_name) {
- self.state.lock().push(DiffReportItem {
+ self.state.lock().unwrap().push(DiffReportItem {
file_name,
rome_formatted_result: rome_formatted_result.to_owned(),
prettier_formatted_result: prettier_formatted_result.to_owned(),
@@ -463,7 +463,7 @@ impl DiffReport {
}
fn report_prettier(&self, report_type: ReportType, report_filename: String) {
- let mut state = self.state.lock();
+ let mut state = self.state.lock().unwrap();
state.sort_by_key(|DiffReportItem { file_name, .. }| *file_name);
let mut report_metric_data = PrettierCompatibilityMetricData::default();

MODIFY
crates/rome_lsp/Cargo.toml
crates/rome_lsp/Cargo.toml
@@ -25,7 +25,6 @@ rome_console = { path = "../rome_console" }
tokio = { version = "1.15.0", features = ["io-std"] }
tower-lsp = { version = "0.17.0" }
tracing = { version = "0.1.31", default-features = false, features = ["std", "attributes"] }
-parking_lot = "0.12.0"
futures = "0.3"
[dev-dependencies]

MODIFY
crates/rome_lsp/src/server.rs
crates/rome_lsp/src/server.rs
@@ -45,6 +45,7 @@ impl LanguageServer for LSPServer {
self.session
.client_capabilities
.write()
+ .unwrap()
.replace(params.capabilities);
let init = InitializeResult {
@@ -67,7 +68,11 @@ impl LanguageServer for LSPServer {
match load_config(&self.session.fs) {
Ok(Some(configuration)) => {
info!("Configuration found, and it is valid!");
- self.session.configuration.write().replace(configuration);
+ self.session
+ .configuration
+ .write()
+ .unwrap()
+ .replace(configuration);
}
Err(err) => {
error!("Couldn't load the configuration file, reason:\n {}", err);

MODIFY
crates/rome_lsp/src/session.rs
crates/rome_lsp/src/session.rs
@@ -5,7 +5,6 @@ use crate::url_interner::UrlInterner;
use crate::utils;
use futures::stream::futures_unordered::FuturesUnordered;
use futures::StreamExt;
-use parking_lot::RwLock;
use rome_analyze::RuleCategories;
use rome_diagnostics::file::FileId;
use rome_fs::{FileSystem, OsFileSystem, RomePath};
@@ -16,6 +15,7 @@ use rome_service::Workspace;
use rome_service::{DynRef, RomeError};
use std::collections::HashMap;
use std::sync::Arc;
+use std::sync::RwLock;
use tower_lsp::lsp_types;
use tracing::{error, trace};
@@ -66,6 +66,7 @@ impl Session {
pub(crate) fn document(&self, url: &lsp_types::Url) -> Result<Document, RomeError> {
self.documents
.read()
+ .unwrap()
.get(url)
.cloned()
.ok_or(RomeError::NotFound)
@@ -75,18 +76,18 @@ impl Session {
///
/// Used by [`handlers::text_document] to synchronize documents with the client.
pub(crate) fn insert_document(&self, url: lsp_types::Url, document: Document) {
- self.documents.write().insert(url, document);
+ self.documents.write().unwrap().insert(url, document);
}
/// Remove the [`Document`] matching the provided [`lsp_types::Url`]
pub(crate) fn remove_document(&self, url: &lsp_types::Url) {
- self.documents.write().remove(url);
+ self.documents.write().unwrap().remove(url);
}
/// Return the unique [FileId] associated with the url for this [Session].
/// This will assign a new FileId if there isn't one for the provided url.
pub(crate) fn file_id(&self, url: lsp_types::Url) -> FileId {
- self.url_interner.write().intern(url)
+ self.url_interner.write().unwrap().intern(url)
}
pub(crate) fn file_path(&self, url: &lsp_types::Url) -> RomePath {
@@ -134,6 +135,7 @@ impl Session {
let mut futures: FuturesUnordered<_> = self
.documents
.read()
+ .unwrap()
.keys()
.map(|url| self.update_diagnostics(url.clone()))
.collect();
@@ -149,6 +151,7 @@ impl Session {
pub(crate) fn can_register_did_change_configuration(&self) -> bool {
self.client_capabilities
.read()
+ .unwrap()
.as_ref()
.and_then(|c| c.workspace.as_ref())
.and_then(|c| c.did_change_configuration)
@@ -170,7 +173,7 @@ impl Session {
.into_iter()
.next()
.and_then(|client_configuration| {
- let mut config = self.config.write();
+ let mut config = self.config.write().unwrap();
config
.set_workspace_settings(client_configuration)
@@ -178,7 +181,7 @@ impl Session {
error!("Cannot set workspace settings: {}", err);
})
.ok()?;
- let mut configuration = self.configuration.write();
+ let mut configuration = self.configuration.write().unwrap();
// This operation is intended, we want to consume the configuration because once it's read
// from the LSP, it's not needed anymore
let settings = config.as_workspace_settings(configuration.take());

refactor: use `std::sync::Mutex` instead of `parking_lot::Mutex` (#3095)