0
0

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.

VS codeの拡張機能自作時にTreeItemでcommandに引数を渡す方法

Posted at

はじめに

Jupyter Labの拡張機能で、サイドバーにTOCを追加してくれるjupyterlab-tocという拡張機能があるんですけど、これがすごく便利なんですよね。

  • TOCの項目を自分で設定できる (VScodeのアウトライン機能はごちゃごちゃしすぎです)
  • 項目をクリックすることで移動できる (長いファイルを扱っているときは必須……)

VScodeで探しても同じような拡張機能が見つからなかったので、自分でも作ろうと思いました。

TreeItem

サイドバーにTreeItemを追加するまでは【VSCode】サイドバーランチャー的な拡張機能をつくるで分かったのですが、
項目に関数を設定する段階で困りました。

各Itemに設定できるpropertyの中にはcommandと呼ばれるものがありますが、ここには関数の名前をStringで入れます
そして引数はargumentsに、Arrayの形で渡します
下記のScriptでObjectは

class vsclauncherView {
	data() {
		return [{
            title: "見出し",
            command: "Command",
            arguments: [arg1, arg2],
            chldren : [{
                title: "小見出し"
            }]
        }];
	}

補足

ちなみに、VScodeの拡張機能でエディターの表示を上下に移動させる方法はeditor.revealRange()です。

const editor = vscode.window.activeTextEditor;
const lineInd = listNum || 1;
if (editor) {
    editor.revealRange(new vscode.Range(lineInd, 1, lineInd + 3, 1),
        vscode.TextEditorRevealType.InCenter);
}

Reference

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?