VS Code 中的偵錯
本指南將引導您設定 VS Code,以偵錯 Tauri 應用程式的核心程序。
先決條件
安裝 vscode-lldb
擴充功能。
設定 launch.json
建立一個 .vscode/launch.json
檔案,並將以下 JSON 內容貼到其中
.vscode/launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Tauri Development Debug",
"cargo": {
"args": [
"build",
"--manifest-path=./src-tauri/Cargo.toml",
"--no-default-features"
]
},
// task for the `beforeDevCommand` if used, must be configured in `.vscode/tasks.json`
"preLaunchTask": "ui:dev"
},
{
"type": "lldb",
"request": "launch",
"name": "Tauri Production Debug",
"cargo": {
"args": ["build", "--release", "--manifest-path=./src-tauri/Cargo.toml"]
},
// task for the `beforeBuildCommand` if used, must be configured in `.vscode/tasks.json`
"preLaunchTask": "ui:build"
}
]
}
這會直接使用 cargo
來建置 Rust 應用程式,並在開發和生產模式中載入它。
請注意,它不使用 Tauri CLI,因此不會執行獨有的 CLI 功能。beforeDevCommand
和 beforeBuildCommand
腳本必須事先執行,或在 preLaunchTask
欄位中設定為一個工作。以下是一個範例 .vscode/tasks.json
檔案,其中包含兩個工作,一個是執行開發伺服器的 beforeDevCommand
,另一個是 beforeBuildCommand
.vscode/tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "ui:dev",
"type": "shell",
// `dev` keeps running in the background
// ideally you should also configure a `problemMatcher`
// see https://vscode.dev.org.tw/docs/editor/tasks#_can-a-background-task-be-used-as-a-prelaunchtask-in-launchjson
"isBackground": true,
// change this to your `beforeDevCommand`:
"command": "yarn",
"args": ["dev"]
},
{
"label": "ui:build",
"type": "shell",
// change this to your `beforeBuildCommand`:
"command": "yarn",
"args": ["build"]
}
]
}
現在,您可以在 src-tauri/src/main.rs
或任何其他 Rust 檔案中設定中斷點,並按下 F5
開始除錯。