Qt Creator 12:C++代码模型更新

Qt Creator 12: C++ Code Model Update

Qt Creator 12:C++代码模型更新

November 24, 2023 by Christian Kandeler | Comments

​2023年11月24日:Christian Kandeler |评论

In our previous instance of this column, we introduced our then-brand new clangd support, so let's start with what has happened in that area since then.

​在本专栏的前一个例子中,我们介绍了当时全新的clangd支持,所以让我们从那以后在该领域发生的事情开始。

Clangd

In Qt Creator 7, clangd became the default back-end of the clang code model, and in Qt Creator 8, the original libclang-based back-end was removed.

在QtCreator 7中,clangd成为clang代码模型的默认后端,而在QtCCreator 8中,原始的基于libclang的后端被删除。

When we started this endeavor, clangd lacked a number of capabilities that we needed for our feature set. In order not to lose any important features, we added temporary client-side workarounds, while also trying to get things fixed upstream. Some of these workarounds were rather expensive computing-wise; in particular, semantic highlighting slowed down noticeably, as we had to retrieve the document's AST from clangd and poke around in it to extract the information we needed for features such as the visualization of angle brackets in templates.

当我们开始这项工作时,clangd缺乏我们的功能集所需的一些功能。为了不丢失任何重要功能,我们添加了临时的客户端解决方案,同时也试图在上游解决问题。其中一些变通方法在计算方面相当昂贵;特别是,语义高亮显示明显放缓,因为我们必须从clangd中检索文档的AST,并在其中四处查找,以提取我们所需的信息,以实现模板中尖括号的可视化等功能。

However, we have now successfully upstreamed all the relevant features, so that when using a current clangd, we don't need to employ our workarounds anymore, resulting among other things in a major speed-up in semantic highlighting. For this reason, we strongly recommend switching to  clangd 17, if you haven't done so already. This version is also shipped with Qt Creator 12, so if you use our installer, you don't have to do anything (assuming you never tinkered with the settings). Otherwise, if your host OS has not yet upgraded to LLVM 17, you can get stand-alone clangd binaries here. We will soon drop support for older clangd versions altogether.

​然而,我们现在已经成功地升级了所有相关的功能,因此在使用当前的clangd时,我们不需要再使用我们的解决方案,从而大大加快了语义突出显示的速度。因此,如果您还没有切换到clangd 17,我们强烈建议您切换到clang 17。这个版本还附带了Qt Creator 12,所以如果你使用我们的安装程序,你不必做任何事情(假设你从未修改过设置)。否则,如果您的主机操作系统尚未升级到LLVM 17,则可以在此处获得独立的clangd二进制文件。我们很快将完全放弃对旧clangd版本的支持。

Other clangd-related improvements in Qt Creator 12:

Qt Creator 12中其他与clangd相关的改进:

  • Changes in header files take effect immediately, not just after saving the file.
  • 头文件中的更改将立即生效,而不仅仅是在保存文件之后。
  • We have identified and fixed some scenarios in which the symbol index was getting out of sync.
  • 我们已经确定并修复了一些符号索引不同步的情况。
  • Users can now choose between completion engines.
  • 用户现在可以在完成引擎之间进行选择。

Refactoring Goodies

重构Goodies

  • Symbol renaming now also considers the content of comments.
  • 符号重命名现在还考虑注释的内容。
  • Function documentation can be moved from declaration to implementation and vice versa.
  • 函数文档可以从声明转移到实现,反之亦然。
  • Comment blocks can be switched from C to C++ style and vice versa.
  • 注释块可以从C风格切换到C++风格,反之亦然。
  • Users can fold and unfold all comment blocks in a file at once.
  • 用户可以一次折叠和展开文件中的所有注释块。
  • Code inserted by quickfixes now gets auto-formatted (if ClangFormat is enabled and set up for full formatting).
  • 通过快速修复插入的代码现在会自动格式化(如果ClangFormat已启用并设置为完全格式化)。

As the above list indicates, we have put quite some effort into features related to comments. The video below shows them in action.

正如上面的列表所示,我们已经在与评论相关的功能上投入了相当多的精力。下面的视频展示了他们的行动。

Other Code Model Improvements

其他代码模型改进

  • We have restructured the editor context menu so that related actions are now grouped together. Also, the context menu is now in sync with the one in Tools -> C++.
  • 我们已经重新构造了编辑器上下文菜单,以便将相关操作分组在一起。此外,上下文菜单现在与Tools->C++中的菜单同步。
  • More C++ settings are now available in a per-project variant (namely "Documentation Comments" and "File Naming").
  • 现在,在每个项目的变体中可以使用更多的C++设置(即“文档注释”和“文件命名”)。

Coming next

下一个

We are currently looking into utilizing clangd's "tweaks" infrastructure to enhance our refactoring features. We have already added the ability to convert an unscoped into a scoped enum (available with clangd 18), and we are planning to base our "create function definition" quickfix on clangd in the future, in order to get more reliable results in more complex scenarios.

我们目前正在研究利用clangd的“调整”基础设施来增强我们的重构功能。我们已经添加了将非作用域枚举转换为作用域枚举的功能(可与clangd 18一起使用),并且我们计划在未来基于clangd进行“创建函数定义”快速修复,以便在更复杂的场景中获得更可靠的结果。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值