mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-31 15:47:31 +00:00
Make working with codegen less annoying
We probably should look into removing `xtask codegen` altogether. The test workflow works perfectly for package.json config. There are two things preventing that: * Lint completions are generated on demand. * Docs are not committed to the repository.
This commit is contained in:
parent
071dde1c1d
commit
0f6f458cc1
3 changed files with 25 additions and 21 deletions
|
@ -32,7 +32,7 @@ pub(crate) use self::{
|
|||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub(crate) enum Mode {
|
||||
Overwrite,
|
||||
Verify,
|
||||
Ensure,
|
||||
}
|
||||
|
||||
impl flags::Codegen {
|
||||
|
@ -59,12 +59,19 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
|
|||
}
|
||||
_ => (),
|
||||
}
|
||||
if mode == Mode::Verify {
|
||||
anyhow::bail!("`{}` is not up-to-date", path.display());
|
||||
}
|
||||
let return_error = match mode {
|
||||
Mode::Overwrite => false,
|
||||
Mode::Ensure => true,
|
||||
};
|
||||
eprintln!("updating {}", path.display());
|
||||
write_file(path, contents)?;
|
||||
return Ok(());
|
||||
|
||||
return if return_error {
|
||||
let path = path.strip_prefix(&project_root()).unwrap_or(path);
|
||||
anyhow::bail!("`{}` was not up-to-date, updating", path.display());
|
||||
} else {
|
||||
Ok(())
|
||||
};
|
||||
|
||||
fn normalize(s: &str) -> String {
|
||||
s.replace("\r\n", "\n")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue