我正在尋找可以幫助我執行以下操作的工具:
鑒于該代碼:
const before = (arg1: string, arg2: string) => null;
我想得到以下結果:
const after = ({ arg1, arg2 }: { arg1: string; arg2: string }) => null;
有可能用一個片段來做到這一點嗎?(例如,我選擇我的 args 并直接轉換它們)
uj5u.com熱心網友回復:
定義以下 Typescript 片段
"Convert Arguments": {
"prefix": "conarg",
"body": [
"{ ${TM_SELECTED_TEXT/(\\w ):[^,]*(,\\s*)?/$1$2/g} }: { ${TM_SELECTED_TEXT/,/;/g}}"
],
"description": "Convert Arguments"
}
- 選擇之間的引數
() - 輸入
conarg并選擇片段
uj5u.com熱心網友回復:
由于我通常需要執行相當大的更改串列,因此我傾向于使用任務(Ctrl Shift P/運行任務/[任務名稱])
https://code.visualstudio.com/docs/editor/tasks
{
"label": "vueconv",
"type": "shell",
"command": "tsx scripts/vueconv ${file}",
"problemMatcher": [],
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "shared",
"showReuseMessage": false,
"clear": true
}
},
我的腳本讀取檔案,進行修復(主要使用string.replace(/regex/g, callback)),并覆寫
我只使用的檔案${file},但如果您還可以添加行號或選擇作為腳本引數
https://code.visualstudio.com/docs/editor/variables-參考
自制的簡單替換庫
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/527230.html
