Skip to content

Formatter incorrectly formats (applies diff of) correct raw clang-format output #6205

@mkurdej

Description

@mkurdej

Type: LanguageService

Describe the bug

  • OS and Version: Windows 10 2004
  • VS Code Version: 1.49.1
  • C/C++ Extension Version: 1.0.1
  • Other extensions you installed (and if the issue persists after disabling them): not relevant
  • Does this issue involve using SSH remote to run the extension on a remote machine?: No
  • A clear and concise description of what the bug is, including information about the workspace (i.e. is the workspace a single project or multiple projects, size of the project, etc).

Formatting C++ code:

#include <array>
#include <array>
#include <vector>
#include <vector>

(and newline at the end of file is important, otherwise the issue disappears if the file ends just after <vector>)

I get the correct (raw) output from clang-format (also did it in the command line and it is the same there):

#include <array>
#include <vector>

But VSCode applies the diff strangely breaking the code and resulting in:

#include <array>
#include <#include <vector>

Steps to reproduce

  1. Copy-paste the first of the above snippets
  2. Execute "Format Document"
  3. See error

Expected behavior

The formatted text should be equal to the raw clang-format output:

#include <array>
#include <vector>

Logs
cpptools/formatDocument: file:///d%3A/src/bugs/llvm/pr47634/bug-47634-clang-format.cpp (id: 875)
Formatting input:
#include <array>
#include <array>
#include <vector>
#include <vector>

Formatting document: file:///d%3A/src/bugs/llvm/pr47634/bug-47634-clang-format.cpp
Formatting Engine: clangFormat
Formatting raw output:
#include <array>
#include <vector>

Formatting diffed output:

textDocument/didChange: file:///d%3A/src/bugs/llvm/pr47634/bug-47634-clang-format.cpp
cpptools/textEditorSelectionChange
cpptools/getFoldingRanges: file:///d%3A/src/bugs/llvm/pr47634/bug-47634-clang-format.cpp (id: 876)
cpptools/getSemanticTokens: file:///d%3A/src/bugs/llvm/pr47634/bug-47634-clang-format.cpp (id: 877)
Checking for syntax errors: file:///d%3A/src/bugs/llvm/pr47634/bug-47634-clang-format.cpp
Queueing IntelliSense update for files in translation unit of: D:\SRC\BUGS\LLVM\PR47634\BUG-47634-CLANG-FORMAT.CPP
  tag parsing file: D:\SRC\BUGS\LLVM\PR47634\BUG-47634-CLANG-FORMAT.CPP
sending 1 changes to server
cpptools/finishUpdateSquiggles
-------- Diagnostics - 24/09/2020 à 10:43:26
Version: 1.0.1
Current Configuration:
{
    "name": "Win32",
    "includePath": [
        "${workspaceFolder}/**"
    ],
    "defines": [
        "_DEBUG",
        "UNICODE",
        "_UNICODE"
    ],
    "windowsSdkVersion": "10.0.18362.0",
    "compilerPath": "D:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.28.29304/bin/Hostx64/x64/cl.exe",
    "cStandard": "c11",
    "cppStandard": "c++17",
    "intelliSenseMode": "msvc-x64",
    "compilerArgs": [],
    "browse": {
        "path": [
            "${workspaceFolder}/**"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Translation Unit Mappings:
[ D:\src\bugs\llvm\pr47634\bug-47634-clang-format.cpp ]:
    D:\SRC\BUGS\LLVM\PR47634\BUG-47634-CLANG-FORMAT.CPP
Translation Unit Configurations:
[ D:\src\bugs\llvm\pr47634\bug-47634-clang-format.cpp ]:
    Process ID: 4216
    Memory Usage: 59 MB
    Compiler Path: D:/Program Files (x86)/Microsoft Visual Studio/2019/Preview/VC/Tools/MSVC/14.28.29304/bin/Hostx64/x64/cl.exe
    Includes:
        D:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\PREVIEW\VC\TOOLS\MSVC\14.28.29304\INCLUDE
        D:\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UM
        D:\WINDOWS KITS\10\INCLUDE\10.0.18362.0\UCRT
        D:\WINDOWS KITS\10\INCLUDE\10.0.18362.0\SHARED
        D:\WINDOWS KITS\10\INCLUDE\10.0.18362.0\WINRT
        D:\WINDOWS KITS\10\INCLUDE\10.0.18362.0\CPPWINRT
    Defines:
        _DEBUG
        UNICODE
        _UNICODE
    Standard Version: ms_c++17
    IntelliSense Mode: msvc-x64
Total Memory Usage: 59 MB

------- Workspace parsing diagnostics -------
Number of folders and files enumerated: 4785
Number of files discovered (not excluded): 4764

Screenshots
image

Additional context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions