Skip to content

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

Open
yCodeTech wants to merge 5 commits into
masterfrom
feat/auto-update-language-definitions-on-settings-change
Open

feat: ability to auto-update the language definitions on settings change#53
yCodeTech wants to merge 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 PR adds the ability to auto-update the language definitions and reconfigure the comment blocks when the user settings 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.

…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.
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