4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VSCode拡張機能開発メモ

Last updated at Posted at 2020-05-17

はじめに

アルバイトの改修案件で version3 の Riot.js を使っているのですが、.tagファイル内のjsをショートカットキーでコメントアウトしようとしても、うまくコメントアウトできないのが不便だったので、拡張機能を自作しました。

全体の流れ等は、すでに記事が散見されたので、その記事を見ても詰まったところを列挙していきたいと思います。

gasでの開発と似たような感じがありましたが、固定されているセルがないので難しく感じました。
かかった期間は半日です。

レポジトリ
https://github.com/wafuwafu13/riot-commentout

参考記事、リファレンス

開発

公開

開発で詰まったところ

コードをデバッグしたい

console.log で吐き出し、拡張機能を開発している方の画面の DEBUG CONSOLE をみる
スクリーンショット 2020-05-17 15.58.21.png

「cmd+shift+p」で出てくる選択肢に自分の拡張機能がない

package.jsontitle を変えないといけない

package.json
"contributes": {
		"commands": [
			{
				"command": "riot-comment.riot-commentout",
				"title": "riot-commentout"  // 変える
			}
		]
},

ショートカットキーを設定したい

package.json で 以下のように keybindings を設定

package.json
"contributes": {
		"keybindings": [
			{
				"command": "riot-comment.riot-commentout",
				"key": "cmd+c"
			}
		]
},

editor.edit内の処理が一回しか実行されない

editor.editの処理は非同期で行われるようなので、以下のコードでは1行しかコメントアウトできなかった。(デバッグしたら同期的だったので本当はよくわからない)

for (let i = start; i <= end; i++) {
	editor.edit((edit: any) => {
		let position = new vscode.Position(i, 0);
		edit.insert(position, '// ');
	});
}

async/await を使って解決する

async function main(){

        ......

        for (let i = start; i <= end; i++) {
            let start_position: vscode.Position = new vscode.Position(i, space);
					
            await editor.edit((edit: string | any) => {
                   edit.insert(start_position, '// ');
            });
     }
				
}

main();

公開で詰まったところ

アクセストークンをどこから入手すれば良いか分からない

公式をみる
Get a Personal Access Token

vsce create-publisher で401エラー

Common questions

アクセストークンの Scopes を Full access にする
スクリーンショット 2020-05-17 17.32.49.png

vsce publish で Error, WARNING がでる

Error: Make sure to edit the README.md file before you publish your extension.

このエラーはReadMeを書き換えれば解決
https://github.com/Microsoft/vscode/issues/14730 

WARNING  A 'repository' field is missing from the 'package.json' manifest file.

このエラーは package.jsonrepository を編集すれば解決
https://stackoverflow.com/questions/16827858/npm-warn-package-json-no-repository-field

Marketplace の Readme が更新されない

1回目の vuce publish で下記のURLが生成された

Readmeを更新して再度 vuce publish をしても更新されていない

3回目の vuce publish で下記のエラー

 ERROR  hirotakatagawa.riot-commentout@0.0.1 already exists. Version number cannot be the same.

package.jsonversion を変更して vuce publish したら解決

4
3
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
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?