<AI>
JavaScriptからVS Codeを指定行・指定桁(カラム)で起動するには、
Node.jsの child_process モジュールを使い、
VS Codeのコマンドライン引数 -g (または --goto )に ファイル名:行番号:桁番号 を渡して実行します。
実装方法Node.jsの exec や spawn を利用します。
javascript
const { exec } = require('child_process');
// 例: sample.js の 10行目、5桁目にカーソルを合わせてVS Codeを開く
const filePath = 'sample.js';
const line = 10;
const column = 5;
// -g オプションで file:line:column を指定
exec(`code -g ${filePath}:${line}:${column}`, (error, stdout, stderr) => {
if (error) {
console.error(`エラーが発生しました: ${error.message}`);
return;
}
if (stderr) {
console.error(`標準エラー: ${stderr}`);
return;
}
console.log('VS Codeを起動しました。');
});
注意点
あらかじめVS Codeのコマンド code がシステムの環境変数(PATH)に登録されている必要があります。
桁(カラム)を指定する場合は、行番号の指定が必須となります。
For a quick demonstration of the goto flag syntax in VS Code