paths: Replace lazy_static!
with OnceLock
(#13213)
This PR replaces the `lazy_static!` usages in the `paths` crate with `OnceLock` from the standard library. This allows us to drop the `lazy_static` dependency from this crate. The paths are now exposed as accessor functions that reference a private static value. Release Notes: - N/A
This commit is contained in:
parent
ba59e66314
commit
81475ac4cd
27 changed files with 322 additions and 172 deletions
|
@ -18,7 +18,7 @@ use language::{
|
|||
};
|
||||
use lsp::{LanguageServer, LanguageServerId};
|
||||
use node_runtime::NodeRuntime;
|
||||
use paths::DEFAULT_PRETTIER_DIR;
|
||||
use paths::default_prettier_dir;
|
||||
use prettier::Prettier;
|
||||
use util::{ResultExt, TryFutureExt};
|
||||
|
||||
|
@ -252,7 +252,7 @@ fn start_default_prettier(
|
|||
}
|
||||
let new_default_prettier = project.update(&mut cx, |project, cx| {
|
||||
let new_default_prettier =
|
||||
start_prettier(node, DEFAULT_PRETTIER_DIR.clone(), worktree_id, cx);
|
||||
start_prettier(node, default_prettier_dir().clone(), worktree_id, cx);
|
||||
project.default_prettier.prettier =
|
||||
PrettierInstallation::Installed(PrettierInstance {
|
||||
attempt: 0,
|
||||
|
@ -267,7 +267,7 @@ fn start_default_prettier(
|
|||
None => {
|
||||
let new_default_prettier = project.update(&mut cx, |project, cx| {
|
||||
let new_default_prettier =
|
||||
start_prettier(node, DEFAULT_PRETTIER_DIR.clone(), worktree_id, cx);
|
||||
start_prettier(node, default_prettier_dir().clone(), worktree_id, cx);
|
||||
project.default_prettier.prettier =
|
||||
PrettierInstallation::Installed(PrettierInstance {
|
||||
attempt: instance.attempt + 1,
|
||||
|
@ -380,7 +380,7 @@ async fn install_prettier_packages(
|
|||
.await
|
||||
.context("fetching latest npm versions")?;
|
||||
|
||||
let default_prettier_dir = DEFAULT_PRETTIER_DIR.as_path();
|
||||
let default_prettier_dir = default_prettier_dir().as_path();
|
||||
match fs.metadata(default_prettier_dir).await.with_context(|| {
|
||||
format!("fetching FS metadata for default prettier dir {default_prettier_dir:?}")
|
||||
})? {
|
||||
|
@ -406,7 +406,7 @@ async fn install_prettier_packages(
|
|||
}
|
||||
|
||||
async fn save_prettier_server_file(fs: &dyn Fs) -> anyhow::Result<()> {
|
||||
let prettier_wrapper_path = DEFAULT_PRETTIER_DIR.join(prettier::PRETTIER_SERVER_FILE);
|
||||
let prettier_wrapper_path = default_prettier_dir().join(prettier::PRETTIER_SERVER_FILE);
|
||||
fs.save(
|
||||
&prettier_wrapper_path,
|
||||
&text::Rope::from(prettier::PRETTIER_SERVER_JS),
|
||||
|
@ -423,7 +423,7 @@ async fn save_prettier_server_file(fs: &dyn Fs) -> anyhow::Result<()> {
|
|||
}
|
||||
|
||||
async fn should_write_prettier_server_file(fs: &dyn Fs) -> bool {
|
||||
let prettier_wrapper_path = DEFAULT_PRETTIER_DIR.join(prettier::PRETTIER_SERVER_FILE);
|
||||
let prettier_wrapper_path = default_prettier_dir().join(prettier::PRETTIER_SERVER_FILE);
|
||||
if !fs.is_file(&prettier_wrapper_path).await {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -67,7 +67,8 @@ use lsp_command::*;
|
|||
use node_runtime::NodeRuntime;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use paths::{
|
||||
LOCAL_SETTINGS_RELATIVE_PATH, LOCAL_TASKS_RELATIVE_PATH, LOCAL_VSCODE_TASKS_RELATIVE_PATH,
|
||||
local_settings_file_relative_path, local_tasks_file_relative_path,
|
||||
local_vscode_tasks_file_relative_path,
|
||||
};
|
||||
use postage::watch;
|
||||
use prettier_support::{DefaultPrettier, PrettierInstance};
|
||||
|
@ -8176,10 +8177,10 @@ impl Project {
|
|||
}
|
||||
};
|
||||
|
||||
if abs_path.ends_with(&*LOCAL_SETTINGS_RELATIVE_PATH) {
|
||||
if abs_path.ends_with(local_settings_file_relative_path()) {
|
||||
let settings_dir = Arc::from(
|
||||
path.ancestors()
|
||||
.nth(LOCAL_SETTINGS_RELATIVE_PATH.components().count())
|
||||
.nth(local_settings_file_relative_path().components().count())
|
||||
.unwrap(),
|
||||
);
|
||||
let fs = self.fs.clone();
|
||||
|
@ -8193,7 +8194,7 @@ impl Project {
|
|||
},
|
||||
)
|
||||
});
|
||||
} else if abs_path.ends_with(&*LOCAL_TASKS_RELATIVE_PATH) {
|
||||
} else if abs_path.ends_with(local_tasks_file_relative_path()) {
|
||||
self.task_inventory().update(cx, |task_inventory, cx| {
|
||||
if removed {
|
||||
task_inventory.remove_local_static_source(&abs_path);
|
||||
|
@ -8213,7 +8214,7 @@ impl Project {
|
|||
);
|
||||
}
|
||||
})
|
||||
} else if abs_path.ends_with(&*LOCAL_VSCODE_TASKS_RELATIVE_PATH) {
|
||||
} else if abs_path.ends_with(local_vscode_tasks_file_relative_path()) {
|
||||
self.task_inventory().update(cx, |task_inventory, cx| {
|
||||
if removed {
|
||||
task_inventory.remove_local_static_source(&abs_path);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue