Skip to content

Commit

Permalink
(fix) prevent crash when ts project is closed (#2144)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlyu123 committed Aug 29, 2023
1 parent 461e25b commit 5a8cfa5
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/typescript-plugin/src/project-svelte-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export class ProjectSvelteFilesManager {
return;
}

this.disposeWatchersAndFiles();
this.disposeWatchers();
this.clearProjectFile();
this.parsedCommandLine = parsedCommandLine;
this.setupWatchers();
this.updateProjectSvelteFiles();
Expand Down Expand Up @@ -162,7 +163,8 @@ export class ProjectSvelteFilesManager {
}

private onConfigChanged(config: Configuration) {
this.disposeWatchersAndFiles();
this.disposeWatchers();
this.clearProjectFile();

if (config.enable) {
this.setupWatchers();
Expand All @@ -178,16 +180,23 @@ export class ProjectSvelteFilesManager {
}
}

private disposeWatchersAndFiles() {
private disposeWatchers() {
this.directoryWatchers.forEach((watcher) => watcher.close());
this.directoryWatchers.clear();
}

private clearProjectFile() {
this.projectFileToOriginalCasing.forEach((file) => this.removeFileFromProject(file));
this.projectFileToOriginalCasing.clear();
}

dispose() {
this.disposeWatchersAndFiles();
this.disposeWatchers();

// Don't remove files from the project here
// because TypeScript already does that when the project is closed
// - and because the project is closed, `project.removeFile` will result in an error
this.projectFileToOriginalCasing.clear();

ProjectSvelteFilesManager.instances.delete(this.project.getProjectName());
}
Expand Down

0 comments on commit 5a8cfa5

Please sign in to comment.