diff --git a/package.json b/package.json index ad9bee2..e55bdbb 100644 --- a/package.json +++ b/package.json @@ -45,20 +45,66 @@ "default": [], "markdownDescription": "Add language IDs here to disable any comment completion for that language." }, + "auto-comment-blocks.supportUnsupportedLanguages": { + "type": "object", + "default": { + "multiLineStyleBlocks": [ + "blade", + "html" + ], + "slashStyleBlocks": [], + "hashStyleBlocks": [], + "semicolonStyleBlocks": [] + }, + "markdownDescription": "Enables unsupported languages to have comment completion. \n\rProperties: \n- `multiLineStyleBlocks` to enable multi-line block comment support. The default is `['blade', 'html']` \n- `slashStyleBlocks` to enable `//`-style single-line comment support. \n- `hashStyleBlocks` to enable `#`-style single-line comment support. \n- `semicolonStyleBlocks` to enable `;`-style single-line comment support.", + "properties": { + "multiLineStyleBlocks": { + "type": "array", + "default": [ + "blade", + "html" + ], + "markdownDescription": "Add language IDs here to enable multi-line comment blocks support for that language. This allows unsupported languages to have comment completion. The default is `['blade', 'html']`" + }, + "slashStyleBlocks": { + "type": "array", + "default": [], + "markdownDescription": "Add language IDs to enable `//`-style single-line comment blocks for that language." + }, + "hashStyleBlocks": { + "type": "array", + "default": [], + "markdownDescription": "Add language IDs to enable `#`-style single-line comment blocks for that language." + }, + "semicolonStyleBlocks": { + "type": "array", + "default": [], + "markdownDescription": "Add language IDs to enable `;`-style single-line comment blocks for that language." + } + }, + "additionalProperties": false, + "order": 0 + }, "auto-comment-blocks.slashStyleBlocks": { "type": "array", "default": [], - "markdownDescription": "Add language IDs here to enable `//` and `///`-style single-line comment blocks for that language. This allows unsupported languages to have comment completion." + "markdownDescription": "Add language IDs here to enable `//` and `///`-style single-line comment blocks for that language. This allows unsupported languages to have comment completion.", + "deprecationMessage": "**Deprecated**: Please use `auto-comment-blocks.supportUnsupportedLanguages` with the property key `slashStyleBlocks` instead.", + "markdownDeprecationMessage": "**Deprecated**: Please use `#auto-comment-blocks.supportUnsupportedLanguages#` with the property key `slashStyleBlocks` instead." }, "auto-comment-blocks.hashStyleBlocks": { "type": "array", "default": [], - "markdownDescription": "Add language IDs here to enable `#`-style single-line comment blocks for that language. This allows unsupported languages to have comment completion." + "markdownDescription": "Add language IDs here to enable `#`-style single-line comment blocks for that language. This allows unsupported languages to have comment completion.", + "deprecationMessage": "**Deprecated**: Please use `auto-comment-blocks.supportUnsupportedLanguages` with the property key `hashStyleBlocks` instead.", + "markdownDeprecationMessage": "**Deprecated**: Please use `#auto-comment-blocks.supportUnsupportedLanguages#` with the property key `hashStyleBlocks` instead." }, "auto-comment-blocks.semicolonStyleBlocks": { "type": "array", "default": [], - "markdownDescription": "Add language IDs here to enable `;`-style single-line comment blocks for that language. This allows unsupported languages to have comment completion." + "markdownDescription": "Add language IDs here to enable `;`-style single-line comment blocks for that language. This allows unsupported languages to have comment completion.", + "deprecationMessage": "**Deprecated**: Please use `auto-comment-blocks.supportUnsupportedLanguages` with the property key `semicolonStyleBlocks` instead.", + "markdownDeprecationMessage": "**Deprecated**: Please use `#auto-comment-blocks.supportUnsupportedLanguages#` with the property key `semicolonStyleBlocks` instead." }, "auto-comment-blocks.multiLineStyleBlocks": { "type": "array", @@ -66,7 +112,9 @@ "blade", "html" ], - "markdownDescription": "Add language IDs here to enable multi-line comment blocks support for that language. This allows unsupported languages to have comment completion. The default is `['blade', 'html']`" + "markdownDescription": "Add language IDs here to enable multi-line comment blocks support for that language. This allows unsupported languages to have comment completion. The default is `['blade', 'html']`", + "deprecationMessage": "**Deprecated**: Please use `auto-comment-blocks.supportUnsupportedLanguages` with the property key `multiLineStyleBlocks` instead.", + "markdownDeprecationMessage": "**Deprecated**: Please use `#auto-comment-blocks.supportUnsupportedLanguages#` with the property key `multiLineStyleBlocks` instead." }, "auto-comment-blocks.overrideDefaultLanguageMultiLineComments": { "type": "object", diff --git a/src/configuration.ts b/src/configuration.ts index 3acb96d..f6ef9f7 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -272,6 +272,28 @@ export class Configuration { return this.getConfigurationValue("disabledLanguages").includes(langId); } + /** + * Update the single-line comment language definitions. + */ + public updateSingleLineCommentLanguageDefinitions() { + // Remove all elements from the current Map, so we can update + // the definitions with an empty Map. + this.singleLineBlocksMap.clear(); + // Update the definitions. + this.setSingleLineCommentLanguageDefinitions(); + } + + /** + * Update the single-line comment language definitions. + */ + public updateSingleLineCommentLanguageDefinitions() { + // Remove all elements from the current Map, so we can update + // the definitions with an empty Map. + this.singleLineBlocksMap.clear(); + // Update the definitions. + this.setSingleLineCommentLanguageDefinitions(); + } + /** * Is the multi-line comment overridden for the specified language ID? * @@ -296,6 +318,31 @@ export class Configuration { return overriddenList[langId]; } + /** + * Get the custom supported language configuration value for the specified key. + * + * Decides which setting to return, either the old or new setting. + * + * @param {string} key - The configuration key to retrieve. Can be one of `"slashStyleBlocks"`, `"hashStyleBlocks"`, or `"semicolonStyleBlocks"`. + * @returns {string[]} An array of strings representing the configuration values. + */ + private getCustomSupportedLangConfigurationValue(key: "slashStyleBlocks" | "hashStyleBlocks" | "semicolonStyleBlocks"): string[] { + /** + * @deprecated since v1.2.0, will be removed in v2.0.0 + */ + // Get the old configuration property. + const oldConfigProp = this.getConfigurationValue(key); + + // If old config property has a length more than 0 (ie. it has values in the array), + // then return the old property array. + if (oldConfigProp.length > 0) { + return oldConfigProp; + } + + // Otherwise, return the property array from the new supportUnsupportedLanguages setting. + return this.getConfigurationValue("supportUnsupportedLanguages")[key]; + } + /** * Get an array of languages to skip, like plaintext, that don't have comment syntax * @@ -594,7 +641,7 @@ export class Configuration { settingKey: "slashStyleBlocks" | "hashStyleBlocks" | "semicolonStyleBlocks", style: SingleLineCommentStyle ): void { - const customLangs = this.getConfigurationValue(settingKey); + const customLangs = this.getCustomSupportedLangConfigurationValue(settingKey); for (const langId of customLangs) { // If langId exists (ie. not NULL or empty string) AND // the langId is longer than 0, AND diff --git a/src/extension.ts b/src/extension.ts index c76915f..d425671 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,5 +1,7 @@ "use strict"; +// INFO: How to publish extension: https://code.visualstudio.com/api/working-with-extensions/publishing-extension#publishing-extensions + import * as vscode from "vscode"; import {Configuration} from "./configuration"; @@ -57,15 +59,19 @@ export function activate(context: vscode.ExtensionContext) { } } + /** + * Support Unsupported Languages + */ + if (event.affectsConfiguration(`${extensionName}.supportUnsupportedLanguages`)) { + configuration.updateSingleLineCommentLanguageDefinitions(); + + const configureCommentBlocksDisposable = configuration.configureCommentBlocks(); + + disposables.push(...configureCommentBlocksDisposable); + } + // Settings that require an extension host reload when changed. - const reloadRequiredSettings = [ - "disabledLanguages", - "overrideDefaultLanguageMultiLineComments", - "multiLineStyleBlocks", - "slashStyleBlocks", - "hashStyleBlocks", - "semicolonStyleBlocks", - ]; + const reloadRequiredSettings = ["disabledLanguages", "overrideDefaultLanguageMultiLineComments"]; // Settings that require extension host reload for (const setting of reloadRequiredSettings) {