mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Refucktor codegen
This commit is contained in:
parent
98819d8919
commit
21b98d585e
1 changed files with 6 additions and 6 deletions
|
@ -9,9 +9,9 @@ mod gen_syntax;
|
||||||
mod gen_parser_tests;
|
mod gen_parser_tests;
|
||||||
mod gen_assists_docs;
|
mod gen_assists_docs;
|
||||||
|
|
||||||
use std::{fs, mem, path::Path};
|
use std::{mem, path::Path};
|
||||||
|
|
||||||
use crate::Result;
|
use crate::{not_bash::fs2, Result};
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
gen_assists_docs::generate_assists_docs, gen_parser_tests::generate_parser_tests,
|
gen_assists_docs::generate_assists_docs, gen_parser_tests::generate_parser_tests,
|
||||||
|
@ -39,7 +39,7 @@ pub enum Mode {
|
||||||
/// A helper to update file on disk if it has changed.
|
/// A helper to update file on disk if it has changed.
|
||||||
/// With verify = false,
|
/// With verify = false,
|
||||||
fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
|
fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
|
||||||
match fs::read_to_string(path) {
|
match fs2::read_to_string(path) {
|
||||||
Ok(ref old_contents) if normalize(old_contents) == normalize(contents) => {
|
Ok(ref old_contents) if normalize(old_contents) == normalize(contents) => {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
|
||||||
anyhow::bail!("`{}` is not up-to-date", path.display());
|
anyhow::bail!("`{}` is not up-to-date", path.display());
|
||||||
}
|
}
|
||||||
eprintln!("updating {}", path.display());
|
eprintln!("updating {}", path.display());
|
||||||
fs::write(path, contents)?;
|
fs2::write(path, contents)?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
||||||
fn normalize(s: &str) -> String {
|
fn normalize(s: &str) -> String {
|
||||||
|
@ -65,7 +65,7 @@ fn extract_comment_blocks_with_empty_lines(text: &str) -> Vec<Vec<String>> {
|
||||||
do_extract_comment_blocks(text, true)
|
do_extract_comment_blocks(text, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_extract_comment_blocks(text: &str, allow_blocks_with_empty_lins: bool) -> Vec<Vec<String>> {
|
fn do_extract_comment_blocks(text: &str, allow_blocks_with_empty_lines: bool) -> Vec<Vec<String>> {
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
|
|
||||||
let prefix = "// ";
|
let prefix = "// ";
|
||||||
|
@ -73,7 +73,7 @@ fn do_extract_comment_blocks(text: &str, allow_blocks_with_empty_lins: bool) ->
|
||||||
|
|
||||||
let mut block = vec![];
|
let mut block = vec![];
|
||||||
for line in lines {
|
for line in lines {
|
||||||
if line == "//" && allow_blocks_with_empty_lins {
|
if line == "//" && allow_blocks_with_empty_lines {
|
||||||
block.push(String::new());
|
block.push(String::new());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue