Repository navigation
Closed
Closed
Copy link
Labels
Feature: Code FormattingLanguage ServicebugfixedCheck the Milestone for the release in which the fix is or will be available.Check the Milestone for the release in which the fix is or will be available.
Milestone
Description
Environment
- OS and Version: Windows 11 23H2
- VS Code Version: 1.92.2
- C/C++ Extension Version: v1.21.6
- If using SSH remote, specify OS of remote machine: wsl (Ubuntu 20.04)
Bug Summary and Steps to Reproduce
Bug Summary:
I am not using any VS code settings overrides for the C_Cpp.clang_format. options. I have a .clang-format with the following content:
BasedOnStyle: Chromium
InsertNewlineAtEOF: trueThe C file src/main.c contents are:
#include <stdio.h>
/**
* @brief Some info
*
* @param argc - The main `arg`
* @param argv - The not main arg
* @return int
*/
int main(int argc, char const* argv[]) {
int a, b;
printf("Foo mains\n");
return 0;
}If using the Format Document command from within VS Code it does not add a new line at EOF (End Of File). However, if I invoke the clang-format command from a terminal, it does add a new line at EOF:
> clang-format -i src/main.cSteps to reproduce:
- Copy & paste the above files and test it via the VS code command
Format Document.
Expected behavior:
It should format the file and add a new line at EOF.
Configuration and Logs
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c99",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64",
"configurationProvider": "ms-vscode.cmake-tools"
},
{
"name": "CMake",
"compileCommands": "${config:cmake.buildDirectory}/compile_commands.json",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}-------- Diagnostics - 9/4/2024, 1:10:29 PM
Version: 1.21.6
Current Configuration:
{
"name": "Linux",
"includePath": [
"/home/tobias/code/c-test/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c99",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64",
"configurationProvider": "ms-vscode.cmake-tools",
"compilerPathIsExplicit": true,
"cStandardIsExplicit": true,
"cppStandardIsExplicit": true,
"intelliSenseModeIsExplicit": true,
"compilerPathInCppPropertiesJson": "/usr/bin/gcc",
"configurationProviderInCppPropertiesJson": "ms-vscode.cmake-tools",
"mergeConfigurations": false,
"browse": {
"path": [
"/home/tobias/code/c-test/**",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
}
}
Custom browse configuration:
{
"browsePath": [
"/home/tobias/code/c-test/src"
],
"compilerPath": "/usr/bin/gcc",
"compilerArgs": [],
"compilerFragments": [
"-g"
]
}
cpptools version (native): 1.21.6.0
Translation Unit Mappings:
[ /home/tobias/code/c-test/src/main.c - source TU]:
Translation Unit Configurations:
[ /home/tobias/code/c-test/src/main.c ]:
Process ID: 30660
Memory Usage: 15 MB
Compiler Path: /usr/bin/gcc
Includes:
System Includes:
/usr/lib/gcc/x86_64-linux-gnu/9/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
Standard Version: c17
IntelliSense Mode: linux-gcc-x64
Other Flags:
--gcc
--gnu_version=90400
Total Memory Usage: 15 MB
------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 4908
LSP: (received) cpptools/didChangeActiveEditor: file:///home/tobias/code/c-test/src/main.c
LSP: (invoked) cpptools/didChangeActiveEditor: file:///home/tobias/code/c-test/src/main.c
LSP: (received) cpptools/formatDocument: file:///home/tobias/code/c-test/src/main.c (id: 161)
LSP: (invoked) cpptools/formatDocument: file:///home/tobias/code/c-test/src/main.c (id: 161)
Formatting document: file:///home/tobias/code/c-test/src/main.c
Formatting Engine: clangFormat
/home/tobias/.vscode-server/extensions/ms-vscode.cpptools-1.21.6-linux-x64/bin/../LLVM/bin/clang-format -style=file -fallback-style=LLVM --Wno-error=unknown -assume-filename=/home/tobias/code/c-test/src/main.c
LSP: Sending response (id: 161)
LSP: (received) textDocument/willSaveWaitUntil: file:///home/tobias/code/c-test/src/main.c (id: 162)
LSP: (invoked) textDocument/willSaveWaitUntil: file:///home/tobias/code/c-test/src/main.c (id: 162)
LSP: Sending response (id: 162)
willSaveWaitUntil: 0ms
LSP: (received) textDocument/didSave: file:///home/tobias/code/c-test/src/main.c
LSP: (invoked) textDocument/didSave: file:///home/tobias/code/c-test/src/main.c
Intellisense update pending for: file:///home/tobias/code/c-test/src/main.c
tag parsing file: /home/tobias/code/c-test/src/main.c
LSP: (received) cpptools/fileChanged: file:///home/tobias/code/c-test/src/main.c
LSP: (invoked) cpptools/fileChanged: file:///home/tobias/code/c-test/src/main.c
IntelliSense update scheduled and TU acquisition started for: file:///home/tobias/code/c-test/src/main.c
Update IntelliSense time (sec): 0.006
LSP: (received) cpptools/getFoldingRanges: file:///home/tobias/code/c-test/src/main.c (id: 163)
LSP: (invoked) cpptools/getFoldingRanges: file:///home/tobias/code/c-test/src/main.c (id: 163)
LSP: Sending response (id: 163)
LSP: (received) cpptools/getDocumentSymbols: file:///home/tobias/code/c-test/src/main.c (id: 164)
LSP: (invoked) cpptools/getDocumentSymbols: file:///home/tobias/code/c-test/src/main.c (id: 164)
LSP: Sending response (id: 164)
Database safe to open.
LSP: (received) cpptools/didChangeActiveEditor: file:///home/tobias/code/c-test/src/main.c
LSP: (invoked) cpptools/didChangeActiveEditor: file:///home/tobias/code/c-test/src/main.c
LSP: (received) cpptools/didChangeTextEditorSelection
LSP: (invoked) cpptools/didChangeTextEditorSelection
LSP: (received) cpptools/getCodeActions: file:///home/tobias/code/c-test/src/main.c (id: 165)
LSP: (invoked) cpptools/getCodeActions: file:///home/tobias/code/c-test/src/main.c (id: 165)
LSP: Sending response (id: 165)
Other Extensions
No response
Additional context
No response
Reacted by Tobias Hernstig
Metadata
Metadata
Assignees
Labels
Feature: Code FormattingLanguage ServicebugfixedCheck the Milestone for the release in which the fix is or will be available.Check the Milestone for the release in which the fix is or will be available.
Type
Projects
- StatusShow more project fieldsDone
Activity
thernstig commentedon Oct 26, 2024
Adding rationale why this is good:
Ending files with a new line is a POSIX standard: https://stackoverflow.com/a/729795/1853417
(Sean McManus (@sean-mcmanus) we are having some larger issues with our developers pushing code reviews where the newline at EOF
InsertNewlineAtEOF: trueis not respected, so verification fail in CI.)14 remaining items
sean-mcmanus commentedon Aug 29, 2026
Tobias Hernstig (@thernstig) Fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/v1.34.1 (pre-release).
thernstig commentedon Sep 10, 2026
Sean McManus (@sean-mcmanus) great, but I moved over to using Rust 😆 Things were/are too slow in the C/C++ ecosystem for me.