Skip to content

Getting "command not found" error in my extension despite having the onCommand activation event #48605

@markvincze

Description

@markvincze
  • VSCode Version: 1.22.2
  • OS Version: Win10 64 bit

Steps to Reproduce:

  1. Start VSCode with this extension (either by installing it from the marketplace, or with the debugger) with the Explorer view being hidden.
  2. Create a new file, type some text and select it.
  3. Try to save it as a Code Fragment with the extension by opening the Command Palette and executing the "Save selection as Code Fragment" command

It won't work, the following error will be displayed: command 'codeFragments.saveSelectedCodeFragment' not found.

In my extension I have the following activation events:

    "activationEvents": [
        "onCommand:saveSelectedCodeFragment",
        "onView:codeFragments"
    ],

I expect the first one to prevent this problem, so that it should make sure that the extension is activated when that command is executed.
With some experimentation I noticed that if I also add "*" as an activation event, then the issue goes away. But is that the proper way? I don't necessarily want to load my extension on startup, it'd be enough to be activated the first time this command is executed.
Is this the expected behavior, or a bug?

In either case, I think the documentation should be clarified, because it's unclear whether the onCommand event should be enough in this case or not.

Metadata

Metadata

Assignees

Labels

*dev-questionVS Code Extension Development Question

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions