@@ -46,7 +46,8 @@ export class ProjectSvelteFilesManager {
4646 return ;
4747 }
4848
49- this . disposeWatchersAndFiles ( ) ;
49+ this . disposeWatchers ( ) ;
50+ this . clearProjectFile ( ) ;
5051 this . parsedCommandLine = parsedCommandLine ;
5152 this . setupWatchers ( ) ;
5253 this . updateProjectSvelteFiles ( ) ;
@@ -162,7 +163,8 @@ export class ProjectSvelteFilesManager {
162163 }
163164
164165 private onConfigChanged ( config : Configuration ) {
165- this . disposeWatchersAndFiles ( ) ;
166+ this . disposeWatchers ( ) ;
167+ this . clearProjectFile ( ) ;
166168
167169 if ( config . enable ) {
168170 this . setupWatchers ( ) ;
@@ -178,16 +180,23 @@ export class ProjectSvelteFilesManager {
178180 }
179181 }
180182
181- private disposeWatchersAndFiles ( ) {
183+ private disposeWatchers ( ) {
182184 this . directoryWatchers . forEach ( ( watcher ) => watcher . close ( ) ) ;
183185 this . directoryWatchers . clear ( ) ;
186+ }
184187
188+ private clearProjectFile ( ) {
185189 this . projectFileToOriginalCasing . forEach ( ( file ) => this . removeFileFromProject ( file ) ) ;
186190 this . projectFileToOriginalCasing . clear ( ) ;
187191 }
188192
189193 dispose ( ) {
190- this . disposeWatchersAndFiles ( ) ;
194+ this . disposeWatchers ( ) ;
195+
196+ // Don't remove files from the project here
197+ // because TypeScript already does that when the project is closed
198+ // - and because the project is closed, `project.removeFile` will result in an error
199+ this . projectFileToOriginalCasing . clear ( ) ;
191200
192201 ProjectSvelteFilesManager . instances . delete ( this . project . getProjectName ( ) ) ;
193202 }
0 commit comments