亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Visial Studio Code 擴展開發中為命令“explorer.newFile”

如何在 Visial Studio Code 擴展開發中為命令“explorer.newFile”

哆啦的時光機 2023-10-20 16:34:02
explorer.newFile如何在 Visual Studio Code 擴展開發中為命令提供參數?我只是想添加在資源管理器視圖中創建一個具有特定名稱的文件,然后打開它并插入一個片段,這些操作將在函數中實現。幫助^_^
查看完整描述

1 回答

?
九州編程

TA貢獻1785條經驗 獲得超4個贊

我當然可能是錯的,但我不確定explorer.newFile是否會爭論。


盡管如此,這個函數將執行您想要的操作:創建一個文件,打開它,然后插入一個現有的代碼片段:


async function createFileOpen() {


  const we = new vscode.WorkspaceEdit();


  const thisWorkspace = await vscode.workspace.workspaceFolders[0].uri.toString();


  // if you want it to be in some folder under the workspaceFolder: append a folder name

  // const uriBase = `${thisWorkspace}/folderName`; 

  // let newUri1 = vscode.Uri.parse(`${uriBase}/index.js`);


  // create a Uri for a file to be created

  const newUri = await vscode.Uri.parse(`${ thisWorkspace }\\myTestIndex.js`);

  

  // create an edit that will create a file

  await we.createFile(newUri, { ignoreIfExists: false, overwrite: true });


  await vscode.workspace.applyEdit(we); // actually apply the edit: in this case file creation


  await vscode.workspace.openTextDocument(newUri).then(

    async document => {      

      await vscode.window.showTextDocument(document);

      // if you are using a predefined snippet

      await vscode.commands.executeCommand('editor.action.insertSnippet', { 'name': 'My Custom Snippet Label Here'});

    });

}


查看完整回答
反對 回復 2023-10-20
  • 1 回答
  • 0 關注
  • 146 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號