mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
gen_assists_docs skip hidden files
This commit is contained in:
parent
5e827bd948
commit
90c66470f9
3 changed files with 21 additions and 26 deletions
|
@ -4,7 +4,7 @@ use std::{fs, path::Path};
|
|||
|
||||
use crate::{
|
||||
codegen::{self, extract_comment_blocks_with_empty_lines, Mode},
|
||||
project_root, Result,
|
||||
project_root, rust_files, Result,
|
||||
};
|
||||
|
||||
pub fn generate_assists_docs(mode: Mode) -> Result<()> {
|
||||
|
@ -46,12 +46,8 @@ fn reveal_hash_comments(text: &str) -> String {
|
|||
|
||||
fn collect_assists() -> Result<Vec<Assist>> {
|
||||
let mut res = Vec::new();
|
||||
for entry in fs::read_dir(project_root().join(codegen::ASSISTS_DIR))? {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
if path.is_file() {
|
||||
collect_file(&mut res, path.as_path())?;
|
||||
}
|
||||
for path in rust_files(&project_root().join(codegen::ASSISTS_DIR)) {
|
||||
collect_file(&mut res, path.as_path())?;
|
||||
}
|
||||
res.sort_by(|lhs, rhs| lhs.id.cmp(&rhs.id));
|
||||
return Ok(res);
|
||||
|
|
|
@ -17,6 +17,7 @@ use std::{
|
|||
path::{Path, PathBuf},
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
use walkdir::{DirEntry, WalkDir};
|
||||
|
||||
use crate::{
|
||||
codegen::Mode,
|
||||
|
@ -37,6 +38,21 @@ pub fn project_root() -> PathBuf {
|
|||
.to_path_buf()
|
||||
}
|
||||
|
||||
pub fn rust_files(path: &Path) -> impl Iterator<Item = PathBuf> {
|
||||
let iter = WalkDir::new(path);
|
||||
return iter
|
||||
.into_iter()
|
||||
.filter_entry(|e| !is_hidden(e))
|
||||
.map(|e| e.unwrap())
|
||||
.filter(|e| !e.file_type().is_dir())
|
||||
.map(|e| e.into_path())
|
||||
.filter(|path| path.extension().map(|it| it == "rs").unwrap_or(false));
|
||||
|
||||
fn is_hidden(entry: &DirEntry) -> bool {
|
||||
entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_rustfmt(mode: Mode) -> Result<()> {
|
||||
let _dir = pushd(project_root());
|
||||
ensure_rustfmt()?;
|
||||
|
|
|
@ -5,13 +5,12 @@ use std::{
|
|||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use walkdir::{DirEntry, WalkDir};
|
||||
use xtask::{not_bash::fs2, project_root};
|
||||
use xtask::{not_bash::fs2, project_root, rust_files};
|
||||
|
||||
#[test]
|
||||
fn rust_files_are_tidy() {
|
||||
let mut tidy_docs = TidyDocs::default();
|
||||
for path in rust_files() {
|
||||
for path in rust_files(&project_root().join("crates")) {
|
||||
let text = fs2::read_to_string(&path).unwrap();
|
||||
check_todo(&path, &text);
|
||||
check_trailing_ws(&path, &text);
|
||||
|
@ -142,19 +141,3 @@ fn is_exclude_dir(p: &Path, dirs_to_exclude: &[&str]) -> bool {
|
|||
|
||||
false
|
||||
}
|
||||
|
||||
fn rust_files() -> impl Iterator<Item = PathBuf> {
|
||||
let crates = project_root().join("crates");
|
||||
let iter = WalkDir::new(crates);
|
||||
return iter
|
||||
.into_iter()
|
||||
.filter_entry(|e| !is_hidden(e))
|
||||
.map(|e| e.unwrap())
|
||||
.filter(|e| !e.file_type().is_dir())
|
||||
.map(|e| e.into_path())
|
||||
.filter(|path| path.extension().map(|it| it == "rs").unwrap_or(false));
|
||||
|
||||
fn is_hidden(entry: &DirEntry) -> bool {
|
||||
entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue