0
0

More than 3 years have passed since last update.

ジェネレーターに頼らずVSCodeの拡張作ってみる

Last updated at Posted at 2020-07-22

2020/07/23更新1

初めに

Node.jsがDL出来ない特殊環境でもVSCodeの拡張を作りたいというニッチ(というか私だけ)のためにまずは自宅環境でジェネレーターで作ったhelloworldをもとに手動で作ってみる。

まだ本番環境では試せてない かつ
一応この手順で本番環境でもインストールできた。
ただ、中身は理解しないまま進んでいるため、試してみようって方は自己責任で

構成

root
├extension
│├src
││└extension.js
│└package.json
└extension.vsixmanifest

この構成でzipに圧縮。拡張子vsixに変更して、[VSIXからのインストール]でインストール

package.json

{
    "name": "helloworld",
    "version": "0.0.1",
    "engines": {
        "vscode": "^1.22.0"
    },
    "activationEvents": [
        "onCommand:helloworld.helloWorld"
    ],
    "main": "./src/extension.js",
    "contributes": {
        "commands": [
            {
                "command": "helloworld.helloWorld",
                "title": "Hello World"
            }
        ]
    },
    "publisher": "test"
}

extension.js

const vscode = require('vscode');

/**
    @param {vscode.ExtensionContext} context
*/
function activate(context) {
    let disposable = vscode.commands.registerCommand('helloworld.helloWorld',
        function () {
            vscode.window.showInformationMessage('Hello!!!');
        }
    );

    context.subscriptions.push(disposable);
}

exports.activate = activate;

extension.vsixmanifest

<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
  <Metadata>
    <Identity Language="JP" Id="helloworld" Version="0.0.1" Publisher="testtest"/>
    <DisplayName>helloworld</DisplayName>
  </Metadata>
  <Installation>
    <InstallationTarget Id="Microsoft.VisualStudio.Code"/>
  </Installation>
  <Dependencies/>
  <Assets>
    <Asset Type="Microsoft.VisualStudio.Code.Manifest" Path="extension/package.json" Addressable="true" />
  </Assets>
</PackageManifest>

まとめ

これで、Node.jsがDL出来ない特殊環境でもVSCodeの拡張を作れるようになったので、車輪の再開発を辞さなければ特殊環境でも拡張の恩恵を得られるようになった。


  1. 3回目 

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0