microsoft / vscode-cpptools

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

clang-format is not executed in default terminal #12320

Open wobakj opened 1 month ago

wobakj commented 1 month ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary: When a custom default terminal is defined for windows, and clang-format is configured as formatter, it is not executed within the terminal. As a result, custom clang-format executables, which require an extended PATH to find all DLLs, will fail at DLL load.

Until December 2023, this was working, but I could not find anything related in the changelogs.

It is not possible to work around this by using set PATH=...&& in the value of C_Cpp.clang_format_path because it is put into quotes when executed by vscode and thus not recognized as mutliple commands.

Steps to reproduce:

  1. Configure settings.json as below
  2. Open any .h or .cpp file
  3. press F1, activate 'Format Document'
  4. Formatting never finishes because the executable opens an error window (which VSCode does not display) to report a missing DLL

Expected behavior: clang-format is executed in the specified default terminal, enabling custom builds.

Configuration and Logs

"terminal.integrated.profiles.windows": {
        "MinGW Bash": {
            "path": "...\\msys64\\usr\\bin\\bash.exe",
            // ...
            "env": {
                "PATH": "<additional paths for clang-format DLLs>;${env:PATH}"
            }
        }
    },
   "terminal.integrated.defaultProfile.windows": "MinGW Bash",
   "C_Cpp.formatting": "clangFormat"
   "C_Cpp.clang_format_path": "<custom path>\\clang-format.exe",
   "C_Cpp.clang_format_style": "file",
   "[cpp]": {
       "editor.defaultFormatter": "ms-vscode.cpptools",
   },

Other Extensions

Disabled all extensions except for ms-vscode.cpptools

Additional context

No response

sean-mcmanus commented 1 month ago

@wobakj I believe this was caused by a change made to the cwd that is used for child processes.

sean-mcmanus commented 4 weeks ago

I was mistaken by my previous comment. The change I made only affected the cwd of the cpptools-srv process and not clang-format...I don't know what change could have caused a change to clang-format (i.e. I looked and didn't see any).

wobakj commented 2 weeks ago

Too bad. Is there anything I can do help to diagnose the cause?

sean-mcmanus commented 1 week ago

@wobakj Yeah, which version was the last version that worked and the 1st version that stopped working? Can you confirm 1.19.1 (November) was working and 1.19.2 (January) was not working? i.e. see https://github.com/microsoft/vscode-cpptools/releases?page=2 .