Initialize prettier_server.js wrapper along with default prettier

This commit is contained in:
Kirill Bulatov 2023-09-17 01:21:46 +03:00
parent 010bb73ac2
commit dca93fb177
7 changed files with 7 additions and 39 deletions

View file

@ -1 +0,0 @@
node_modules/

View file

@ -1,7 +0,0 @@
{
"languages": {
"JavaScript": {
"tab_size": 4
}
}
}

View file

@ -1,12 +0,0 @@
{
"name": "prettier_server",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "prettier_server",
"version": "1.0.0"
}
}
}

View file

@ -1,14 +0,0 @@
{
"name": "prettier_server",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"start": "node src/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Zed Industries",
"dev-dependencies": {
"prettier": "^3.0"
}
}

View file

@ -18,6 +18,8 @@ pub struct LocateStart {
pub starting_path: Arc<Path>,
}
pub const PRETTIER_SERVER_JS: &str = include_str!("./prettier_server.js");
impl Prettier {
// This was taken from the prettier-vscode extension.
pub const CONFIG_FILE_NAMES: &'static [&'static str] = &[

View file

@ -79,7 +79,7 @@ use std::{
time::{Duration, Instant},
};
use terminals::Terminals;
use text::Anchor;
use text::{Anchor, LineEnding, Rope};
use util::{
debug_panic, defer,
http::HttpClient,
@ -8350,10 +8350,10 @@ impl Project {
let fs = Arc::clone(&self.fs);
cx.background()
.spawn(async move {
let prettier_dir_metadata = fs.metadata(default_prettier_dir).await.with_context(|| format!("fetching FS metadata for prettier default dir {default_prettier_dir:?}"))?;
if prettier_dir_metadata.is_none() {
fs.create_dir(default_prettier_dir).await.with_context(|| format!("creating prettier default dir {default_prettier_dir:?}"))?;
}
let prettier_wrapper_path = default_prettier_dir.join("prettier_server.js");
// method creates parent directory if it doesn't exist
fs.save(&prettier_wrapper_path, &Rope::from(prettier::PRETTIER_SERVER_JS), LineEnding::Unix).await
.with_context(|| format!("writing prettier_server.js file at {prettier_wrapper_path:?}"))?;
let packages_to_versions = future::try_join_all(
prettier_plugins