Skip to content

Release v1.2.0: Enable language definitions to be auto updated and reconfigured when user settings change. #3

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 51 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -45,28 +45,74 @@
"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",
"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']`"
"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",
Expand Down
42 changes: 39 additions & 3 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,17 @@ export class Configuration {
return this.getConfigurationValue<string[]>("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?
*
Expand All @@ -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<string[]>(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<any>("supportUnsupportedLanguages")[key];
}

/**
* Get an array of languages to skip, like plaintext, that don't have comment syntax
*
Expand Down Expand Up @@ -509,23 +545,23 @@ export class Configuration {
tempMap.clear();

// Get user-customized langIds for the //-style and add to the map.
let customSlashLangs = this.getConfigurationValue<string[]>("slashStyleBlocks");
let customSlashLangs = this.getCustomSupportedLangConfigurationValue("slashStyleBlocks");
for (let langId of customSlashLangs) {
if (langId && langId.length > 0) {
tempMap.set(langId, "//");
}
}

// Get user-customized langIds for the #-style and add to the map.
let customHashLangs = this.getConfigurationValue<string[]>("hashStyleBlocks");
let customHashLangs = this.getCustomSupportedLangConfigurationValue("hashStyleBlocks");
for (let langId of customHashLangs) {
if (langId && langId.length > 0) {
tempMap.set(langId, "#");
}
}

// Get user-customized langIds for the ;-style and add to the map.
let customSemicolonLangs = this.getConfigurationValue<string[]>("semicolonStyleBlocks");
let customSemicolonLangs = this.getCustomSupportedLangConfigurationValue("semicolonStyleBlocks");
for (let langId of customSemicolonLangs) {
if (langId && langId.length > 0) {
tempMap.set(langId, ";");
Expand Down
65 changes: 7 additions & 58 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
}
});

Expand Down