Skip to content

Commit 79fd1f5

Browse files
committed
fix: watch lockfiles didn't work with git checkouts on Windows
I fixed all problems I could find so far
1 parent 9c587c8 commit 79fd1f5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/autoInstall.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ export const registerLockfilesWatcher = () => {
4545
const lockfileChangeHandler = (action: 'created' | 'changed') => async (uri: vsc.Uri) => {
4646
if (getExtensionSetting('install.watchLockfilesGitCheckouts')) {
4747
recentLockfileChanges ??= []
48+
let finalCallback: (() => void) | undefined
4849
if (!Array.isArray(recentLockfileChanges)) {
49-
recentLockfileChanges()
50+
finalCallback = recentLockfileChanges
5051
recentLockfileChanges = []
5152
}
5253

5354
recentLockfileChanges.push({ action, uri })
55+
// do it in next loop when all (probably) lockfileChangeHandler callback are called
56+
setTimeout(() => finalCallback?.())
5457
setTimeout(() => {
5558
recentLockfileChanges = null
5659
// vscode git is slow
@@ -100,7 +103,12 @@ export const registerLockfilesWatcher = () => {
100103
if (commit === newCommit) return
101104
commit = newCommit
102105

103-
if (recentLockfileChanges && !Array.isArray(recentLockfileChanges)) recentLockfileChanges(true)
106+
if (recentLockfileChanges && !Array.isArray(recentLockfileChanges)) {
107+
// on some random checkouts on windows, repo.state.onDidChange gets called twice,
108+
// so we cancel old and bind new
109+
recentLockfileChanges(true)
110+
recentLockfileChanges = null
111+
}
104112
// eslint-disable-next-line curly
105113
if (recentLockfileChanges === null) {
106114
await new Promise<void>((resolve, reject) => {

0 commit comments

Comments
 (0)