Skip to content

refactor: extension activation and performance improvements#29

Merged
yCodeTech merged 6 commits intomasterfrom
refactor/extension-activation
Apr 19, 2026
Merged

refactor: extension activation and performance improvements#29
yCodeTech merged 6 commits intomasterfrom
refactor/extension-activation

Conversation

@yCodeTech
Copy link
Copy Markdown
Owner

@yCodeTech yCodeTech commented Apr 19, 2026

  • Refactored the activate function to set up the logger first, initialize extension data and configuration.

  • Ensured that development environment variables are only loaded when not in production mode, i.e. in development or testing modes.

  • Consolidated multiple configuration change handlers into a single handler that checks for a list of settings requiring extension reload. If any are changed, a single reload prompt is shown using the new showReloadMessage helper function, reducing code duplication.

  • Improved performance and event handling to prevent memory leaks by properly disposing of old comment configurations.

- Moved `logger.setupOutputChannel`, `addDevEnvVariables`, `ExtensionData`, and `Configuration` initialisations into the extension's `activate` function.

- Added a conditional around `addDevEnvVariables` util function call to check to see if the extension is running in development mode before accessing a .env and adding the dev environment variables. This uses the `context.extensionMode`, which is only available inside the `activate` function which is why everything outside of the function had to be moved into it.

The reason for the conditional is because if for some reason there is a .env in a production environment, then this .env file and it's variables would be added to the environment all the time. This could potentially cause a security risk, so we prevent this by only adding the dev env variables when not in production, so in development mode.
- Move the `extensionName`, `extensionDisplayName` variables up to the top of `activate` function so they are grouped with the rest of the variable initialisation.

- Move the `disposables` array variable into the `activate` function.
There is a lot of duplication in the configuration change handling in the extension's `activate` function, with the `showInformationMessage` and reloading the window code.

- Replaced all the configuration change event handlers that required extension reload: `disabledLanguages`, `overrideDefaultLanguageMultiLineComments`, `multiLineStyleBlocks`, `slashStyleBlocks`, `hashStyleBlocks`, and `semicolonStyleBlocks`, with an array to define the setting names.

- Added a `for...of` loop to loop through the new settings array and applies the change event handler, which uses the new `showReloadMessage` function. This makes the code DRY.

- Added new `showReloadMessage` function to show the reload info message and code to reload the extensions. This prevents duplication of the message and reload code as it was previously.
- Move the array pushing of the `configureCommentBlocksDisposable` variable up a few lines to where it's defined.
- Added proper disposable management for the `onDidChangeConfiguration` and `onDidOpenTextDocument` events, to ensure they are properly discarded once we're done with them.
- Added new `commentBlocksDisposables` disposable array to keep track of the comment blocks.

- Changed the variable name for the comment block disposable to `commentBlocksDisposables`.

- Fixed potential memory leak in the `onDidOpenTextDocument` event handler. On each document opening, we reconfigure the comment blocks configs which pushes new disposables everytime. This could lead to memory leaks over time.

Fixed by looping through the `commentBlocksDisposables` array and disposing of each configuration, before new ones are created.
@yCodeTech yCodeTech added the enhancement New feature or quality of life enhancement label Apr 19, 2026
@yCodeTech yCodeTech merged commit 6b395b2 into master Apr 19, 2026
1 check passed
@yCodeTech yCodeTech deleted the refactor/extension-activation branch April 19, 2026 17:08
github-actions Bot added a commit that referenced this pull request Apr 19, 2026
@github-actions github-actions Bot mentioned this pull request Apr 19, 2026
yCodeTech pushed a commit that referenced this pull request Apr 19, 2026
* docs: update changelog for PR #26

* docs: update changelog for PR #29

* docs: update changelog for PR #30

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or quality of life enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant