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:
Marshall Bowers 2024-06-18 12:22:37 -04:00 committed by GitHub
parent ba59e66314
commit 81475ac4cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 322 additions and 172 deletions

View file

@ -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;
}