
CLion 2019.1: ClangFormat, code highlighting through Clangd, memory view, initial support for microcontrollers
Hello, Habr!
The CLion team has a lot of great news - the St. Petersburg part of the team, together with other colleagues, successfully moved to a new office, new cool developers joined us, and most importantly, just the other day, we released the first big update this year, CLion 2019.1 !
Work in the new version went on several fronts at once:

Read more about these and other innovations below. And to try new features and improvements, download the free 30-day version of CLion from our website .
As you already know, in CLion there are two tools for supporting the C ++ language - one completely its own, and the second based on Clangd. They work together, complementing each other and sharing the necessary information. At the same time, if performance and the criterion of functional completeness allow, we are now trying to transfer smart tools for working with C ++ code in CLion to a Clangd-based tool. We are not talking about code refactoring yet, but the highlighting of the code in 2019.1 is already done on the basis of Clangd. This significantly improved the responsiveness of the editor.
A few releases back, we switched CLion to a Clangd-based tool when displaying errors in the editor. Now the error text is shown in more detail. This is useful, for example, when debugging errors related to function overloading:

Added to this is the ability to calculate the position of a possible fix (quick-fix) also through Clangd. The fix itself is provided directly by CLion's own tool.
Another interesting area of our work is writing new checks on the Clangd code parsing tool. Starting with CLion 2019.1, a new check for C ++ code will tell you when a member function of a class can be declared static:

By the way, managing the settings of this alternative tool on Clangd can be found in Settings / Preferences | Languages & Frameworks | C / C ++ | Clangd.
Editor productivity is one of our top priorities. In addition to many small improvements, in this release it is worth noting a significant improvement in the initial indexing time of the project. It does not always happen, but in cases where you use the same libraries for your projects: then CLion can automatically notice this and reuse the symbols for these libraries for a new open project that uses them. When it comes to STL or Boost, the improvements are very noticeable!
Our plans for this year are to increase the accuracy and accuracy of our refactoring for C ++. We started with the two most basic ones - Rename and Extract. For Extract, we fixed many cases where the refactoring result turned out to be incorrect due to incorrectly considered namespace qualifiers (for example
In relation to Rename, we paid attention to the case when there is a renaming of a class or structure that matches the name of the file in which they are located. Previously, we always renamed the file too, but now CLion asks you about the preferred outcome during refactoring. You can rename, or you can leave the old file name. The reverse also works - renaming the file does not lead to unconditional renaming of the class. (Somewhere here there should be screams from the audience: “Finally!”)

And, by the way, a little later I’ll talk about the possibility of setting header guards styles. So, if the header guard used in the file follows the specified style template and at the same time the name of the renamed file is in its name, then CLion will also update the header guard!
In version 2019.1, we added the ability to switch to ClangFormat to format code in CLion. This includes not only the formatting action itself (
You can switch to ClangFormat globally - in the Settings / Preferences | Editor | Code Style. And you can only for a specific project. Moreover, if the configuration file .clang-format is detected in the project, CLion will propose switching to ClangFormat using this configuration file:

A little more details can be found in our blog (in English).
Naming variables, types, and other characters in code is a complex, sometimes even philosophical, issue. But in the programming world (to improve code readability), naming styles have long been invented. There is LLVM style, there is Qt, there is Google. Therefore, in the settings CLion Settings / Preferences | Editor | Code Style | C / C ++ now has a new tab - Naming Convention, in which you can choose one of the predefined styles or customize your own by setting the naming style for various types of characters (macros, global functions, class members, parameters, local variables, etc.). The chosen convention will be used in all IDE actions - code generation, refactoring, automatic corrections, etc. In addition, if you want to more accurately monitor the implementation of naming rules, you can enable the new Inconsistent Naming check, which will show the names,

In the same tab, you can find the header guards style settings that I mentioned above:

By the way, if you prefer to use it
We finally got our hands on viewing the memory in the debugger. In the current version, you can see the memory by pointer: just stand at any point in the Variables panel during debugging and request a Memory View (

Changes in UI / UX are already planned for the next release, but first I would like to collect feedback from users. So write!
The assembler code is now divided by function and, most importantly, it is shown not only in the case of GDB, but also for LLDB!

It is worth noting, however, that assembler code is still shown only in cases where there are no source codes for the function. The so-called disassemble on demand mode is not yet supported.
Sometimes step-by-step debugging is delayed due to the long calculation of variables at each step. But after all, sometimes these calculations are not needed by anyone - I want to go through some area of the code as quickly as possible, occasionally looking at the values of a pair of variables! Now in CLion there is an opportunity to disable variable recount during step-by-step debugging - Mute Variables in the debugger context menu does exactly that. And when you need to calculate and display the values, you can click Load on the variable :

Ilya Motor ( elmot ) already wrote here on Habré about his plug-in for integration of CLion with STM32CubeMX and support of OpenOCD debugger. At the end of last year, Ilya joined our team and had already managed to significantly update the plugin and move it inside CLion.

A fairly large and detailed blog post on the updated plugin can be found on our blog . Here I will describe the most important thing that can now be done:
Ilya has many ambitious plans, so your feedback is very important to us. So, if you are interested in developing for embedded systems in CLion, we are waiting for you in the comments!
Some time ago, the list of supported design models in CLion was expanded by Gradle C ++ and compilation database. There were problems with the latter, because the format does not include information about the assembly of the entire project, so neither the assembly, nor launching, nor debugging of the project in the case of a compilation database were possible. Yes, and just in the case of the well-known CLion project model, sometimes you want to have a target that is simply assembled by some team in the terminal.
Now for such cases there are Custom Targets (Settings / Preferences | Build, Execution, Deployment | Custom Build Targets) and Custom Run / Debug Configurations (Run | Edit Configurations ...). In the case of a target, you need to set the parameters of external tools (external tools), which will be used when assembling and cleaning the project:

And in the case of a project-independent configuration, for launch and debugging, you need to specify the target, executable file and the desired arguments to run:

Do you have string literals in your code that contain an SQL query, HTML code, or regular expression? If so, then surely you would like to at least highlight the code inside the literal in accordance with its origin. Now it is possible! You can temporarily include another language in a string literal by simply pressing

Products at JetBrains are usually created not by one small team, but by the team of the entire relevant platform. Therefore, CLion gets features from IntelliJ IDEA, WebStorm, AppCode, DataGrip, PyCharm, etc. In this release, these improvements include the following:
That's all for now. Thank you if you read to the end!
Well, and the traditional video about the new features of CLion 2019.1 (in English):
Questions, wishes, bug reports and just thoughts express in the comments! We will be happy to answer.
Your JetBrains CLion The Drive to Develop Team
The CLion team has a lot of great news - the St. Petersburg part of the team, together with other colleagues, successfully moved to a new office, new cool developers joined us, and most importantly, just the other day, we released the first big update this year, CLion 2019.1 !
Work in the new version went on several fronts at once:
- Improvements to the C ++ language support : code highlighting through Clangd, improvements to Extract and Rename refactoring, a new check that a member function of a class can be declared static.
- More options in the style of writing code : integration with ClangFormat, support for variable naming styles in C / C ++, support for different styles for header guards.
- New features and improvements of the debugger : viewing the state of memory - Memory View - for pointers, viewing disassembled code in case of LLDB, accelerating the work of step-by-step debugging.
- CLion for microcontrollers , the first steps.
- Ability to create Build Targets and configurations for launching / debugging in CLion, which are in no way related to the project model.
- Work with other programming languages in string literals in C / C ++.
- New visual themes and other platform features.

Read more about these and other innovations below. And to try new features and improvements, download the free 30-day version of CLion from our website .
C ++ language support
Clangd
As you already know, in CLion there are two tools for supporting the C ++ language - one completely its own, and the second based on Clangd. They work together, complementing each other and sharing the necessary information. At the same time, if performance and the criterion of functional completeness allow, we are now trying to transfer smart tools for working with C ++ code in CLion to a Clangd-based tool. We are not talking about code refactoring yet, but the highlighting of the code in 2019.1 is already done on the basis of Clangd. This significantly improved the responsiveness of the editor.
A few releases back, we switched CLion to a Clangd-based tool when displaying errors in the editor. Now the error text is shown in more detail. This is useful, for example, when debugging errors related to function overloading:

Added to this is the ability to calculate the position of a possible fix (quick-fix) also through Clangd. The fix itself is provided directly by CLion's own tool.
Another interesting area of our work is writing new checks on the Clangd code parsing tool. Starting with CLion 2019.1, a new check for C ++ code will tell you when a member function of a class can be declared static:

By the way, managing the settings of this alternative tool on Clangd can be found in Settings / Preferences | Languages & Frameworks | C / C ++ | Clangd.
Custom code parsing tool
Editor productivity is one of our top priorities. In addition to many small improvements, in this release it is worth noting a significant improvement in the initial indexing time of the project. It does not always happen, but in cases where you use the same libraries for your projects: then CLion can automatically notice this and reuse the symbols for these libraries for a new open project that uses them. When it comes to STL or Boost, the improvements are very noticeable!
Our plans for this year are to increase the accuracy and accuracy of our refactoring for C ++. We started with the two most basic ones - Rename and Extract. For Extract, we fixed many cases where the refactoring result turned out to be incorrect due to incorrectly considered namespace qualifiers (for example
std::
), template specializations, and overridden type names (type aliases).In relation to Rename, we paid attention to the case when there is a renaming of a class or structure that matches the name of the file in which they are located. Previously, we always renamed the file too, but now CLion asks you about the preferred outcome during refactoring. You can rename, or you can leave the old file name. The reverse also works - renaming the file does not lead to unconditional renaming of the class. (Somewhere here there should be screams from the audience: “Finally!”)

And, by the way, a little later I’ll talk about the possibility of setting header guards styles. So, if the header guard used in the file follows the specified style template and at the same time the name of the renamed file is in its name, then CLion will also update the header guard!
Coding styles
In version 2019.1, we added the ability to switch to ClangFormat to format code in CLion. This includes not only the formatting action itself (
Ctrl+Alt+L
on Windows / Linux, ⌥⌘L
macOS) or autoformatting when printing code, but also pre-commit hook formatting, when generating code using CLion tools, when refactoring and applying fixes (quick -fixes). In general, wherever the IDE formats the code, ClangFormat will be called. You can switch to ClangFormat globally - in the Settings / Preferences | Editor | Code Style. And you can only for a specific project. Moreover, if the configuration file .clang-format is detected in the project, CLion will propose switching to ClangFormat using this configuration file:

A little more details can be found in our blog (in English).
Naming variables, types, and other characters in code is a complex, sometimes even philosophical, issue. But in the programming world (to improve code readability), naming styles have long been invented. There is LLVM style, there is Qt, there is Google. Therefore, in the settings CLion Settings / Preferences | Editor | Code Style | C / C ++ now has a new tab - Naming Convention, in which you can choose one of the predefined styles or customize your own by setting the naming style for various types of characters (macros, global functions, class members, parameters, local variables, etc.). The chosen convention will be used in all IDE actions - code generation, refactoring, automatic corrections, etc. In addition, if you want to more accurately monitor the implementation of naming rules, you can enable the new Inconsistent Naming check, which will show the names,

In the same tab, you can find the header guards style settings that I mentioned above:

By the way, if you prefer to use it
#pragma
, just adjust the template for new header files in Settings / Preferences | Editor | File and Code Templates.Debugger
View Memory View
We finally got our hands on viewing the memory in the debugger. In the current version, you can see the memory by pointer: just stand at any point in the Variables panel during debugging and request a Memory View (
Ctrl+Enter
on Windows / Linux, ⌘Enter
on macOS). And if the memory view tab is open during step-by-step debugging, then you can see the highlighted changes in memory in it: 
Changes in UI / UX are already planned for the next release, but first I would like to collect feedback from users. So write!
Disassembly in case of LLDB
The assembler code is now divided by function and, most importantly, it is shown not only in the case of GDB, but also for LLDB!

It is worth noting, however, that assembler code is still shown only in cases where there are no source codes for the function. The so-called disassemble on demand mode is not yet supported.
Step-by-Step Debugging Performance
Sometimes step-by-step debugging is delayed due to the long calculation of variables at each step. But after all, sometimes these calculations are not needed by anyone - I want to go through some area of the code as quickly as possible, occasionally looking at the values of a pair of variables! Now in CLion there is an opportunity to disable variable recount during step-by-step debugging - Mute Variables in the debugger context menu does exactly that. And when you need to calculate and display the values, you can click Load on the variable :

CLion for microcontrollers
Ilya Motor ( elmot ) already wrote here on Habré about his plug-in for integration of CLion with STM32CubeMX and support of OpenOCD debugger. At the end of last year, Ilya joined our team and had already managed to significantly update the plugin and move it inside CLion.

A fairly large and detailed blog post on the updated plugin can be found on our blog . Here I will describe the most important thing that can now be done:
- In the New Project dialog, you can create the STM32CubeMX project ( .ioc ).
- Directly from CLion, run STM32CubeMX for the project to update the settings of the microcontroller and generate code for the project.
- CLion will generate the correct CMake file for working with this project.
- CLion will suggest choosing a configuration file for hardware (board config).
- For debugging using OpenOCD, you need to create a configuration of the special type “OpenOCD Download and Run”. For the STM32CubeMX project, CLion will create one on its own. Having specified all the settings, you can debug on the microcontroller directly from CLion!
Ilya has many ambitious plans, so your feedback is very important to us. So, if you are interested in developing for embedded systems in CLion, we are waiting for you in the comments!
Design independent targets and configurations
Some time ago, the list of supported design models in CLion was expanded by Gradle C ++ and compilation database. There were problems with the latter, because the format does not include information about the assembly of the entire project, so neither the assembly, nor launching, nor debugging of the project in the case of a compilation database were possible. Yes, and just in the case of the well-known CLion project model, sometimes you want to have a target that is simply assembled by some team in the terminal.
Now for such cases there are Custom Targets (Settings / Preferences | Build, Execution, Deployment | Custom Build Targets) and Custom Run / Debug Configurations (Run | Edit Configurations ...). In the case of a target, you need to set the parameters of external tools (external tools), which will be used when assembling and cleaning the project:

And in the case of a project-independent configuration, for launch and debugging, you need to specify the target, executable file and the desired arguments to run:

Injected language
Do you have string literals in your code that contain an SQL query, HTML code, or regular expression? If so, then surely you would like to at least highlight the code inside the literal in accordance with its origin. Now it is possible! You can temporarily include another language in a string literal by simply pressing
Alt+Enter
and selecting the “Inject language or reference” option. Now we select the language we need and, more recently, in the usual string literal, the highlight of the selected language appears, as well as all the special actions. The most striking example is regular expressions and the ability to check strings for compliance directly with them in the IDE:
And much more
Products at JetBrains are usually created not by one small team, but by the team of the entire relevant platform. Therefore, CLion gets features from IntelliJ IDEA, WebStorm, AppCode, DataGrip, PyCharm, etc. In this release, these improvements include the following:
- Viewing all the places in the project code where the developer made some changes or just read the code, Recent Locations Popup (
Shift+Ctrl+E
on Win / Lin,⇧⌘E
on macOS). - Creation of new themes for the IDE, in addition to the standard light, dark (Darcula) and contrast (High-Contrast). Examples of such plug-ins and a step-by-step tutorial can be found in our documentation .
- Speaking of plugins. If you write in Rust, you probably know that there is an IntelliJ Rust plugin. In CLion, its version includes Cargo support and a debugger. And with the new release, the plugin has tools for profiling code on Linux and macOS, the ability to autocomplete not yet imported characters, as well as other improvements.
That's all for now. Thank you if you read to the end!
Demo
Well, and the traditional video about the new features of CLion 2019.1 (in English):
Questions, wishes, bug reports and just thoughts express in the comments! We will be happy to answer.
Your JetBrains CLion The Drive to Develop Team