如何在launch.json中配置vs代码工作目录

Jen*_*ton 5 visual-studio-code

我使用的Goland(同webstorm /的IntelliJ等),IDE和调试配置存在时,你可以配置一个地方working directory现在我试着将工作与VSCODE,我不觉得这配置,有点研究后,我发现下面的JSON的应处置这,但找不到工作目录的正确位置

例如这是我的工作目录

/Users/i022226/go/src/myapp

"configurations": [{
            "name": "Launch Package",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "${workspaceRoot}"
        },
        {
            "name": "Launch Package",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "${workspaceRoot}"
        },
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "remotePath": "",
            "port": 2345,
            "host": "127.0.0.1",
            "program": "${fileDirname}",
            "env": {},
            "args": [],
            "showLog": true
        } 
Run Code Online (Sandbox Code Playgroud)

在“ launch.json添加配置”按钮中,当我键入内容时,cwd我没有任何输入,有任何想法吗?

在这篇文章中cwd是在,option但我找不到option https://github.com/Microsoft/vscode/issues/856

小智 6

你应该像下面这样添加它

    {
        "name": "Launch",
        "type": "go",
        "request": "launch",
        "mode": "debug",
        "cwd": "Your Path",
        "remotePath": "",
        "port": 2345,
        "host": "127.0.0.1",
        "program": "${fileDirname}",
        "env": {},
        "args": [],
        "showLog": true
    }
Run Code Online (Sandbox Code Playgroud)

  • 这并不完全符合我的情况,但关键信息是:密钥是“cwd”,一个有用的变量是“${fileDirname}”...... (4认同)

vah*_*ala 5

以下是launch.json根据Tals 的回答在项目子文件夹中运行 Python 模块的示例:

{
    // 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": [
        {
            "name": "Python: Launch",
            "type": "python",
            "request": "launch",
            "module": "module_source_folder.filename",
            "cwd": "${workspaceFolder}/examples/folder_with_test_files",
            "args": ["-f", "input_filename"]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

请注意,cwd必须在此之前出现,args否则将不起作用。