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

Commit 31eec52

Browse files
committed
Filter out hidden and extensionless files from watching
1 parent beac276 commit 31eec52

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/io.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77
};
88
use crossbeam_channel::{Sender, Receiver, unbounded, RecvError, select};
99
use relative_path::RelativePathBuf;
10-
use walkdir::WalkDir;
10+
use walkdir::{WalkDir, DirEntry};
1111
use notify::{DebouncedEvent, RecommendedWatcher, RecursiveMode, Watcher as _Watcher};
1212

1313
use crate::{Roots, VfsRoot, VfsTask};
@@ -250,6 +250,14 @@ fn handle_change(
250250
}
251251
}
252252

253+
fn is_extensionless_file(entry: &DirEntry) -> bool {
254+
entry.file_type().is_file() && entry.path().extension().is_none()
255+
}
256+
257+
fn is_hidden(entry: &DirEntry) -> bool {
258+
entry.file_name().to_str().map(|s| s.starts_with(".")).unwrap_or(false)
259+
}
260+
253261
fn watch_recursive(
254262
mut watcher: Option<&mut RecommendedWatcher>,
255263
dir: &Path,
@@ -259,7 +267,11 @@ fn watch_recursive(
259267
let mut files = Vec::new();
260268
for entry in WalkDir::new(dir)
261269
.into_iter()
262-
.filter_entry(|it| roots.contains(root, it.path()).is_some())
270+
.filter_entry(|it| {
271+
!is_hidden(it)
272+
&& !is_extensionless_file(it)
273+
&& roots.contains(root, it.path()).is_some()
274+
})
263275
.filter_map(|it| it.map_err(|e| log::warn!("watcher error: {}", e)).ok())
264276
{
265277
if entry.file_type().is_dir() {

tests/vfs.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ macro_rules! assert_match {
4444
fn test_vfs_works() -> std::io::Result<()> {
4545
// Logger::with_str("vfs=debug,ra_vfs=debug").start().unwrap();
4646

47-
let files = [("a/foo.rs", "hello"), ("a/bar.rs", "world"), ("a/b/baz.rs", "nested hello")];
47+
let files = [
48+
("a/foo.rs", "hello"),
49+
("a/bar.rs", "world"),
50+
("a/b/baz.rs", "nested hello"),
51+
("a/LICENSE", "extensionless file"),
52+
("a/b/AUTHOR", "extensionless file"),
53+
("a/.hidden.txt", "hidden file"),
54+
];
4855

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

0 commit comments

Comments
 (0)