@@ -32,6 +32,7 @@ import {
32
32
getPackageManager ,
33
33
getPackagesAdvisories ,
34
34
PackageManager ,
35
+ packageManagerCaches ,
35
36
PackagesAdvisories ,
36
37
packagesInstalledCaches ,
37
38
} from "./PackageManager"
@@ -82,19 +83,24 @@ export const diagnosticSubscribe = (
82
83
)
83
84
84
85
// Trigger when any file in the workspace is modified.
85
- // Our interest here is to know about package-lock.json.
86
- context . subscriptions . push (
87
- workspace
88
- . createFileSystemWatcher ( "**/{package-lock.json,pnpm-lock.yaml}" )
89
- . onDidChange ( ( uri : Uri ) => {
90
- packagesInstalledCaches . get ( getWorkspacePath ( uri ) ) ?. invalidate ( )
91
-
92
- window . visibleTextEditors . forEach ( ( editor ) =>
93
- handleChange ( editor . document )
94
- )
95
- } )
86
+ // Our interest here is to know about package-lock.json or pnpm-lock.yaml.
87
+ const lockerWatcher = workspace . createFileSystemWatcher (
88
+ "**/{package-lock.json,pnpm-lock.yaml}"
96
89
)
97
90
91
+ const lockerUpdated = ( uri : Uri ) => {
92
+ const workspacePath = getWorkspacePath ( uri )
93
+
94
+ packageManagerCaches . get ( workspacePath ) ?. invalidate ( )
95
+ packagesInstalledCaches . get ( workspacePath ) ?. invalidate ( )
96
+
97
+ window . visibleTextEditors . forEach ( ( editor ) => handleChange ( editor . document ) )
98
+ }
99
+
100
+ context . subscriptions . push ( lockerWatcher . onDidCreate ( lockerUpdated ) )
101
+ context . subscriptions . push ( lockerWatcher . onDidChange ( lockerUpdated ) )
102
+ context . subscriptions . push ( lockerWatcher . onDidDelete ( lockerUpdated ) )
103
+
98
104
// Trigger when the active document is closed, removing the current document from the diagnostic collection.
99
105
context . subscriptions . push (
100
106
workspace . onDidCloseTextDocument ( ( document : TextDocument ) => {
0 commit comments