简体   繁体   English

VS Code 需要几秒钟才能将文档保存在 C++

[英]VS Code takes several seconds to save a document in C++

This is my C/C++ configs in /home/user/.config/Code/User/settings.json :这是我在/home/user/.config/Code/User/settings.json中的 C/C++ 配置:

  "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:现在,当我尝试保存 C++ 文档时,有时需要几秒钟才能保存,有时则不需要:

在此处输入图像描述

However when i try developing in Rust, this problem does not exist:但是,当我尝试在 Rust 中开发时,不存在此问题:

在此处输入图像描述

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?还有一种方法可以查看在保存 vs 代码时发生了什么,这样我就可以知道导致这种延迟的过程是什么?

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.在vscode中,我尝试禁用我之前安装的所有扩展,我一个一个禁用它们,每次禁用后,我通过更改代码然后保存进行测试,但问题仍然存在,直到所有扩展都关闭。

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.我打开扩展,然后按下左侧栏右上角的三个点,然后我选择Show running extensions ,将打开正在Running extensions的扩展,您会在其中找到 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.我注意到 git 没有响应并且旁边有一个巨大的数字,比如4000+ms ,这比所有其他扩展都大得多。

Notice that i am using git version 2.34.1 .请注意,我使用的是 git 版本2.34.1 Also the git extension is ok and responsive during Rust development.此外,git 扩展在 Rust 开发期间可以正常响应。

So i updated git to the latest version which is 2.37.1 using these commands:因此,我使用以下命令将 git 更新为最新版本2.37.1

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.现在我重新启动 vscode 并且 git 扩展响应并正常工作。 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.据我所知,问题是由于 git 扩展仅在 C++ 开发中无响应造成的。 So update git to the latest version.所以更新git到最新版本。

Update:更新:

I think the problem still exists even after i updated git to the latest version.我认为即使我将 git 更新到最新版本后问题仍然存在。 The delay still only happens with C++ development.延迟仍然只发生在 C++ 开发中。 The problem is solved once i initialized git in my working directory using git init .一旦我使用git init在我的工作目录中初始化 git ,问题就解决了。 When i restart vscode, everything works fine.当我重新启动 vscode 时,一切正常。 Here is a screenshot of the Running extensions when the problem exists (Notice the first git extension):这是存在问题时运行扩展的屏幕截图(注意第一个 git 扩展): 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM