refactor: extension activation and performance improvements#29
Merged
refactor: extension activation and performance improvements#29
Conversation
- 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.
Merged
yCodeTech
pushed a commit
that referenced
this pull request
Apr 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactored the
activatefunction 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
showReloadMessagehelper function, reducing code duplication.Improved performance and event handling to prevent memory leaks by properly disposing of old comment configurations.