15

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

Jenny Hilton
  • 1,297
  • 7
  • 21
  • 40
  • 2
    There is a `launch.json` file...there you should be able to set the `cwd` property...(`cwd` stands for `current working directory`) – Hackerman Nov 28 '17 at 20:50
  • @Hackerman - The json that I put in the question is the launch.json ;) , I dont see any `cwd` there, any idea?>] – Jenny Hilton Nov 28 '17 at 20:53
  • There are more options available than are shown on one of the default pre-made tasks. Try typing "cwd" within a task and you will see it prompted. – Mark Nov 28 '17 at 23:04
  • @Mark - Try it without success , I dont find the cwd when I click on add configuration on the launch.json – Jenny Hilton Nov 29 '17 at 07:06

2 Answers2

11

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

{
    "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.

vahlala
  • 355
  • 3
  • 14
9

You should add it like following

    {
        "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
    }
Tals
  • 121
  • 3
  • 5
    This doesn't correspond to my case exactly, but the key informations were: the key is `"cwd"`, and one useful variable is `${fileDirname}`... – Tomasz Gandor Mar 06 '19 at 16:45