Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.1.0 #1

Merged
merged 27 commits into from
Dec 22, 2024
Merged

Release v1.1.0 #1

merged 27 commits into from
Dec 22, 2024

Conversation

yCodeTech
Copy link
Owner

@yCodeTech yCodeTech commented Dec 3, 2024

Release v1.1.0 adds auto detection of supported languages by grabbing all language configuration files internally added either officially by VScode or by 3rd party extensions.

Changelog Brief Overview:

Removed:

  • All language configuration files and package.json contribution declaration, in favour of auto-supported languages. So this extension no longer needs to keep adding language support, as the extension does it automatically.

Added:

View the commits below for a more detailed changelog.

…ternal configs.

Also, change package.json:

- Version bump.
- Fix user settings descriptions.
- Remove language contribution declaration.
- Added 3 new user settings:
`multiLineStyleBlocks` to add unsupported languages to use the `/** */` comments;

`overrideDefaultLanguageMultiLineComments` to override the style of multi-line comments for a language for the native vscode `blockComment` command.

`bladeOverrideComments` to switch between HTML style `<!-- -->` comments, and Blade style `{{--  --}}` comments, when the file is using the Blade language. Also added a new keybinding for this.

- Updated various dependencies and added new ones.
…as been changed, and show an information message to the user.

Also re-configures the comment blocks when the active editor language has been changed.
- The default multi-line language config that define the block comment and auto closing pairs, ready to merge with the internal language configs.
- An array of languages to skip while finding the internal language configs, because these languages don't have any useful configs that we need.
…grouped together properly, and add a rule for the normal `/* */` comment.
…omment `;;`.

The descriptive comments are to prevent confusion over what the regexes are matching.
… and command, plus others.

- bladeOverrideComments command functionality to enable/disable the usage of Blade's `{{-- --}}` comments instead of HTML `<!-- -->` comments  in blade files.

- Add various typings.

- Refactor some code:
   - Use `array.includes()` instead of `array.indexOf()`.

   - Add a new method `getExtensionNames()` to obtain the extension name, id, and display name from the package.json instead of the explicitly coded `extensionName` property. Removed all references to the old property.

   - Add a cleaner, DRYer way to the disposables. Collect all disposables in an array and then push the array elements into the extension context subscriptions at the very end.
…automatically support any language found internally in vscode.

Deleted:

- Delete the hardcoded single-line and multi-line configuration files and imports.

Added:

- Auto-generated language definition files.

   These files, will be overwritten every time the extension activates or renews it's
   definitions.

- Several new properties to define new Map()s for the language paths, configs, and definitions.

- `findAllLanguageConfigFilePaths()` to find all internal language config file paths from vscode installed extensions (built-in and 3rd party).

- `readJsonFile()` and npm packages to read and parse JSON files.

- `getLanguagesToSkip()` to read and skip the languages defined in the skip-languages config file.

- `setLanguageConfigDefinitions()` to read and set the language config definitions into the Map.

- `getLanguageConfig()`  to get a specified language config from the definition Map.

- `writeJsonFile()` to write JSON into a file.

- `setMultiLineCommentLanguageDefinitions()` to determine if a language supports block comments, and set the supported languages into the definition Map.

- `setSingleLineCommentLanguageDefinitions()` - replaces the old functionality of `getSingleLineLanguages()` - to determine if a language supports a particular line comment, and set the supported languages into the definition Map.

- `writeCommentLanguageDefinitionsToJsonFile()` to write the single-line and multi-line comment language definitions into the auto-generated definitions JSON files respectively.

- `mergeConfigAutoClosingPairs()` to merge the autoClosingPairs of the internal config with the default, removing any duplicates.

- `mergeConfigOnEnterRules()` to merge the onEnterRules of the internal config with the default, removing any duplicates.

- Add a constructor() to setup the definitions.

Changed:
- Simplified `getSingleLineLanguages()` to return just the Map, and moved the functionality into the new method `setSingleLineCommentLanguageDefinitions()`.

- `setLanguageConfiguration()` to use the new internal language configs and merge the configs with the default multi-line config if required and then set vscode to use the language configuration for the extension to work its magic.
 ...change the `getMultiLineLanguages()` to use the Map.
 Also change vscode typings to use vscode global variable.
…efaultLanguageMultiLineComments` config setting.

- Remove unnecessary properties that only define strings, and move the strings directly into the methods that need them. These properties are only declaring the configuration setting names, which are mostly only used once, but contributes to code bloat.

- Added the functionality of `disabledLanguageList` and `overriddenLangMultiLineCommentList` properties directly into the `isLangIdDisabled` and `isLangIdMultiLineCommentOverridden` methods respectively, and removed the unnecessary properties.

- Added `isLangIdMultiLineCommentOverridden` method to determine if the specified language ID is in the `overrideDefaultLanguageMultiLineComments` config setting.

- Added `getOverriddenMultiLineComment` method to get the overridden multi-line comment for that language ID within the `overrideDefaultLanguageMultiLineComments` config setting.

- Move the `languageConfigFilePaths` and `languageConfigs` properties to the top to keep things in order of usage.
… simplify code.

- Added `getConfigurationValue` method to get the value of the specified key from the extension's config settings.

- Added `updateConfigurationValue` method to update value of the specified key from the extension's config settings.

- Changed all code to use these methods. This is so we only chain `vscode.WorkspaceConfiguration`'s `get` and `update` methods directly in the corresponding new methods, which simplifies code.
…e extension, and more.

Fix:

- The `for...of` loops in `configureCommentBlocks` method to use the `singleLineLangs` variable which uses the `getSingleLineLanguages` method instead of directly using the property `singleLineBlocksMap`.

- The single line languages `for...of` loop to only setup the config for the langId if it's not currently set as disabled in the user config settings, using the `isLangIdDisabled` method to check.

- The merging of onEnterRules for single-line comments. When a language config doesn't have the `onEnterRules` key and the user config setting `singleLineBlockOnEnter` is true, previously the extension couldn't be activated due to the error:

> Cannot read properties of undefined (reading 'concat')

because the key is undefined. Fixed by using the chaining operator (?.) before trying to access the array method `concat`. If the key exists then concat still works and combines the new rules with the internal config rules. If key is undefined then by using the nullish coalescing operator (??) we just assign the new rules since there's no rules to combine with.

- When a config has the `wordPattern` key with a regex pattern as a string,
the extension can't activate due to the error:

> TypeError: e.exec is not a function

It's unknown why the allowed regex as string causes this, there seems to be a similar, related issue in microsoft/vscode#171194 but was closed as (wrongly?) an invalid issue.

Fixed by changing the string to an actual regex pattern. But because `wordPattern` can also be an object with a key of `pattern` then we also need to change this and add the regex pattern directly as the value of `wordPattern` instead of an object.

- The extension only ran on opening a document, but we need it to run everytime the current editor changes or the current language changes. Fixed to use the on change event `onDidChangeTextDocument` instead.

Removed:

- Remove the unnecessary check for the length of landId is more than 0 in `setMultiLineCommentLanguageDefinitions` method, because just the first part of that conditional also checks for not NULL or empty strings, so the extra check is redundant.

Added:

- The return type of `getExtensionNames` method, now as an object with `id`, `name`, and `displayName` keys, so TS isn't guessing at compile time.

- Code comments

- The execution of changing the blockComment style when it's been overridden for that langId in the user config settings.
Change:

- The format of the language definitions to separate user-defined languages from the auto-supported languages. (added keys `supportedLanguages` and `customSupportedLanguages` to both multi-line and single-line definitions.)

- `singleLineBlocksMap` property type to accept a nested Map.

- `getMultiLineLanguages` and `getSingleLineLanguages` methods to accept a stringed key parameter and return the value of that key from the Map. Also changed all references to utilise the new key parameter.

- `setMultiLineCommentLanguageDefinitions` and `setSingleLineCommentLanguageDefinitions` methods to set both auto-supported and custom-supported languages into the correct key.

- `writeCommentLanguageDefinitionsToJsonFile` method to only be called once per activation, in the class constructor. (Removed the calls in `setMultiLineCommentLanguageDefinitions` and `setSingleLineCommentLanguageDefinitions` methods.)

- `handleSingleLineBlock` to use the `getSingleLineLanguages` method instead of the actual property. Also added the customSupportedLangs to it.

Removed:
- `reverseMapping` function in `writeCommentLanguageDefinitionsToJsonFile` in favour of the new `convertMapToReversedObject` method.

Added:

- New `convertMapToReversedObject` method to convert the `singleLineBlocksMap` to an object while also reversing the keys and values of the nested map into an key : array pair, where the key is the original value, and an array of the original keys.

- The `defaultMultiLineConfig` comments to the `langConfig` only if the comments key doesn't exist. Necessary for custom-supported languages to properly have block comment support.

- The `lineComment` to the `langConfig` comments only if it doesn't exist.

- Implementation to setup the custom supported languages to `configureCommentBlocks` method.

- Various code comments and TODOs and FIXMEs.

- User information messages if the `multiLineStyleBlocks`, `slashStyleBlocks`, `hashStyleBlocks` or `semicolonStyleBlocks` settings change, and prompt the user to reload the extension.
…ent`

In commit 30de00a, the `onDidOpenTextDocument` workspace event in `extension.ts` was changed to `onDidChangeTextDocument`, with the assumption that the former only ran the function when opening a document. However, this is not the case. It runs when a document is opened OR when the language ID has been changed. It's fully described in https://github.com/microsoft/vscode/blob/4e8fbaef741afebd24684b88cac47c2f44dfb8eb/src/vscode-dts/vscode.d.ts#L13716-L13728

This also fixes the issue of running the extension on every document change, even if it's not a comment, which would eventually cause performance issues.
…terRules` methods...

...into one to make the new `mergeConfig` method, and updated the references to use it.
…hing it's regex.

When using `//!`-style and the `singleLineBlockOnEnter` setting is turned on, the `//` regex matches because the negative lookahead `(?!...)` expression doesn't include the `!` therefore it would still match the `//` part of the `//!`. Therefore, it would enter `//` on the next line instead of the anticipated `//!`-style.

Fixed by updating the regex to include the `!` in the negative lookahead expression which basically means "don't match if it has these characters in".
@yCodeTech yCodeTech closed this Dec 22, 2024
@yCodeTech yCodeTech reopened this Dec 22, 2024
@yCodeTech yCodeTech merged commit 657b723 into master Dec 22, 2024
@yCodeTech yCodeTech deleted the release/v1.1.0 branch December 26, 2024 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant