Skip to content

feat: ability to auto-update the language definitions on settings change - #53

Merged
yCodeTech merged 5 commits into
masterfrom
feat/auto-update-language-definitions-on-settings-change
Aug 26, 2026
Merged

feat: ability to auto-update the language definitions on settings change#53
yCodeTech merged 5 commits into
masterfrom
feat/auto-update-language-definitions-on-settings-change

Conversation

@yCodeTech

@yCodeTech yCodeTech commented Aug 21, 2026

Copy link
Copy Markdown
Owner

This pull request introduces several improvements to how language comment block definitions are managed and updated in the extension. The most significant changes are the ability to auto update language definitions on settings change without requiring an extension host reload, the caching of configuration files for efficiency, and performance improvements. Below are the most important changes:

Auto-Update Language Definitions:

  • Added a new updateLanguageDefinitions method to Configuration, allowing language comment block definitions to be updated at runtime without requiring an extension host reload.

  • The extension now listens for changes to relevant configuration settings in the activate function and automatically updates language definitions and reconfigures the comment blocks as needed, removing the pop-up message and the requirement for an extension reload.

Performance Improvements:

  • Accidental cached data mutation prevention and unnecessary disk read improvements:

    • The setLanguageConfiguration method now deep-clones language configurations before modification to prevent accidental mutation of cached data.

    • The default multi-line language configuration (default-multi-line-config.json) and the languages to skip (skip-languages.jsonc) files are now read once during initialisation and cached for later use, improving efficiency and reducing redundant disk reads on every loop iteration.

  • Writing of Language Definition Files and Logging Enhancements:

    • The extension no longer writes the current language definitions to JSON files in production, they are only written in development and testing modes for easier debugging and quick reference during development, and preventing unnecessary file writes in production.

    • Refactored the debug logging in the logDebugInfo method to use the existing cached language definitions instead of reading from files, improving efficiency.

These changes collectively improve the maintainability, performance, and experience of the extension.

…change

- Added new `updateLanguageDefinitions` function in Configuration class to update the language definitions.

- Refactored the `onDidChangeConfiguration` event in the `activate` function of the extension to auto-update the language definitions and reconfigure the comment blocks when a user changes the settings. It uses the new `updateLanguageDefinitions` function to update the definitions before reconfiguring the comment blocks.

- Removed the old `reloadRequiredSettings` array and the `showReloadMessage` function.
@yCodeTech yCodeTech added the enhancement New feature or quality of life enhancement label Aug 21, 2026
- Added new Configuration class properties:
    - `defaultMultiLineConfig` to store the default multi-line configuration object.
    - `languagesToSkip` to store the languages to skip object.

- Refactored `getLanguagesToSkip` method to get the languages from the new `languagesToSkip` class property instead of repeatedly reading the `skip-languages.jsonc` file from disk on every loop iteration of the `findAllLanguageConfigFilePaths` method.

- Refactored `setLanguageConfiguration` method to get the default config from the new `defaultMultiLineConfig` class property instead of repeatedly reading the `default-multi-line-config.json` file from disk on every loop iteration of the `configureCommentBlocks` method.

- Added a once-per-activation disk read of the `default-multi-line-config.json` and `skip-languages.jsonc` files in the Configuration `constructor` method, and add their contents to the respective new properties. This caches the JSON objects in memory ready for later use, enhancing performance by not reading them from disk on every loop iteration.
Writing to the auto generated language definition files is not very useful in production and are only helpful in development. In production, they are only ever read from disk to log their data for debugging.
So for performance, they should only be written when in development/testing mode, and the updated definitions should only be cached in memory in production mode.

- Removed the `writeCommentLanguageDefinitionsToJsonFile` method calls from the `constructor` and `updateLanguageDefinitions` methods.

- Refactored `writeCommentLanguageDefinitionsToJsonFile` method:

    - Changed the visibility of the method from `private` to `public`, so it can be called from outside of the class.

    - Extracted the call to the `convertMapToReversedObject` utils function into a new method: `getSingleLineLanguageDefinitions`. This method returns the formatted and reversed single-line definitions object ready for logging or writing to JSON file.

    - Extracted the `Object.fromEntries` call into a new method: `getMultiLineLanguageDefinitions`. This method returns the formatted multi-line definitions object ready for logging or writing to JSON file.

    - Changed the `writeJsonFile` method calls to get the data from the 2 new methods instead of the old removed variables.

- Changed the logging of the language definitions in `logDebugInfo` method to get the data from the new `getMultiLineLanguageDefinitions` and `getSingleLineLanguageDefinitions` methods, instead of reading directly from disk.

- Added a conditional in the `activate` function to only run the `writeCommentLanguageDefinitionsToJsonFile` Configuration method when the context of the extension is not running in production (ie. it's running in development or testing mode).

The same conditional is added into the configuration change event so when the definitions auto update they are written to the files in development/testing mode.
This helps vscode to show intellisense on native JS functions.
…rride.

While adding a multi-line override in the `overrideDefaultLanguageMultiLineComments` setting auto-updated the language definitions correctly and used the override style, removing the override didn't work and it was still in place internally in vscode, and the extension's auto-complete no-longer worked.

This happened because the override was inadvertently changing the multi-line style in the cached internal language config whilst also changing it on the shallow-copy for the immediate setting into vscode. So without ever changing it back as it was never supposed to be changed, the override was still apart of the extension's cached language configs making it permanent and breaking functionality.

- Fixed by deep-cloning the `internalLangConfig` using JavaScript's `structuredClone` function in `setLanguageConfiguration` method so mutations (like comment overrides) never write back into the cached `languageConfigs` Map, which prevents pollution during definition auto-updates.

- Added deep-cloning of the comments object in the cached `defaultMultiLineConfig` using `structuredClone` to prevent shared references and accidental mutations down the line during the fallback assignment.

- Update comment override assignment to construct a new block comment tuple while preserving the ending, instead of mutating the existing array in place.
@yCodeTech
yCodeTech merged commit a961988 into master Aug 26, 2026
1 check passed
@yCodeTech
yCodeTech deleted the feat/auto-update-language-definitions-on-settings-change branch August 26, 2026 06:34
github-actions Bot added a commit that referenced this pull request Aug 26, 2026
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