mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
Improve compile time a tiny bit
This commit is contained in:
parent
4271e4c703
commit
c7a079d32d
4 changed files with 13 additions and 10 deletions
|
@ -77,12 +77,12 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
|
|||
|
||||
const PREAMBLE: &str = "Generated file, do not edit by hand, see `xtask/src/codegen`";
|
||||
|
||||
fn reformat(text: impl std::fmt::Display) -> Result<String> {
|
||||
fn reformat(text: &str) -> Result<String> {
|
||||
let _e = pushenv("RUSTUP_TOOLCHAIN", "stable");
|
||||
ensure_rustfmt()?;
|
||||
let stdout = run!(
|
||||
"rustfmt --config-path {} --config fn_single_line=true", project_root().join("rustfmt.toml").display();
|
||||
<text.to_string().as_bytes()
|
||||
<text.as_bytes()
|
||||
)?;
|
||||
Ok(format!("//! {}\n\n{}\n", PREAMBLE, stdout))
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ r#####"
|
|||
|
||||
buf.push_str(&test)
|
||||
}
|
||||
let buf = reformat(buf)?;
|
||||
let buf = reformat(&buf.to_string())?;
|
||||
codegen::update(&project_root().join("crates/assists/src/tests/generated.rs"), &buf, mode)
|
||||
}
|
||||
|
||||
|
|
|
@ -46,5 +46,5 @@ fn generate_descriptor(src_dir: PathBuf) -> Result<String> {
|
|||
#(#definitions),*
|
||||
];
|
||||
};
|
||||
reformat(ts)
|
||||
reformat(&ts.to_string())
|
||||
}
|
||||
|
|
|
@ -61,10 +61,13 @@ fn generate_tokens(grammar: &AstSrc) -> Result<String> {
|
|||
}
|
||||
});
|
||||
|
||||
let pretty = reformat(quote! {
|
||||
use crate::{SyntaxKind::{self, *}, SyntaxToken, ast::AstToken};
|
||||
#(#tokens)*
|
||||
})?
|
||||
let pretty = reformat(
|
||||
"e! {
|
||||
use crate::{SyntaxKind::{self, *}, SyntaxToken, ast::AstToken};
|
||||
#(#tokens)*
|
||||
}
|
||||
.to_string(),
|
||||
)?
|
||||
.replace("#[derive", "\n#[derive");
|
||||
Ok(pretty)
|
||||
}
|
||||
|
@ -261,7 +264,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> Result<String> {
|
|||
}
|
||||
}
|
||||
|
||||
let pretty = reformat(res)?;
|
||||
let pretty = reformat(&res)?;
|
||||
Ok(pretty)
|
||||
}
|
||||
|
||||
|
@ -383,7 +386,7 @@ fn generate_syntax_kinds(grammar: KindsSrc<'_>) -> Result<String> {
|
|||
}
|
||||
};
|
||||
|
||||
reformat(ast)
|
||||
reformat(&ast.to_string())
|
||||
}
|
||||
|
||||
fn to_upper_snake_case(s: &str) -> String {
|
||||
|
|
Loading…
Reference in a new issue