@@ -95,70 +95,77 @@ object Watching {
95
95
if (alreadyStale) {
96
96
enterKeyPressed = false
97
97
} else {
98
- enterKeyPressed = watchAndWait(streams, streams.in, watchables, watchArgs, watchViaNotify)
98
+ enterKeyPressed =
99
+ watchAndWait(streams, streams.in, watchables, watchArgs, watchViaNotify)
99
100
}
100
101
}
101
102
throw new IllegalStateException (" unreachable" )
102
103
}
103
104
104
105
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
+ }
112
115
}
113
- }
114
116
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 " )}"
128
148
)
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
+ }
151
158
}
152
159
} else loop(watchViaNotify = None )
153
160
}
154
161
}
155
162
156
163
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 ]
162
169
) {
163
170
def watchedValueCount : Int = watched.size - watchedPathsSeq.size
164
171
@@ -198,8 +205,11 @@ object Watching {
198
205
}
199
206
200
207
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
203
213
)
204
214
}
205
215
}
@@ -229,7 +239,8 @@ object Watching {
229
239
230
240
watchViaNotifyArgs match {
231
241
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)))
233
244
}
234
245
}
235
246
0 commit comments