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

Commit 94df525

Browse files
bors[bot]vipentti
andcommitted
Merge #3
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 <[email protected]>
2 parents beac276 + 55f333d commit 94df525

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/roots.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,31 @@ impl RootData {
9595
}
9696

9797
match path.extension() {
98-
None | Some("rs") => false,
99-
_ => true,
98+
Some("rs") => false,
99+
Some(_) => true,
100+
// Exclude extension-less and hidden files
101+
None => is_extensionless_or_hidden_file(&self.path, path),
100102
}
101103
}
102104
}
103105

106+
fn is_extensionless_or_hidden_file<P: AsRef<Path>>(base: P, relative_path: &RelativePath) -> bool {
107+
// Exclude files/paths starting with "."
108+
if relative_path.file_stem().map(|s| s.starts_with(".")).unwrap_or(false) {
109+
return true;
110+
}
111+
112+
if relative_path.extension().is_some() {
113+
return false;
114+
}
115+
116+
let path = relative_path.to_path(base);
117+
118+
std::fs::metadata(path)
119+
.map(|m| m.is_file())
120+
.unwrap_or(false)
121+
}
122+
104123
fn rel_path(base: &Path, path: &Path) -> Option<RelativePathBuf> {
105124
let path = path.strip_prefix(base).ok()?;
106125
let path = RelativePathBuf::from_path(path).unwrap();

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)