PJCHENder 未整理筆記

[Note] VSCode Debugger

2018-01-17

[Note] VSCode Debugger

@(軟體程式與外掛套件)[vscode]

組態設定

建立組態檔

點選左邊的「蟲蟲」—> 點選「齒輪」 —> 選擇 「Node.js」

Imgur

設定組態檔

1
2
3
4
5
6
7
8
9
10
11
12
13
// launch.json
{
// 如需詳細資訊,請瀏覽: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/bin/www"
}
]
}

常用的設定包含:

  • program - 要執行的檔案或程式
  • args - 要代入在 command line 最後的參數
  • env - environment variables (the value null can be used to “undefined” a variable)
  • cwd - current working directory for finding dependencies and other files
  • port - port when attaching to a running process
  • stopOnEntry - break immediately when the program launches
  • console - what kind of console to use, for example, internalConsole, integratedTerminal, externalTerminal.

可使用的變數包含:

  • ${workspaceFolder} - the path of the folder opened in VS Code
  • ${workspaceFolderBasename} - the name of the folder opened in VS Code without any slashes (/)
  • ${file} - the current opened file
  • ${relativeFile} - the current opened file relative to workspaceFolder
  • ${fileBasename} - the current opened file’s basename
  • ${fileBasenameNoExtension} - the current opened file’s basename with no file extension
  • ${fileDirname} - the current opened file’s dirname
  • ${fileExtname} - the current opened file’s extension
  • ${cwd} - the task runner’s current working directory on startup
  • ${lineNumber} - the current selected line number in the active file

Electron Debugger 設定檔

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Main Process",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
},
"args" : ["."]
}
]
}

Debugging Main Process in VSCode @ Electron

Express Debugger 設定檔

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// launch.json


// 下面這段會執行 node --inspect=46570 --debug-brk bin/www DEBUG=routes,dev:server,model
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "啟動程式",
"args": [ // 要執行的參數
"DEBUG=routes,dev:server,model"
],
"program": "${workspaceRoot}/bin/www" // 要執行的參數
}
]
}

參考

掃描二維條碼,分享此文章