21

Is it possible to invoke a VSCode extension command from a terminal?

I'm aware of the code command and all the switches under the Extensions Management category. However, I do not understand if it's possible to invoke a command implemented within a VSCode extension from the command line or it is required that a user must invoke it from the editor's context?

I cannot seem to find a definitive answer after Googling and searching StackOverflow, so I'm asking as a new question. Any insights?

jayarjo
  • 16,124
  • 24
  • 94
  • 138
ariestav
  • 2,799
  • 4
  • 28
  • 56
  • I don't think that's possible.. What are you trying to do exactly? Seems like most commands wouldn't make sense to be invoked that way. – Gama11 Jan 28 '19 at 20:25
  • The extension I'm using allows me to obfuscate the code as an export function. The obfuscation method is not open source, unfortunately, and so to do it the proprietary way requires the extension. For a build process, I thought I might be able to do it. Maybe not? – ariestav Jan 29 '19 at 14:07
  • 1
    Hm.. well, VSCode extensions necessarily need to ship with their sources. Couldn't you just dig into them and see what it calls when it does the obfuscation, and then use that directly? ;) – Gama11 Jan 29 '19 at 14:16
  • Good call. I'll take a look and see. Many thanks. – ariestav Jan 29 '19 at 14:17
  • Did you find a way to invoke extensions commands from the terminal in the end? I have another use case. – jayarjo Feb 06 '19 at 04:24
  • 1
    The vendor software installed a separate, external NodeJS script that accomplished it. I think the extension runs that script when its mapped keyboard shortcut is invoked. So it was possible to just call the script in a shell directly. – ariestav Feb 19 '19 at 14:11

1 Answers1

4

Ugly workaround I can use - https://marketplace.visualstudio.com/items?itemName=gabrielgrinberg.auto-run-command

write config file and start vscode (which should trigger that task, check if file exists, run commands) and close vscode

Sad, that there is no better solution for a while

Vasiliy vvscode Vanchuk
  • 7,007
  • 2
  • 21
  • 44