Skip to content
Merged
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
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@
}
}
},
"commands": [
{
"command": "auto-comment-blocks.singleLineBlock",
"title": "Continue Single-Line Comment Block",
"category": "Auto Comment Blocks"
},
{
"command": "auto-comment-blocks.changeBladeMultiLineBlock",
"title": "Toggle Blade Multi-Line Comment Style",
"category": "Auto Comment Blocks"
}
],
"keybindings": [
{
"command": "auto-comment-blocks.singleLineBlock",
Expand Down
30 changes: 17 additions & 13 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {Settings} from "./interfaces/settings";
import {ExtraSingleLineCommentStyles, LineComment, SingleLineCommentStyle} from "./interfaces/commentStyles";
import {ExtensionMetaData} from "./interfaces/extensionMetaData";
import {JsonObject, JsonArray, LanguageId, MultiLineLanguageDefinitions, SingleLineLanguageDefinitions} from "./interfaces/utils";
import {CommandRegistration} from "./interfaces/commands";

export class Configuration {
/**************
Expand Down Expand Up @@ -161,22 +162,25 @@ export class Configuration {

/**
* Register some VSCode commands.
*
* @returns {vscode.Disposable[]}
*/
public registerCommands(): vscode.Disposable[] {
const singleLineBlockCommand = vscode.commands.registerTextEditorCommand("auto-comment-blocks.singleLineBlock", (textEditor, edit, args) => {
this.handleSingleLineBlock(textEditor, edit);
});
public registerCommands(context: vscode.ExtensionContext) {
const namespace = this.extensionData.get("namespace");

const changeBladeMultiLineBlockCommand = vscode.commands.registerTextEditorCommand(
"auto-comment-blocks.changeBladeMultiLineBlock",
(textEditor, edit, args) => {
this.handleChangeBladeMultiLineBlock(textEditor);
}
);
const commands: CommandRegistration[] = [
{
command: "singleLineBlock",
handler: this.handleSingleLineBlock.bind(this),
},
{
command: "changeBladeMultiLineBlock",
handler: this.handleChangeBladeMultiLineBlock.bind(this),
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

The handleChangeBladeMultiLineBlock method (line 958 in src/configuration.ts) only accepts one parameter (textEditor: vscode.TextEditor), but registerTextEditorCommand always provides both textEditor and edit parameters. While JavaScript will ignore the extra parameter, this creates a signature mismatch with the CommandRegistration.handler interface. The handler should accept the edit parameter even if it doesn't use it, for consistency and to match the VS Code API contract: (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit) => void.

Suggested change
handler: this.handleChangeBladeMultiLineBlock.bind(this),
handler: (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit) => {
this.handleChangeBladeMultiLineBlock(textEditor);
},

Copilot uses AI. Check for mistakes.
},
];

return [singleLineBlockCommand, changeBladeMultiLineBlockCommand];
commands.forEach(({command, handler}) => {
const namespacedCommand = `${namespace}.${command}`;
context.subscriptions.push(vscode.commands.registerTextEditorCommand(namespacedCommand, handler));
});
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ const disposables: vscode.Disposable[] = [];

export function activate(context: vscode.ExtensionContext) {
const configureCommentBlocksDisposable = configuration.configureCommentBlocks();
const registerCommandsDisposable = configuration.registerCommands();

disposables.push(...configureCommentBlocksDisposable, ...registerCommandsDisposable);
configuration.registerCommands(context);

disposables.push(...configureCommentBlocksDisposable);

const extensionName = extensionData.get("namespace");

Expand Down
33 changes: 33 additions & 0 deletions src/interfaces/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as vscode from "vscode";

/**
* Defines the structure for registering commands.
*/
export interface CommandRegistration {
/**
* The command ID, corresponding to those defined in package.json
*
* @type {keyof Commands}
*/
command: keyof Commands;

/**
* The command handler function.
*
* The parameters are passed to the handler automatically by VS Code when the
* command is executed.
*
* @param textEditor The text editor
* @param edit The text editor edits. Optional because some commands may not need it.
* @returns void
*/
handler: (textEditor: vscode.TextEditor, edit?: vscode.TextEditorEdit) => void;
Comment on lines +21 to +24
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

The edit parameter should not be optional. The VS Code API for registerTextEditorCommand always provides both textEditor and edit parameters to the handler function. The comment on line 21 stating "Optional because some commands may not need it" is misleading - whether a command uses the parameter is different from whether the parameter is provided by the API. The handler signature should be: (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit) => void.

Suggested change
* @param edit The text editor edits. Optional because some commands may not need it.
* @returns void
*/
handler: (textEditor: vscode.TextEditor, edit?: vscode.TextEditorEdit) => void;
* @param edit The text editor edits. Always provided by VS Code, though some commands may not use it.
* @returns void
*/
handler: (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit) => void;

Copilot uses AI. Check for mistakes.
}

/**
* Defines command IDs without the namespace prefix.
*/
interface Commands {
singleLineBlock: string;
changeBladeMultiLineBlock: string;
}
Loading