This is an example of the most minimal VS Code extension I was able to develop.
It consists of two files in tomashubelbauer.extension
:
index.js
and package.json
.
The tomashubelbauer.extension
subdirectory exists because VS Code has a CLI
switch for configuring a directory from which to run extensions and it treats
subdirectories of this directory as extensions. This directory groups the files
making up the barebones extension.
index.js
is the entry point and the implementation of the extension logic. At
current, it displays the extension name and version number using the VS Code API
window.showInformationMessage
.
package.json
is the required manifest in its most barebones form possible:
name
is requiredversion
is required and must be semver-compatible,0.0.0
workspublisher
is required but can be emptymain
seems to be required, I couldn't get it to default toindex.js
:-(engines/vscode
is required, but at least it will accept>0.0.0
activationEvents
is required, I usedonStartupFinished
but*
works, too
I tried using "type": "module"
in package.json
and ESM syntax in index.js
,
but VS Code does not seem to support that.
I made this for fun. I might actually migrate my extensions to this, though, as
I dislike using code generators (yo code
).
code --extensions-dir ${.}
Replace ${.}
with the path of this repository directory.
To not have testing and developing mess with up your VS Code instance, open up a terminal window in the repository directory and alternate these two commands as needed:
node .
to test/run the codecode .
to open the repository directory in VS Code
I haven't actually published any extension using this method yet. I know it will require tweaking to support publishing, the VS Code Marrketplace has checks in place to make sure extensions contain some metadata VS Code does not enforce.
If I ever do publish an extension using this method, I'll update this to show
how I did it. Most likely the process will require using vsce package
to pack
the extension directory up to a VSIX archive and then vsce publish
to submit
the extension to the VS Code Marketplace.
This also reproduces locally so it might be easier to debug this way. To repro,
run ubuntu
, then cd
to /mnt/…/vscode-barebones-extension
and run node .
(make sure you have a recent version of Node and Code installed). This will show
the temporary directory path as expected, but running /mnt/…/index.log
will
print an empty file. node .
does not seem to run the extension and update the
file.
https://github.com/TomasHubelbauer/code-extension-screencast
Need to figure out how to simplify the extension runner to work with this.