I published my first Visual Studio Code extension recently, but even though the extension works properly in Visual Studio Code while debugging the extension, it doesn't work when installed from the Marketplace or when loading the .vsix file manually in Visual Studio Code.
The extension is here: https://marketplace.visualstudio.com/items?itemName=john-wargo.describer-genai The source code is here: https://github.com/johnwargo/vscode-describer-genai
The extension publishes two commands:
describer-genai.configdescriber-genai.generate
The config command opens the settings for the extension:
const configCmd = `${extensionName}.config`;
const configHandler = () => {
vscode.commands.executeCommand('workbench.action.openSettings', 'describer-genai.');
};
context.subscriptions.push(vscode.commands.registerCommand(configCmd, configHandler));
but when I install the extension from marketplace or by directly loading the .vsix file and execute the config command from the Visual Studio Code Command Palette, instead of opening the settings page to my extension's settings like its supposed to, VSCode instead displays an error dialog with the following content:
Command 'Open Describer Settings' resulted in an error
command 'describer-genai-config' not found
The generate command first checks the settings page to ensure that the required settings values are populated:
const config = vscode.workspace.getConfiguration(extensionName);
let apiKey: string = config.apiKey;
if (!apiKey) {
doNotify(DialogType.dtError, 'Extension Configuration missing ChatGPT API Key');
return;
}
let targetProperty: string = config.targetProperty;
if (!targetProperty) {
doNotify(DialogType.dtError, 'Extension Configuration missing Description Property');
return;
}
The displays a notification in Visual Studio Code using vscode.window.showInformationMessage as shown in the function below:
export function doNotify(dialogType: DialogType, msg: string) {
switch (dialogType) {
case DialogType.dtError:
vscode.window.showErrorMessage(`Describer: ${msg}`);
break;
case DialogType.dtWarning:
vscode.window.showWarningMessage(`Describer: ${msg}`);
break;
default:
vscode.window.showInformationMessage(`Describer: ${msg}`);
break;
}
}
When I open a markdown file in Visual Studio Code and right-click to invoke the generate command, nothing happens. It should display an error message in Visual Studio Code, but nothing of the sort happens.
I assume the extension isn't initializing correctly - the command palette and right-click menu items are registered (because they're initialized through the extension's package.json file), but the actual extension code fails on initialization and I can't tell how or why.
I saw some other posts here that related to the error, but didn't seem relevant to my particular problem:
- VSCode Extension: Command 'Hello World' resulted in an error (command 'vscode-err-reproduce.helloWorld' not found) but my /out folder contains my extension code.
- Visual Studio Code - C/C++ Extension commands don't exist but this extension simply calls an API and modifies a document in the editor. I can't see how an incompatibility would apply here nor how to determine if there's one.
I had a bunch of console.log statements in the code, so I removed all of them and installed the extension manually and saw the same results. I thought perhaps VSCode didn't support them in an extension, but that didn't make any difference.