@@ -122,68 +122,78 @@ object Watching {
122
122
enterKeyPressed
123
123
}
124
124
125
- if (useNotify) Using .resource(os.write.outputStream(serverDir / " fsNotifyWatchLog" )) { watchLog =>
126
- def writeToWatchLog (s : String ): Unit = {
127
- watchLog.write(s.getBytes(java.nio.charset.StandardCharsets .UTF_8 ))
128
- watchLog.write('\n ' )
129
- }
125
+ if (useNotify)
126
+ Using .resource(os.write.outputStream(serverDir / " fsNotifyWatchLog" )) { watchLog =>
127
+ def writeToWatchLog (s : String ): Unit = {
128
+ watchLog.write(s.getBytes(java.nio.charset.StandardCharsets .UTF_8 ))
129
+ watchLog.write('\n ' )
130
+ }
130
131
131
- @ volatile var pathChangesDetected = false
132
+ @ volatile var pathChangesDetected = false
132
133
133
- // oslib watch only works with folders, so we have to watch the parent folders instead
134
+ // oslib watch only works with folders, so we have to watch the parent folders instead
134
135
135
- writeToWatchLog(s " [watched-paths:unfiltered] ${watchedPathsSet.toSeq.sorted.mkString(" \n " )}" )
136
+ writeToWatchLog(
137
+ s " [watched-paths:unfiltered] ${watchedPathsSet.toSeq.sorted.mkString(" \n " )}"
138
+ )
136
139
137
- val workspaceRoot = mill.api.WorkspaceRoot .workspaceRoot
140
+ val workspaceRoot = mill.api.WorkspaceRoot .workspaceRoot
138
141
139
- /** Paths that are descendants of [[workspaceRoot ]]. */
140
- val pathsUnderWorkspaceRoot = watchedPathsSet.filter { path =>
141
- val isUnderWorkspaceRoot = path.startsWith(workspaceRoot)
142
- if (! isUnderWorkspaceRoot) {
143
- streams.err.println(colors.error(
144
- s " Watched path $path is outside workspace root $workspaceRoot, this is unsupported. "
145
- ).toString())
146
- }
142
+ /** Paths that are descendants of [[workspaceRoot ]]. */
143
+ val pathsUnderWorkspaceRoot = watchedPathsSet.filter { path =>
144
+ val isUnderWorkspaceRoot = path.startsWith(workspaceRoot)
145
+ if (! isUnderWorkspaceRoot) {
146
+ streams.err.println(colors.error(
147
+ s " Watched path $path is outside workspace root $workspaceRoot, this is unsupported. "
148
+ ).toString())
149
+ }
147
150
148
- isUnderWorkspaceRoot
149
- }
151
+ isUnderWorkspaceRoot
152
+ }
150
153
151
- // If I have 'root/a/b/c'
152
- //
153
- // Then I want to watch:
154
- // root/a/b/c
155
- // root/a/b
156
- // root/a
157
- // root
158
- val filterPaths = pathsUnderWorkspaceRoot.flatMap { path =>
159
- path.relativeTo(workspaceRoot).segments.inits.map(segments => workspaceRoot / segments)
160
- }
161
- writeToWatchLog(s " [watched-paths:filtered] ${filterPaths.toSeq.sorted.mkString(" \n " )}" )
162
-
163
- Using .resource(os.watch.watch(
164
- // Just watch the root folder
165
- Seq (workspaceRoot),
166
- filter = path => {
167
- val shouldBeWatched =
168
- filterPaths.contains(path) || watchedPathsSet.exists(watchedPath => path.startsWith(watchedPath))
169
- writeToWatchLog(s " [filter] (shouldBeWatched= $shouldBeWatched) $path" )
170
- shouldBeWatched
171
- },
172
- onEvent = changedPaths => {
173
- // Make sure that the changed paths are actually the ones in our watch list and not some adjacent files in the
174
- // same folder
175
- val hasWatchedPath =
176
- changedPaths.exists(p => watchedPathsSet.exists(watchedPath => p.startsWith(watchedPath)))
177
- writeToWatchLog(s " [changed-paths] (hasWatchedPath= $hasWatchedPath) ${changedPaths.mkString(" \n " )}" )
178
- if (hasWatchedPath) {
179
- pathChangesDetected = true
180
- }
181
- },
182
- logger = (eventType, data) => writeToWatchLog(s " [watch:event] $eventType: ${pprint.apply(data).plainText}" )
183
- )) { _ =>
184
- doWatch(notifiablesChanged = () => pathChangesDetected)
154
+ // If I have 'root/a/b/c'
155
+ //
156
+ // Then I want to watch:
157
+ // root/a/b/c
158
+ // root/a/b
159
+ // root/a
160
+ // root
161
+ val filterPaths = pathsUnderWorkspaceRoot.flatMap { path =>
162
+ path.relativeTo(workspaceRoot).segments.inits.map(segments => workspaceRoot / segments)
163
+ }
164
+ writeToWatchLog(s " [watched-paths:filtered] ${filterPaths.toSeq.sorted.mkString(" \n " )}" )
165
+
166
+ Using .resource(os.watch.watch(
167
+ // Just watch the root folder
168
+ Seq (workspaceRoot),
169
+ filter = path => {
170
+ val shouldBeWatched =
171
+ filterPaths.contains(path) || watchedPathsSet.exists(watchedPath =>
172
+ path.startsWith(watchedPath)
173
+ )
174
+ writeToWatchLog(s " [filter] (shouldBeWatched= $shouldBeWatched) $path" )
175
+ shouldBeWatched
176
+ },
177
+ onEvent = changedPaths => {
178
+ // Make sure that the changed paths are actually the ones in our watch list and not some adjacent files in the
179
+ // same folder
180
+ val hasWatchedPath =
181
+ changedPaths.exists(p =>
182
+ watchedPathsSet.exists(watchedPath => p.startsWith(watchedPath))
183
+ )
184
+ writeToWatchLog(
185
+ s " [changed-paths] (hasWatchedPath= $hasWatchedPath) ${changedPaths.mkString(" \n " )}"
186
+ )
187
+ if (hasWatchedPath) {
188
+ pathChangesDetected = true
189
+ }
190
+ },
191
+ logger = (eventType, data) =>
192
+ writeToWatchLog(s " [watch:event] $eventType: ${pprint.apply(data).plainText}" )
193
+ )) { _ =>
194
+ doWatch(notifiablesChanged = () => pathChangesDetected)
195
+ }
185
196
}
186
- }
187
197
else {
188
198
doWatch(notifiablesChanged = () => watchedPathsSeq.exists(p => ! p.validate()))
189
199
}
0 commit comments