Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure vs code working directory in the launch.json

I use goland(same as webstorm/intellij etc) IDE and in debug configuration there is a place when you can configure working directory Now I try to work with VSCODE and I dont find this configuration , after a bit research I find the following json which should handle this but dont find the right place for working directory

e.g. this is my working directory

/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
        } 

In the launch.json there is add configuration button and when I type cwd I dont get any entry, any idea ?

In this post the cwd is under the option but I dont find the option https://github.com/Microsoft/vscode/issues/856

like image 789
Jenny Hilton Avatar asked Nov 28 '17 20:11

Jenny Hilton


People also ask

How do I change the current working directory code in Visual Studio?

To open the Settings editor, use the following VS Code menu command: On Windows/Linux - File > Preferences > Settings. On macOS - Code > Preferences > Settings.

Where is VS Code settings json stored?

Depending on your platform, the user settings file is located here: Windows: %APPDATA%\Code\User\settings. json.


1 Answers

Here's an example launch.json to run a Python module in a project subfolder based on Tals's answer:

{
    // 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"]
        }
    ]
}

Note that cwd must come before args or it won't work.

like image 187
vahlala Avatar answered Oct 04 '22 23:10

vahlala