调试器启动的进程无法触发VS Code「跳转到源代码」功能
问题描述
当通过调试器启动Rust或Go程序时,该程序通过spawn调用Code.exe无法触发VS Code的「跳转到源代码」功能,但直接在CMD中运行该程序则可正常触发。
VS Code版本信息
- VS Code版本:1.103.2(用户安装版)
- Commit哈希:6f17636121051a53c88d3e605c491d22af2ba755
- 发布日期:2025-08-20T16:45:34.255Z
- Electron版本:37.2.3
- Electron构建ID:12035395
- Chromium版本:138.0.7204.100
- Node.js版本:22.17.0
- V8引擎版本:13.8.500258-electron.0
- 操作系统:Windows_NT x64 10.0.19045
复现步骤
Rust程序示例
use std::env; use std::process::Command; fn main() { let args: Vec<String> = env::args().collect(); if args.len() < 2 { println!("Usage: {} <file_path> [additional args...]", args[0]); return; } let vsc_exe = "D:\\Program Files\\Microsoft VS Code\\Code.exe"; let output = Command::new(vsc_exe).args(&args[1..]).output(); match output { Ok(_) => println!("Successfully launched VS Code with provided args"), Err(e) => println!("Launch failed: {}", e), } }
对应的launch.json配置:
{ "version": "0.2.0", "configurations": [ { "name": "vsc_process", "type": "cppvsdbg", "request": "launch", "program": "${workspaceFolder}/target/debug/vsc_process.exe", "args": ["${workspaceFolder}/.vscode/launch.json"], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "console": "integratedTerminal" } ] }
Go程序示例
package main import ( "fmt" "os" "os/exec" ) func main() { args := os.Args if len(args) < 2 { fmt.Printf("Usage: %s <file_path> [additional args...]\n", args[0]); return; } vscExe := "D:\\Program Files\\Microsoft VS Code\\Code.exe"; cmd := exec.Command(vscExe, args[1:]...); err := cmd.Run(); if err != nil { fmt.Printf("Launch failed: %v\n", err); } else { fmt.Println("Successfully launched VS Code with provided args"); } }
对应的launch.json配置:
{ "version": "0.2.0", "configurations": [ { "name": "Launch Package", "type": "go", "request": "launch", "mode": "auto", "program": "${workspaceFolder}/main.go", "args": ["${workspaceFolder}/.vscode/launch.json"], } ] }
补充信息
该场景用于Unreal引擎的源码跳转功能,对应代码位于UnrealEngine仓库中VisualStudioCodeSourceCodeAccessor.cpp文件的第236行。已参考相关问题讨论,尝试设置环境变量ELECTRON_RUN_AS_NODE为0或1均无效,甚至会阻止VS Code启动。判断这是VS Code的Bug而非配置问题。
内容的提问来源于stack exchange,提问作者wicast
相关产品推荐
相关产品推荐

