@@ -95,70 +95,77 @@ object Watching {
9595 if (alreadyStale) {
9696 enterKeyPressed = false
9797 } else {
98- enterKeyPressed = watchAndWait(streams, streams.in, watchables, watchArgs, watchViaNotify)
98+ enterKeyPressed =
99+ watchAndWait(streams, streams.in, watchables, watchArgs, watchViaNotify)
99100 }
100101 }
101102 throw new IllegalStateException (" unreachable" )
102103 }
103104
104105 if (watchArgs.useNotify) {
105- Using .resource(os.write.outputStream(watchArgs.serverDir / " fsNotifyWatchLog" )) { watchLog =>
106- def writeToWatchLog (s : String ): Unit = {
107- try {
108- watchLog.write(s.getBytes(java.nio.charset.StandardCharsets .UTF_8 ))
109- watchLog.write('\n ' )
110- } catch {
111- case _ : ClosedChannelException => /* do nothing, the file is already closed */
106+ Using .resource(os.write.outputStream(watchArgs.serverDir / " fsNotifyWatchLog" )) {
107+ watchLog =>
108+ def writeToWatchLog (s : String ): Unit = {
109+ try {
110+ watchLog.write(s.getBytes(java.nio.charset.StandardCharsets .UTF_8 ))
111+ watchLog.write('\n ' )
112+ } catch {
113+ case _ : ClosedChannelException => /* do nothing, the file is already closed */
114+ }
112115 }
113- }
114116
115- val watchedFiles = evaluateOnce()
116- writeToWatchLog(s " [watched-paths:unfiltered] ${watchedFiles.watchedPathsSet.toSeq.sorted.mkString(" \n " )}" )
117- writeToWatchLog(s " [watched-paths:filtered] ${watchedFiles.filterPaths.toSeq.sorted.mkString(" \n " )}" )
118-
119- // Start the watch before entering the evaluation loop to make sure no events fall through.
120- @ volatile var pathChangesDetected = false
121- Using .resource(os.watch.watch(
122- // Just watch the root folder
123- Seq (workspaceRoot),
124- filter = path => {
125- val shouldBeWatched =
126- watchedFiles.filterPaths.contains(path) || watchedFiles.watchedPathsSet.exists(watchedPath =>
127- path.startsWith(watchedPath)
117+ val watchedFiles = evaluateOnce()
118+ writeToWatchLog(
119+ s " [watched-paths:unfiltered] ${watchedFiles.watchedPathsSet.toSeq.sorted.mkString(" \n " )}"
120+ )
121+ writeToWatchLog(
122+ s " [watched-paths:filtered] ${watchedFiles.filterPaths.toSeq.sorted.mkString(" \n " )}"
123+ )
124+
125+ // Start the watch before entering the evaluation loop to make sure no events fall through.
126+ @ volatile var pathChangesDetected = false
127+ Using .resource(os.watch.watch(
128+ // Just watch the root folder
129+ Seq (workspaceRoot),
130+ filter = path => {
131+ val shouldBeWatched =
132+ watchedFiles.filterPaths.contains(path) || watchedFiles.watchedPathsSet.exists(
133+ watchedPath =>
134+ path.startsWith(watchedPath)
135+ )
136+ writeToWatchLog(s " [filter] (shouldBeWatched= $shouldBeWatched) $path" )
137+ shouldBeWatched
138+ },
139+ onEvent = changedPaths => {
140+ // Make sure that the changed paths are actually the ones in our watch list and not some adjacent files in the
141+ // same folder
142+ val hasWatchedPath =
143+ changedPaths.exists(p =>
144+ watchedFiles.watchedPathsSet.exists(watchedPath => p.startsWith(watchedPath))
145+ )
146+ writeToWatchLog(
147+ s " [changed-paths] (hasWatchedPath= $hasWatchedPath) ${changedPaths.mkString(" \n " )}"
128148 )
129- writeToWatchLog(s " [filter] (shouldBeWatched= $shouldBeWatched) $path" )
130- shouldBeWatched
131- },
132- onEvent = changedPaths => {
133- // Make sure that the changed paths are actually the ones in our watch list and not some adjacent files in the
134- // same folder
135- val hasWatchedPath =
136- changedPaths.exists(p =>
137- watchedFiles.watchedPathsSet.exists(watchedPath => p.startsWith(watchedPath))
138- )
139- writeToWatchLog(
140- s " [changed-paths] (hasWatchedPath= $hasWatchedPath) ${changedPaths.mkString(" \n " )}"
141- )
142- if (hasWatchedPath) {
143- pathChangesDetected = true
144- }
145- },
146- logger = (eventType, data) =>
147- writeToWatchLog(s " [watch:event] $eventType: ${pprint.apply(data).plainText}" )
148- )) { _ =>
149- loop(Some (WatchViaNotifyArgs (notifiablesChanged = () => pathChangesDetected)))
150- }
149+ if (hasWatchedPath) {
150+ pathChangesDetected = true
151+ }
152+ },
153+ logger = (eventType, data) =>
154+ writeToWatchLog(s " [watch:event] $eventType: ${pprint.apply(data).plainText}" )
155+ )) { _ =>
156+ loop(Some (WatchViaNotifyArgs (notifiablesChanged = () => pathChangesDetected)))
157+ }
151158 }
152159 } else loop(watchViaNotify = None )
153160 }
154161 }
155162
156163 private case class WatchedFiles (
157- watched : Seq [Watchable ],
158- watchedPollables : Seq [Watchable .Pollable ],
159- watchedPathsSeq : Seq [Watchable .Path ],
160- watchedPathsSet : Set [os.Path ],
161- filterPaths : Set [os.Path ]
164+ watched : Seq [Watchable ],
165+ watchedPollables : Seq [Watchable .Pollable ],
166+ watchedPathsSeq : Seq [Watchable .Path ],
167+ watchedPathsSet : Set [os.Path ],
168+ filterPaths : Set [os.Path ]
162169 ) {
163170 def watchedValueCount : Int = watched.size - watchedPathsSeq.size
164171
@@ -198,8 +205,11 @@ object Watching {
198205 }
199206
200207 apply(
201- watched = watched, watchedPollables = watchedPollables, watchedPathsSeq = watchedPathsSeq,
202- watchedPathsSet = watchedPathsSet, filterPaths = filterPaths
208+ watched = watched,
209+ watchedPollables = watchedPollables,
210+ watchedPathsSeq = watchedPathsSeq,
211+ watchedPathsSet = watchedPathsSet,
212+ filterPaths = filterPaths
203213 )
204214 }
205215 }
@@ -229,7 +239,8 @@ object Watching {
229239
230240 watchViaNotifyArgs match {
231241 case Some (notifyArgs) => doWatch(notifyArgs.notifiablesChanged)
232- case None => doWatch(notifiablesChanged = () => watchedPathsSeq.exists(p => ! validateAnyWatchable(p)))
242+ case None =>
243+ doWatch(notifiablesChanged = () => watchedPathsSeq.exists(p => ! validateAnyWatchable(p)))
233244 }
234245 }
235246
0 commit comments