This is my C/C++ configs in /home/user/.config/Code/User/settings.json:
"C_Cpp.formatting": "clangFormat",
"C_Cpp.default.intelliSenseMode": "linux-clang-x64",
"C_Cpp.dimInactiveRegions": false,
"C_Cpp.clang_format_path": "/usr/bin/clang-format",
"C_Cpp.clang_format_sortIncludes": true,
"C_Cpp.codeAnalysis.clangTidy.enabled": true,
"C_Cpp.codeAnalysis.clangTidy.path": "/usr/bin/clang-tidy",
"C_Cpp.default.cppStandard": "c++23",
"C_Cpp.default.cStandard": "c17",
"C_Cpp.autocompleteAddParentheses": true,
"C_Cpp.default.compilerPath": "/usr/bin/clang"
Now when i try to save a C++ document, sometimes it takes several seconds to save and sometimes not:

However when i try developing in Rust, this problem does not exist:

How can i fix that problem as it is so annoying?
Also is there a way to see what's happening while saving in vs code so that i can know what is the process that causes this delay?
In vscode, i tried to disable all the extensions that i installed previously, i disabled them one by one, after each disable, i test by changing the code then saving, yet the problem persists, until all the extensions are off.
Then i remembered there are some other built-in extensions. I opened the extensions, then pressed on the three dots at the top right of the left side bar, then i chose Show running extensions, the Running extensions will open and you will find among them git. I noticed that git in unresponsive and had a huge number beside it like 4000+ms which is substantially greater than all the other extensions.
Notice that i am using git version 2.34.1. Also the git extension is ok and responsive during Rust development.
So i updated git to the latest version which is 2.37.1 using these commands:
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git
Now i restarted vscode and the git extension is responsive and working properly. Also the saving is fast and everything in fine.
The problem was due to unresponsive git extension only in C++ development as far as i know. So update git to the latest version.
Update:
I think the problem still exists even after i updated git to the latest version. The delay still only happens with C++ development. The problem is solved once i initialized git in my working directory using git init. When i restart vscode, everything works fine. Here is a screenshot of the Running extensions when the problem exists (Notice the first git extension):

Update:
I think i knew where the problem is. The directory of my C++ project is /home/user/Projects/cpp/testing_1, in cpp/ directory i put all my C++ projects such as testing_1/, testing_2/ and so on. I initialized git in cpp/ dir before which is the parent dir of all my projects. When i deleted that .git dir in cpp/ the git extension in responsive and working fine, even when i am not initializing git in my working project such as testing_1/. I think not initializing git in the parent dir of your project solved the problem. I will see where that goes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With