Skip to content
Closed
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: 52 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,76 @@
"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",
"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
49 changes: 48 additions & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,28 @@
return this.getConfigurationValue("disabledLanguages").includes(langId);
}

/**
* Update the single-line comment language definitions.
*/
public updateSingleLineCommentLanguageDefinitions() {

Check failure on line 278 in src/configuration.ts

View workflow job for this annotation

GitHub Actions / check-ts

Duplicate function implementation.
// 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() {

Check failure on line 289 in src/configuration.ts

View workflow job for this annotation

GitHub Actions / check-ts

Duplicate function implementation.
// 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 @@ -296,6 +318,31 @@
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);

Check failure on line 334 in src/configuration.ts

View workflow job for this annotation

GitHub Actions / check-ts

Type 'string[]' does not satisfy the constraint 'keyof Settings'.

// 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) {

Check failure on line 338 in src/configuration.ts

View workflow job for this annotation

GitHub Actions / check-ts

Property 'length' does not exist on type 'unknown'.
return oldConfigProp;

Check failure on line 339 in src/configuration.ts

View workflow job for this annotation

GitHub Actions / check-ts

Type '{}' is missing the following properties from type 'string[]': length, pop, push, concat, and 29 more.
}

// Otherwise, return the property array from the new supportUnsupportedLanguages setting.
return this.getConfigurationValue<any>("supportUnsupportedLanguages")[key];

Copilot AI Jul 27, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using any type defeats TypeScript's type safety. Consider defining a proper interface for the supportUnsupportedLanguages configuration object with properties multiLineStyleBlocks, slashStyleBlocks, hashStyleBlocks, and semicolonStyleBlocks as string arrays.

Suggested change
return this.getConfigurationValue<any>("supportUnsupportedLanguages")[key];
return this.getConfigurationValue<SupportUnsupportedLanguagesConfig>("supportUnsupportedLanguages")[key];

Copilot uses AI. Check for mistakes.
}

/**
* Get an array of languages to skip, like plaintext, that don't have comment syntax
*
Expand Down Expand Up @@ -594,7 +641,7 @@
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
Expand Down
22 changes: 14 additions & 8 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 @@ -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) {
Expand Down
Loading