VSCode Extension
prequisites
ok
generate a new extension
$ yo code
typeを選ぶ
extension, language support, code snippets, keymap, extension packがある
publisher名を作れと言われ、 personal tokenがいるらしい。
$ npm i -g vsce
$ vsce create-publisher MYPUBLISHER_NAME
ok
ok. .yo-rc.jsonと repositoryができてる。respositoryへ go
repostiryに入る
code: tree -L 1
.
├── CHANGELOG.md
├── node_modules
├── package.json
├── package-lock.json
├── README.md
├── src
├── tsconfig.json
├── tslint.json
└── vsc-extension-quickstart.md
A new instance of VS Code will start in a special mode
Debug: start Debuggingで、extension開発用のdebugモードに入る?
デバッグ用の VSCodeのwindowが立ち上がり、そこで、作成したコマンドを実行できる。
command paletteで、用意してもらった Hello Worldコマンドを実行する。
Congratulations, your extension "sendselectionipython" is now active!
register関数でdisposable型な?インスタンスを作って、subscriptionsにpushしておく。
code: hello_extension.ts
export function activate(context: vscode.ExtensionContext){
console.log('Congra.....');
let disposable = vscode.commands.register('extension.helloworld', () => {
vscode.window.shouwInformationMessage('Hello VSCode');
});
context.subscriptions.push(disposable);
}
contribution points
package.jsonにcontributionsのfieldに入れるもの。 extension manifestに入るもの?
package.jsonを見ると、たしかに入ってる。
自分の使ってるextension をチェックしてみる。 ~/.vscode/extenionsにある
https://gyazo.com/2b5b835f719981560eb38c39ea125a71 #tson 使用 breakpointを設定してdebugした。
Debug画面のVariableを見ると、Closureのところに、vscodeがいる。
activate()関数の引数は、context: vscode.ExtensionContextなんだけど、この contextでのvscodeがきてるイメージ?
これが、APIだと思えば良い?, あとは、ほしいのものをリファレンスすればよいかな。
vscode.window
vscode.commands
executeCommand コマンド名を調べるのは、 command paletteが早いか。
今日はここまで、明日は、ipythonのterminalを作って、そちらにtextを送る
上を参考にする。 ただ、line番号で送ってるので、関数内のものが、pythonのindentエラーになるので、textで送る必要がある。
あとは、currentlineとselection,できれば、もう一つコマンドで関数内で一番scopeが低い関数を評価するみたいなもの。
rstudioの挙動のイメージ。
code: resumed.py
export function activate(context: vscode.ExtensionContext) {
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
let disposable = vscode.commands.registerCommand('extension.sendTextToIPython', () => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
var editor = vscode.window.activeTextEditor;
if(!editor) return
var text = editor.document.getText(editor.selection);
vscode.window.showInformationMessage(text);
});
context.subscriptions.push(disposable);
}
ActivationEventもpackage.jsonで変更しておく。