diff --git a/package.json b/package.json index 76955a1..720ec8b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "automatic-comment-blocks", "displayName": "Automatic Comment Blocks", "description": "Provides block comment completion for Javadoc-style multi-line comments and single-line comment blocks for most officially supported languages.", - "version": "1.1.4", + "version": "1.2.0", "publisher": "ycodetech", "homepage": "https://github.com/ycodetech/auto-comment-blocks", "repository": { @@ -45,20 +45,64 @@ "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." + } + } + }, "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 `slashStyleBlocks` 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 `slashStyleBlocks` instead.", + "markdownDeprecationMessage": "**Deprecated**: Please use `#auto-comment-blocks.supportUnsupportedLanguages#` with the property key `semicolonStyleBlocks` instead." }, "auto-comment-blocks.multiLineStyleBlocks": { "type": "array", @@ -66,7 +110,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 7fe8ce3..19e04d5 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -247,6 +247,17 @@ 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(); + } + /** * Is the multi-line comment overridden for the specified language ID? * @@ -271,6 +282,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 * @@ -509,7 +545,7 @@ export class Configuration { tempMap.clear(); // Get user-customized langIds for the //-style and add to the map. - let customSlashLangs = this.getConfigurationValue("slashStyleBlocks"); + let customSlashLangs = this.getCustomSupportedLangConfigurationValue("slashStyleBlocks"); for (let langId of customSlashLangs) { if (langId && langId.length > 0) { tempMap.set(langId, "//"); @@ -517,7 +553,7 @@ export class Configuration { } // Get user-customized langIds for the #-style and add to the map. - let customHashLangs = this.getConfigurationValue("hashStyleBlocks"); + let customHashLangs = this.getCustomSupportedLangConfigurationValue("hashStyleBlocks"); for (let langId of customHashLangs) { if (langId && langId.length > 0) { tempMap.set(langId, "#"); @@ -525,7 +561,7 @@ export class Configuration { } // Get user-customized langIds for the ;-style and add to the map. - let customSemicolonLangs = this.getConfigurationValue("semicolonStyleBlocks"); + let customSemicolonLangs = this.getCustomSupportedLangConfigurationValue("semicolonStyleBlocks"); for (let langId of customSemicolonLangs) { if (langId && langId.length > 0) { tempMap.set(langId, ";"); diff --git a/src/extension.ts b/src/extension.ts index 27d8208..658f229 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"; @@ -80,67 +82,14 @@ export function activate(context: vscode.ExtensionContext) { } /** - * Multi-line style Block Comments + * Support Unsupported Languages */ - if (event.affectsConfiguration(`${extensionName}.multiLineStyleBlocks`)) { - vscode.window - .showInformationMessage( - `The ${extensionName}.multiLineStyleBlocks setting has been changed. Please reload the Extension Host to take effect.`, - "Reload" - ) - .then((selection) => { - if (selection === "Reload") { - vscode.commands.executeCommand("workbench.action.restartExtensionHost"); - } - }); - } + if (event.affectsConfiguration(`${extensionName}.supportUnsupportedLanguages`)) { + configuration.updateSingleLineCommentLanguageDefinitions(); - /** - * //-style single-line comments - */ - if (event.affectsConfiguration(`${extensionName}.slashStyleBlocks`)) { - vscode.window - .showInformationMessage( - `The ${extensionName}.slashStyleBlocks setting has been changed. Please reload the Extension Host to take effect.`, - "Reload" - ) - .then((selection) => { - if (selection === "Reload") { - vscode.commands.executeCommand("workbench.action.restartExtensionHost"); - } - }); - } + const configureCommentBlocksDisposable = configuration.configureCommentBlocks(context); - /** - * #-style single-line comments - */ - if (event.affectsConfiguration(`${extensionName}.hashStyleBlocks`)) { - vscode.window - .showInformationMessage( - `The ${extensionName}.hashStyleBlocks setting has been changed. Please reload the Extension Host to take effect.`, - "Reload" - ) - .then((selection) => { - if (selection === "Reload") { - vscode.commands.executeCommand("workbench.action.restartExtensionHost"); - } - }); - } - - /** - * ;-style single-line comments - */ - if (event.affectsConfiguration(`${extensionName}.semicolonStyleBlocks`)) { - vscode.window - .showInformationMessage( - `The ${extensionName}.semicolonStyleBlocks setting has been changed. Please reload the Extension Host to take effect.`, - "Reload" - ) - .then((selection) => { - if (selection === "Reload") { - vscode.commands.executeCommand("workbench.action.restartExtensionHost"); - } - }); + disposables.push(...configureCommentBlocksDisposable); } });