Skip to content
This repository has been archived by the owner on Aug 20, 2020. It is now read-only.

Commit

Permalink
Merge #3
Browse files Browse the repository at this point in the history
3: Filter out hidden and extensionless files from watching r=matklad a=vipentti

Relates to discussion in rust-lang/rust-analyzer#869

I'm not sure if this is the appropriate place to do the filtering.

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>
  • Loading branch information
bors[bot] and vipentti committed Mar 6, 2019
2 parents beac276 + 55f333d commit 94df525
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/roots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,31 @@ impl RootData {
}

match path.extension() {
None | Some("rs") => false,
_ => true,
Some("rs") => false,
Some(_) => true,
// Exclude extension-less and hidden files
None => is_extensionless_or_hidden_file(&self.path, path),
}
}
}

fn is_extensionless_or_hidden_file<P: AsRef<Path>>(base: P, relative_path: &RelativePath) -> bool {
// Exclude files/paths starting with "."
if relative_path.file_stem().map(|s| s.starts_with(".")).unwrap_or(false) {
return true;
}

if relative_path.extension().is_some() {
return false;
}

let path = relative_path.to_path(base);

std::fs::metadata(path)
.map(|m| m.is_file())
.unwrap_or(false)
}

fn rel_path(base: &Path, path: &Path) -> Option<RelativePathBuf> {
let path = path.strip_prefix(base).ok()?;
let path = RelativePathBuf::from_path(path).unwrap();
Expand Down
9 changes: 8 additions & 1 deletion tests/vfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ macro_rules! assert_match {
fn test_vfs_works() -> std::io::Result<()> {
// Logger::with_str("vfs=debug,ra_vfs=debug").start().unwrap();

let files = [("a/foo.rs", "hello"), ("a/bar.rs", "world"), ("a/b/baz.rs", "nested hello")];
let files = [
("a/foo.rs", "hello"),
("a/bar.rs", "world"),
("a/b/baz.rs", "nested hello"),
("a/LICENSE", "extensionless file"),
("a/b/AUTHOR", "extensionless file"),
("a/.hidden.txt", "hidden file"),
];

let dir = tempdir().unwrap();
for (path, text) in files.iter() {
Expand Down

0 comments on commit 94df525

Please sign in to comment.