Skip to content

Commit 7c1395f

Browse files
[autofix.ci] apply automated fixes
1 parent caffff7 commit 7c1395f

File tree

4 files changed

+71
-56
lines changed

4 files changed

+71
-56
lines changed

main/util/src/mill/util/Watchable.scala

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import mill.api.internal
1010
*/
1111
@internal
1212
private[mill] trait Watchable {
13+
1314
/** @return the hashcode of a watched value. */
1415
def poll(): Long
1516

runner/src/mill/runner/MillCliConfig.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ case class MillCliConfig(
9797
watch: Flag = Flag(),
9898
@arg(
9999
name = "watch-via-fs-notify",
100-
doc = "Use filesystem based file watching instead of polling based one (experimental, defaults to false).",
100+
doc =
101+
"Use filesystem based file watching instead of polling based one (experimental, defaults to false)."
101102
)
102103
watchViaFsNotify: Boolean = false,
103104
@arg(

runner/src/mill/runner/MillMain.scala

+4-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@ object MillMain {
232232
val (isSuccess, evalStateOpt) = Watching.watchLoop(
233233
ringBell = config.ringBell.value,
234234
watch = Option.when(config.watch.value)(Watching.WatchArgs(
235-
setIdle, colors, useNotify = config.watchViaFsNotify, serverDir = serverDir
235+
setIdle,
236+
colors,
237+
useNotify = config.watchViaFsNotify,
238+
serverDir = serverDir
236239
)),
237240
streams = streams,
238241
evaluate = (enterKeyPressed: Boolean, prevState: Option[RunnerState]) => {

runner/src/mill/runner/Watching.scala

+64-54
Original file line numberDiff line numberDiff line change
@@ -122,68 +122,78 @@ object Watching {
122122
enterKeyPressed
123123
}
124124

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+
}
130131

131-
@volatile var pathChangesDetected = false
132+
@volatile var pathChangesDetected = false
132133

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
134135

135-
writeToWatchLog(s"[watched-paths:unfiltered] ${watchedPathsSet.toSeq.sorted.mkString("\n")}")
136+
writeToWatchLog(
137+
s"[watched-paths:unfiltered] ${watchedPathsSet.toSeq.sorted.mkString("\n")}"
138+
)
136139

137-
val workspaceRoot = mill.api.WorkspaceRoot.workspaceRoot
140+
val workspaceRoot = mill.api.WorkspaceRoot.workspaceRoot
138141

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+
}
147150

148-
isUnderWorkspaceRoot
149-
}
151+
isUnderWorkspaceRoot
152+
}
150153

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+
}
185196
}
186-
}
187197
else {
188198
doWatch(notifiablesChanged = () => watchedPathsSeq.exists(p => !p.validate()))
189199
}

0 commit comments

Comments
 (0)