Skip to content

Commit 3cb61c3

Browse files
committed
fix: add proper disposable management for events.
- Added proper disposable management for the `onDidChangeConfiguration` and `onDidOpenTextDocument` events, to ensure they are properly discarded once we're done with them.
1 parent 4233164 commit 3cb61c3

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

src/extension.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function activate(context: vscode.ExtensionContext) {
4040
* When the configuration/user settings are changed, set the extension
4141
* to reflect the settings and output a message to the user.
4242
*/
43-
vscode.workspace.onDidChangeConfiguration((event: vscode.ConfigurationChangeEvent) => {
43+
const configChangeDisposable = vscode.workspace.onDidChangeConfiguration((event: vscode.ConfigurationChangeEvent) => {
4444
// TODO: Work on automatically updating the languages instead of making the user reload the extension.
4545

4646
/**
@@ -74,20 +74,26 @@ export function activate(context: vscode.ExtensionContext) {
7474
}
7575
});
7676

77+
disposables.push(configChangeDisposable);
7778

78-
// An event that is emitted when a text document is opened or when the
79-
// language id of a text document has been changed. As described in
80-
// https://github.com/microsoft/vscode/blob/4e8fbaef741afebd24684b88cac47c2f44dfb8eb/src/vscode-dts/vscode.d.ts#L13716-L13728
81-
82-
// Called when active editor language is changed, so re-configure the comment blocks.
83-
vscode.workspace.onDidOpenTextDocument(() => {
79+
/**
80+
* An event that is emitted when a text document is opened or when the
81+
* language id of a text document has been changed. As described in
82+
* https://github.com/microsoft/vscode/blob/4e8fbaef741afebd24684b88cac47c2f44dfb8eb/src/vscode-dts/vscode.d.ts#L13716-L13728
83+
*
84+
* Called when active editor language is changed, so re-configure the comment blocks.
85+
*/
86+
const documentOpenDisposable = vscode.workspace.onDidOpenTextDocument(() => {
8487
logger.info("Active editor language changed, re-configuring comment blocks.");
8588
const configureCommentBlocksDisposable = configuration.configureCommentBlocks();
8689
disposables.push(...configureCommentBlocksDisposable);
8790
});
8891

92+
disposables.push(documentOpenDisposable);
93+
8994
context.subscriptions.push(...disposables);
9095
}
96+
9197
export function deactivate() {
9298
logger.disposeLogger();
9399
}

0 commit comments

Comments
 (0)