VSCode Macros拡張のマクロでドロップダウンリスト選択を行う方法

この記事は公開から4年以上経過しています。

過去のエントリで紹介したVSCode Macros拡張を使ってドロップダウンリスト(クイックピック)から項目を選択するマクロの作り方を紹介します。


サンプルソースコード

const vscode = require('vscode');

module.exports.macroCommands = {
  単一選択: {
    no: 1,
    func: singleSelectionFunc,
  },
  複数選択: {
    no: 2,
    func: multiSelectionFunc,
  },
};

async function singleSelectionFunc() {
  // 単一選択
  const item = await vscode.window.showQuickPick(['Foo', 'Bar', 'Baz'], { placeHolder: 'Please Select an item', canPickMany: false });
  await vscode.window.showInformationMessage(`Your selection is '${item}'`);
}

async function multiSelectionFunc() {
  // 複数選択
  const items = await vscode.window.showQuickPick(['Foo', 'Bar', 'Baz'], { placeHolder: 'Please Select items', canPickMany: true });
  await vscode.window.showInformationMessage(`Your selections are '${items.join(',')}'`);
}


参考ウェブサイトなど

以上です。

シェアする

  • このエントリーをはてなブックマークに追加

フォローする