microsoft / vscode-cpptools

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

Unable to specify clang-format file:${workspaceFolder} for multi-root workspace #10752

Closed jlj-ee closed 1 year ago

jlj-ee commented 1 year ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary: Setting clang-format via file:${workspaceFolder} works well per https://github.com/microsoft/vscode-cpptools/issues/9786. However, using the standard multi-root workspace syntax file:${workspaceFolder:someOtherFolder} causes the path to no longer be expanded, e.g. ms-vscode.cpptools-1.14.5-win32-x64/bin/../LLVM/bin/clang-format.exe -style=file:${workspaceFolder:common}/.clang-format

Per the multi-root workspace docs

It is possible to scope a variable per workspace folder by appending the root folder's name to a variable (separated by a colon)

While I can work around this by using the actual relative/absolute path instead of ${workspaceFolder:someOtherFolder}, the multi-root scoping syntax works fine in other places in this extension, e.g. in includePath/browsePath, so it seemed reasonable to expect the syntax to work for specifying clang-format/clang-tidy files as well.

Steps to reproduce:

  1. Create a multi-root workspace with at least two named folders, e.g.
    "folders": [
        {
            "name": "vscode",
            "path": ".."
        },
        {
            "name": "common",
            "path": <some path>
        }
    ]
  2. Set "C_Cpp.clang_format_style" to e.g. file:${workspaceFolder:common}/.clang-format
  3. Attempt to format a file..
  4. Formatting will fail.
  5. Observe that path was not expanded in C/C++ extension output window.

Expected behavior: Path would be expanded to the correct multi-root workspace folder so that formatting completes successfully.

Configuration and Logs

vscode.code-workspace:
{
    "folders": [
        {
            "name": "vscode",
            "path": ".."
        },
        {
            "name": "services",
            "path": "../../../../../services"
        },
        {
            "name": "common",
            "path": "../../../../../common/scripts"
        }
    ],
    "settings": {
        "terminal.integrated.env.windows": {
            "Path": "${config:OCD_path};${config:ARM_GCC_path}/bin;${config:xPack_GCC_path}/bin;${config:Make_path};${env:PATH}",
            "MAXIM_PATH": "${config:MAXIM_PATH}"
        },
        "terminal.integrated.defaultProfile.windows": "Command Prompt",

        "target":"MAX32670",
        "project_name":"${workspaceFolderBasename}",
        "program_file":"${config:project_name}.elf",
        "symbol_file":"${config:program_file}",

        "v_Arm_GCC":"10.3",
        "v_xPack_GCC":"10.2.0-1.2",

        "OCD_path":"${config:MAXIM_PATH}/Tools/OpenOCD",
        "ARM_GCC_path":"${config:MAXIM_PATH}/Tools/GNUTools/${config:v_Arm_GCC}",
        "xPack_GCC_path":"${config:MAXIM_PATH}/Tools/xPack/riscv-none-embed-gcc/${config:v_xPack_GCC}",
        "Make_path":"${config:MAXIM_PATH}/Tools/MSYS2/usr/bin",

        "C_Cpp.default.intelliSenseMode": "gcc-arm",
        "C_Cpp.default.compilerPath": "${config:ARM_GCC_path}/bin/arm-none-eabi-gcc.exe",
        "C_Cpp.default.includePath": [
            "${workspaceFolder:vscode}",
            "${workspaceFolder:vscode}/**",
            "${workspaceFolder:services}/comm/include",
            "${config:MAXIM_PATH}/Libraries/CMSIS/Device/Maxim/${config:target}/Include",
            "${config:MAXIM_PATH}/Libraries/CMSIS/Include",
            "${config:ARM_GCC_path}/arm-none-eabi/include",
            "${config:ARM_GCC_path}/lib/gcc/arm-none-eabi/${config:v_Arm_GCC}/include",
            "${config:MAXIM_PATH}/Libraries/PeriphDrivers/Include/${config:target}",
            "${config:MAXIM_PATH}/Libraries/MiscDrivers/LED",
            "${config:MAXIM_PATH}/Libraries/MiscDrivers/PushButton"
        ],
        "C_Cpp.default.browse.path": [
            "${workspaceFolder:vscode}",
            "${workspaceFolder:services}/comm/source",
            "${config:MAXIM_PATH}/Libraries/PeriphDrivers/Source",
            "${config:MAXIM_PATH}/Libraries/MiscDrivers/LED",
            "${config:MAXIM_PATH}/Libraries/MiscDrivers/PushButton",
            "${config:MAXIM_PATH}/Libraries/MiscDrivers"
        ],
        "C_Cpp.default.defines": [
            "${config:target}"
        ],
        "C_Cpp.autoAddFileAssociations": false,
        "C_Cpp.clang_format_style": "file:${workspaceFolder:common}/.clang-format",
        "C_Cpp.codeAnalysis.clangTidy.path": "file:${workspaceFolder:common}/.clang-tidy"
    }
}

Other Extensions

No response

Additional context

No response

sean-mcmanus commented 1 year ago

@jlj-ee Setting "C_Cpp.codeAnalysis.clangTidy.path": "file:${workspaceFolder:common}/.clang-tidy" is not valid. See https://releases.llvm.org/16.0.0/tools/clang/tools/extra/docs/clang-tidy/ . You'd need to use something like "C_Cpp.codeAnalysis.clangTidy.args": [ "--config-file=${workspaceFolder:common}/.clang-tidy" ].

jlj-ee commented 1 year ago

@sean-mcmanus Thanks for the info! Yes, I see I was mixing up that property, since C_Cpp.codeAnalysis.clangTidy.path is just the path to the binary. But there was a path resolution bug for C_Cpp.clang_format_style?

sean-mcmanus commented 1 year ago

Yeah, the clang_format_style will be fixed for 1.15.2 (pre-release).

sean-mcmanus commented 1 year ago

Fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/v1.15.2 .