0

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.config
  • describer-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:

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.

2
  • Please use Help | Toggle Developer Tools to see if any error occurred during extension registration. Typical causes are missing dependencies in your extension package for deployment. Commented Mar 17, 2024 at 3:48
  • Thank you, it is a missing dependency, but the package.json file has all of them listed, I checked. import * as vscode from 'vscode'; import OpenAI from 'openai'; import YAML from 'yaml'; "dependencies": { "openai": "^4.29.1", "yaml": "^2.3.4" } Commented Mar 18, 2024 at 12:09

1 Answer 1

0

Found the problem, I'd read an article somewhere about including the node_modules folder in the .vscodeignore file. I pulled that out and the extension installs and runs correctly

Sign up to request clarification or add additional context in comments.

3 Comments

That indicates you wasn’t using a tool like webpack to generate optimized artifacts for deployment (bundling everything together). You will need to find good examples of tutorials to learn more.
@LexLi I don't believe that's a correct assumption. The documentation for migrating TO webpack specifically mentions putting node_modules in your .vscodeignore file.
@CollinKlopfenstein I wonder if you read my comment properly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.