microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.45k stars 1.53k forks source link

${defaultBuildTask} is not determined when using glob pattern for default task #12638

Open github-day opened 2 weeks ago

github-day commented 2 weeks ago

Environment

Bug Summary and Steps to Reproduce

there are source files .c, .cpp now i want to compile them using with gcc/g++ respectively and i have figured out that according to https://code.visualstudio.com/updates/v1_68#_tasks vscode is able to choose different tasks as default task based on different extend name. and i think the default task should be the value of variable ${defaultBuildTask} in launch.json but not really whether there is an convenient way to let launch.json pick the proper task?

Steps to Reproduce:

  1. open a new workspace
  2. create main1.c and main2.cpp
  3. modify .vscode/launch.json and .vscode/tasks.json as following
  4. now press ctrl+shift+B, the corresponding file will be compiled
  5. but if click the button upper-right image vscode asks me to choose the default build task and configuration files.

Debugger Configurations

./.vscode/tasks.json
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc build active file",
            "command": "/usr/bin/gcc",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/a.out"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": "**.c"
            },
            "detail": "Task generated by Debugger."
        },
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/a.out"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": "**.cpp"
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

in ./.vscode/launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "preLaunchTask": "${defaultBuildTask}",
            "program": "${fileDirname}/a.out",
            "args": ["<","data.in"],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

Debugger Logs

Activating task providers undefined
Activating task providers cppbuild
Activating task providers undefined
Activating task providers undefined
Activating task providers undefined
Activating task providers undefined

Other Extensions

No response

Additional Information

No response

github-day commented 2 weeks ago

here is a workaround by change the keybinding : open keybindings.json(see https://code.visualstudio.com/docs/getstarted/keybindings#_advanced-customization) and add:

[
    {
  "key": "f5",
  "command": "runCommands",
  "args": {
    "commands": [
        "workbench.action.tasks.build",
        "workbench.action.debug.start"
    ]
  }
},
{
    "key": "f5",
    "command": "-workbench.action.debug.start",
    "when": "debuggersAvailable && debugState == 'inactive'"
},
]

if there is a direct way to work out plz let me know