microsoft / microsoft/vscode-cpptools

Remove behavior where `compilerPath` overrides `compile_commands.json` entries, in favor of using an additional setting.

Open
#11,889 24 comments 0 reactions 1 assignee View on GitHub

@Colengms is already working on this.

Since Feb 13, 2024.

configuration revision enhancement Feature: Compile Commands Feature: Configuration Language Service
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Environment
  • OS and Version: Windows 10 22H2
  • VS Code Version: 1.85.2
  • C/C++ Extension Version: 1.18.5
Bug Summary and Steps to Reproduce

Bug Summary:

If both "compilerPath" and "compileCommands" are present in "c_cpp_properties.json", the former seems to take precedence during IntelliSense analysis. This results in the command line of the file present in compile_commands.json (e.g. -mcpu) to be ignored, leading to missing defines. Removing "compilerPath" results in the command line from compile_commands.json being taken into the account.

This behaviour goes directly against what c_cpp_properties.json reference documents:

If there is a matching entry in compile_commands.json for a file open in the editor, that command line will be used to configure IntelliSense for that file, instead of the other fields of c_cpp_properties.json.

Additionally, the intended behaviour (compile_commands.json overriding other options) was mentioned yesterday in another issue: https://github.com/microsoft/vscode-cpptools/issues/11880#issuecomment-1901003596.

Defining "compilerPath": "", works as a workaround.

Observed behaviour:

"compilerPath" takes precedence over "compileCommands" for populating system/architecture specific defines.

Expected behaviour:

"compileCommands" takes precedence over "compilerPath" for populating system/architecture specific defines.

Configuration and Logs
c_cpp_properties.json
{
    "configurations": [
        {
            "name": "main",
            "intelliSenseMode": "gcc-arm",
            "compilerPath": "H:/dev/flipper-zero/.ufbt/toolchain/x86_64-windows/bin/arm-none-eabi-gcc.EXE", // This causes issues
            "compileCommands": "${workspaceFolder}/.vscode/compile_commands.json",
            "configurationProvider": "ms-vscode.cpptools",
            "cStandard": "gnu17",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}
Language server logs ("compilerPath" absent)
Querying compiler's default target using command line: "H:\dev\flipper-zero\.ufbt\toolchain\x86_64-windows\bin\arm-none-eabi-gcc.EXE" -dumpmachine
Compiler returned default target value: arm-none-eabi
Compiler query command line: H:\dev\flipper-zero\.ufbt\toolchain\x86_64-windows\bin\arm-none-eabi-gcc.EXE -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -Wall -Wextra -Wno-address-of-packed-member -Wredundant-decls -Wdouble-promotion -fdata-sections -ffunction-sections -fsingle-precision-constant -fno-math-errno -g -Os -mword-relocations -mlong-calls -fno-common -nostdlib -std=gnu17 -Wp,-v -E -dM -x c nul
Attempting to get defaults from C compiler in compile_commands.json file: 'H:\dev\flipper-zero\.ufbt\toolchain\x86_64-windows\bin\arm-none-eabi-gcc.EXE'
Querying compiler for default C++ language standard using command line: H:\dev\flipper-zero\.ufbt\toolchain\x86_64-windows\bin\arm-none-eabi-g++.EXE -x c++ -E -dM nul
Language server logs ("compilerPath" present)
Querying compiler's default target using command line: "H:/dev/flipper-zero/.ufbt/toolchain/x86_64-windows/bin/arm-none-eabi-gcc.EXE" -dumpmachine
Compiler returned default target value: arm-none-eabi
Compiler query command line: H:/dev/flipper-zero/.ufbt/toolchain/x86_64-windows/bin/arm-none-eabi-gcc.EXE -std=c++17 -Wp,-v -E -dM -x c++ nul
Attempting to get defaults from C++ compiler in "compilerPath" property: 'H:/dev/flipper-zero/.ufbt/toolchain/x86_64-windows/bin/arm-none-eabi-gcc.EXE'
Compiler query command line: H:/dev/flipper-zero/.ufbt/toolchain/x86_64-windows/bin/arm-none-eabi-gcc.EXE -std=gnu17 -Wp,-v -E -dM -x c nul
LSP: Message ignored due to no registered handler: $/setTrace
Other Extensions

No response

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.