File tree Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,11 @@ interface LSAndTSDocResolverOptions {
46
46
tsSystem ?: ts . System ;
47
47
watchDirectory ?: ( patterns : RelativePattern [ ] ) => void ;
48
48
nonRecursiveWatchPattern ?: string ;
49
+ /**
50
+ * Optional callback invoked when a new snapshot is created.
51
+ * Used by svelte-check to dynamically add parent directories to file watchers.
52
+ */
53
+ onSnapshotCreated ?: ( dirPath : string ) => void ;
49
54
}
50
55
51
56
export class LSAndTSDocResolver {
@@ -83,6 +88,20 @@ export class LSAndTSDocResolver {
83
88
84
89
this . tsSystem = this . wrapWithPackageJsonMonitoring ( this . options ?. tsSystem ?? ts . sys ) ;
85
90
this . globalSnapshotsManager = new GlobalSnapshotsManager ( this . tsSystem ) ;
91
+ // Notify when new snapshots are created so external watchers (svelte-check)
92
+ // can add their parent directories dynamically.
93
+ if ( this . options ?. onSnapshotCreated ) {
94
+ this . globalSnapshotsManager . onChange ( ( fileName , newDocument ) => {
95
+ if ( newDocument ) {
96
+ try {
97
+ const dir = dirname ( fileName ) ;
98
+ this . options ?. onSnapshotCreated ?.( dir ) ;
99
+ } catch {
100
+ // best-effort; ignore errors in callback
101
+ }
102
+ }
103
+ } ) ;
104
+ }
86
105
this . userPreferencesAccessor = { preferences : this . getTsUserPreferences ( ) } ;
87
106
const projectService = createProjectService ( this . tsSystem , this . userPreferencesAccessor ) ;
88
107
Original file line number Diff line number Diff line change @@ -31,6 +31,11 @@ export interface SvelteCheckOptions {
31
31
tsconfig ?: string ;
32
32
onProjectReload ?: ( ) => void ;
33
33
watch ?: boolean ;
34
+ /**
35
+ * Optional callback invoked when a new snapshot is created.
36
+ * Used by svelte-check to dynamically add watch directories.
37
+ */
38
+ onSnapshotCreated ?: ( dirPath : string ) => void ;
34
39
}
35
40
36
41
/**
@@ -91,7 +96,8 @@ export class SvelteCheck {
91
96
tsconfigPath : options . tsconfig ,
92
97
isSvelteCheck : true ,
93
98
onProjectReloaded : options . onProjectReload ,
94
- watch : options . watch
99
+ watch : options . watch ,
100
+ onSnapshotCreated : options . onSnapshotCreated
95
101
}
96
102
) ;
97
103
this . pluginHost . register (
Original file line number Diff line number Diff line change @@ -197,6 +197,16 @@ class DiagnosticsWatcher {
197
197
this . updateWatchedDirectories ( ) ;
198
198
}
199
199
200
+ addWatchDirectory ( dir : string ) {
201
+ if ( ! dir || this . currentWatchedDirs . has ( dir ) ) {
202
+ return ;
203
+ }
204
+ this . watcher . add ( dir ) ;
205
+ this . currentWatchedDirs . add ( dir ) ;
206
+ // New files might now be visible; schedule a run
207
+ this . scheduleDiagnostics ( ) ;
208
+ }
209
+
200
210
private async updateWatchedDirectories ( ) {
201
211
const watchDirs = await this . svelteCheck . getWatchDirectories ( ) ;
202
212
const dirsToWatch = watchDirs || [ { path : this . workspaceUri . fsPath , recursive : true } ] ;
@@ -303,11 +313,16 @@ parseOptions(async (opts) => {
303
313
} ;
304
314
305
315
if ( opts . watch ) {
316
+ // Wire callbacks that can reference the watcher instance created below
317
+ let watcher : DiagnosticsWatcher ;
306
318
svelteCheckOptions . onProjectReload = ( ) => {
307
319
watcher . updateWatchers ( ) ;
308
320
watcher . scheduleDiagnostics ( ) ;
309
321
} ;
310
- const watcher = new DiagnosticsWatcher (
322
+ svelteCheckOptions . onSnapshotCreated = ( dirPath : string ) => {
323
+ watcher . addWatchDirectory ( dirPath ) ;
324
+ } ;
325
+ watcher = new DiagnosticsWatcher (
311
326
opts . workspaceUri ,
312
327
new SvelteCheck ( opts . workspaceUri . fsPath , svelteCheckOptions ) ,
313
328
writer ,
You can’t perform that action at this time.
0 commit comments