Skip to content

Commit ef5297d

Browse files
committed
fix: dispose reporters and notification handlers when client is stopped
The "restart Angular Language server" command as well as the restart that happens when a configuration changes stops and starts the client. We should track and clean up the notification and progress handlers for the client at this time rather than continually pushing new ones to the vscode context, which is only cleaned up when the window reloads/closes. Fixes #1232
1 parent ba99ed8 commit ef5297d

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

client/src/client.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ export class AngularLanguageClient implements vscode.Disposable {
115115
await this.client.onReady();
116116
// Must wait for the client to be ready before registering notification
117117
// handlers.
118-
registerNotificationHandlers(this.client, this.context);
119-
registerProgressHandlers(this.client, this.context);
118+
this.disposables.push(registerNotificationHandlers(this.client));
119+
this.disposables.push(registerProgressHandlers(this.client));
120120
}
121121

122122
/**
@@ -170,8 +170,7 @@ export class AngularLanguageClient implements vscode.Disposable {
170170
}
171171
}
172172

173-
function registerNotificationHandlers(
174-
client: lsp.LanguageClient, context: vscode.ExtensionContext) {
173+
function registerNotificationHandlers(client: lsp.LanguageClient): vscode.Disposable {
175174
const disposable1 = client.onNotification(ProjectLoadingStart, () => {
176175
vscode.window.withProgress(
177176
{
@@ -224,10 +223,10 @@ function registerNotificationHandlers(
224223
}
225224
});
226225

227-
context.subscriptions.push(disposable1, disposable2, disposable3);
226+
return vscode.Disposable.from(disposable1, disposable2, disposable3);
228227
}
229228

230-
function registerProgressHandlers(client: lsp.LanguageClient, context: vscode.ExtensionContext) {
229+
function registerProgressHandlers(client: lsp.LanguageClient) {
231230
const progressReporters = new Map<string, ProgressReporter>();
232231
const disposable =
233232
client.onProgress(NgccProgressType, NgccProgressToken, async (params: NgccProgress) => {
@@ -254,8 +253,15 @@ function registerProgressHandlers(client: lsp.LanguageClient, context: vscode.Ex
254253
reporter.report(params.message);
255254
}
256255
});
257-
// Dispose the progress handler on exit
258-
context.subscriptions.push(disposable);
256+
const reporterDisposer = vscode.Disposable.from({
257+
dispose() {
258+
for (const reporter of progressReporters.values()) {
259+
reporter.finish();
260+
}
261+
disposable.dispose();
262+
}
263+
});
264+
return reporterDisposer;
259265
}
260266

261267
/**

0 commit comments

Comments
 (0)