Qt Creator 12: C++ Code Model Update

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

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.

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.

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.

Other clangd-related improvements in Qt Creator 12:

  • 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

  • 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.
  • 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).

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

comment-refactorings

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++.
  • More C++ settings are now available in a per-project variant (namely "Documentation Comments" and "File Naming").

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.


Blog Topics:

Comments