feat: ability to auto-update the language definitions on settings change - #53
Open
yCodeTech wants to merge 5 commits into
Open
feat: ability to auto-update the language definitions on settings change#53yCodeTech wants to merge 5 commits into
yCodeTech wants to merge 5 commits into
Conversation
…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.
- 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.
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.
This PR adds the ability to auto-update the language definitions and reconfigure the comment blocks when the user settings change.
Added new
updateLanguageDefinitionsfunction in Configuration class to update the language definitions.Refactored the
onDidChangeConfigurationevent in theactivatefunction of the extension to auto-update the language definitions and reconfigure the comment blocks when a user changes the settings. It uses the newupdateLanguageDefinitionsfunction to update the definitions before reconfiguring the comment blocks.Removed the old
reloadRequiredSettingsarray and theshowReloadMessagefunction.