Skip to content

Commit d44adc7

Browse files
committed
fix(useFsWatcher): should watch ignore options correctly
1 parent c8c81d4 commit d44adc7

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

packages/core/src/composables/useFsWatcher.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { MaybeRefOrGetter, ShallowReactive } from '@reactive-vscode/reactivity'
2-
import { onScopeDispose, shallowReactive, toValue, watchEffect } from '@reactive-vscode/reactivity'
2+
import { computed, onScopeDispose, shallowReactive, toValue, watch, watchEffect } from '@reactive-vscode/reactivity'
33
import type { Event, FileSystemWatcher, GlobPattern, Uri } from 'vscode'
44
import { workspace } from 'vscode'
55
import type { MaybeNullableRefOrGetter } from '../utils'
@@ -26,13 +26,17 @@ export function useFsWatcher(
2626
const changeEmitter = useEventEmitter<Uri>()
2727
const deleteEmitter = useEventEmitter<Uri>()
2828

29-
watchEffect(() => {
29+
const normalizedPatterns = computed(() => {
3030
const globPatternValue = toValue(globPattern)
31-
const newPatterns = Array.isArray(globPatternValue)
31+
return Array.isArray(globPatternValue)
3232
? globPatternValue
3333
: globPatternValue instanceof Set
3434
? Array.from(globPatternValue)
3535
: [globPatternValue]
36+
})
37+
38+
function updateWatchers() {
39+
const newPatterns = normalizedPatterns.value
3640
for (const [pattern, watcher] of watchers) {
3741
if (!newPatterns.includes(pattern)) {
3842
watcher.dispose()
@@ -52,14 +56,21 @@ export function useFsWatcher(
5256
w.onDidDelete(deleteEmitter.fire)
5357
}
5458
}
55-
})
59+
}
5660

57-
onScopeDispose(() => {
61+
function clearWatchers() {
5862
for (const watcher of watchers.values()) {
5963
watcher.dispose()
6064
}
6165
watchers.clear()
66+
}
67+
68+
watch(normalizedPatterns, updateWatchers)
69+
watch([ignoreCreateEvents, ignoreChangeEvents, ignoreDeleteEvents], () => {
70+
clearWatchers()
71+
updateWatchers()
6272
})
73+
onScopeDispose(clearWatchers)
6374

6475
return {
6576
watchers,

0 commit comments

Comments
 (0)