@@ -40,6 +40,10 @@ async fn async_watch<P: AsRef<Path>>(
40
40
path : P ,
41
41
mut change_tx : UnboundedSender < ( ) > ,
42
42
) -> Result < ( ) , Box < dyn Error > > {
43
+ let path = path. as_ref ( ) ;
44
+ let path = std:: fs:: canonicalize ( path)
45
+ . unwrap_or_else ( |e| panic ! ( "Failed to canonicalize path {path:?}: {e:}" ) ) ;
46
+
43
47
let ( mut watcher, mut rx) = async_watcher ( ) ?;
44
48
45
49
// Add a path to be watched. All files and directories at that path and
@@ -48,8 +52,14 @@ async fn async_watch<P: AsRef<Path>>(
48
52
49
53
while let Some ( res) = rx. next ( ) . await {
50
54
match res {
51
- Ok ( _) => {
52
- change_tx. send ( ( ) ) . await . unwrap ( ) ;
55
+ Ok ( event) => {
56
+ if path. is_dir ( ) || event. paths . iter ( ) . find ( |candidate| {
57
+ std:: fs:: canonicalize ( candidate)
58
+ . unwrap_or_else ( |e| panic ! ( "Failed to canonicalize path {path:?}: {e:}" ) )
59
+ == path
60
+ } ) . is_some ( ) {
61
+ change_tx. send ( ( ) ) . await . unwrap ( ) ;
62
+ }
53
63
}
54
64
Err ( e) => error ! ( "Watch error: {:?}" , e) ,
55
65
}
@@ -98,7 +108,7 @@ struct ShaderBuilder {
98
108
#[ arg( long, default_value = "false" ) ]
99
109
preserve_bindings : bool ,
100
110
/// If set, will watch the provided directory and recompile on change.
101
- ///
111
+ ///
102
112
/// Can be specified multiple times to watch more than one directory.
103
113
#[ arg( short, long) ]
104
114
watch_paths : Option < Vec < String > > ,
0 commit comments