All that you have asked for a long time, in one release - CLion 2018.2
Hi, Habr!
We do not know how hot it is outside your window, but in JetBrains these weeks are exactly the heat - release. One after another, we published updated versions 2018.2 of almost all of our tools based on the IntelliJ platform: WebStorm, IntelliJ IDEA, PyCharm, DataGrip, GoLand, PhpStorm, RubyMine and CLion.
For the CLion team, this release is special, as it includes the results of our work in three very important areas: ')
Clangd as the basis for a new experimental engine for parsing C ++ code.
IDE performance improvements due to new architectural solutions.
New design models supported in CLion.
As well as support for Google Sanitizers, the ability to rebuild a single file and much more!
Below we will talk about improvements and innovations in detail, and the most impatient can right now download the free 30-day version from our website and try new features on your project or a specially prepared demo project from GitHub .
Clangd for parsing C ++ code in CLion
Back in March, we told you that we are considering various alternative language options for CLion. This is understandable - you want to fundamentally improve support for current language features, and quickly add fresh C ++ chips, and write more cool and C ++-specific refactorings, etc. For all this, you need an accurate and fast code parser.
We continue to improve our current parser, methodically corroding various errors and omissions. In addition, we decided to try to make another language engine based on clangd (this is such an implementation of the LSP protocol for clang).
If you go straight to the results - in CLion 2018.2, in addition to the main language engine, the new, experimental, clangd works also. Moreover, we are so bold that we turned it on by default on Linux and macOS. On Windows, unfortunately, an unpleasant feature of the memory clangd work was discovered , and by default we turned off the new engine on this platform (but with a high probability this will be fixed already in the first minor updates to version 2018.2). You can enable / disable the experimental code parser based on clangd in Settings / Preferences | Languages & Frameworks | C / C ++ | Clangd:
It is important to understand:
The clangd-based code parser works in parallel with its own CLion parser.
Clangd is used only to display errors and warnings in the editor. For everything else (including refactorings, bug fixes (quick-fixes), navigation, auto-completion, etc.), CLion's own parser is used.
The configuration of errors and warnings by default Clang is specially selected to show quite a few warnings about potential errors, but it does not contradict the code inspections that work in CLion based on their own code parser and are enabled by default.
When warning your questions, I will say right away that we are planning to try to translate other smart IDE features into clangd, but first you need to stabilize the current solution, conduct many more tests and solve many complex and fundamental issues along the way.
New check for C ++ code
When a function accepts several parameters of the same type, it is easy to make a mistake and unwittingly (and the compiler) swap the arguments of the same type when calling this function. Such errors are hard to catch, which means their cost is high. But in CLion 2018.2, we implemented a new code check (inspection) specifically for such cases. It uses a heuristic algorithm to analyze the names of parameters and function arguments and is able to detect situations where the order of the arguments is erroneously changed:
Important:
To avoid false positives, the algorithm is automatically disabled for very short names (less than 3 characters).
For the same reasons, the algorithm is disabled for functions whose names contain the substrings swap / inverse / rotate / backward / flip.
For a number of technical reasons, the inspection only works when the experimental code parser is enabled on clangd and, moreover, when the clang-tidy code analyzer is enabled via clangd (this is all in the settings of the above-mentioned Settings / Preferences | Languages & Frameworks | C / C ++ | Clangd).
IDE performance
In this release, we purposefully plagued IDE (UI freezes) hangs in a number of cases: with autocompletion, in Search Everywhere search, in navigation to the associated symbol (which is usually used to switch between the source file and the header file and back), when using breadcrumbs (breadcrumbs) to navigate. The first users of the release, as well as numerous members of our Early Access Program, have already appreciated the improvements and confirm that the IDE's behavior has improved significantly, and there have been significantly less hang-ups. Work in this direction will continue in 2018.3.
In addition, we translated the built-in code formatter to lexer . Of course, when working through the parser (as before), its result is more accurate, but here the work time is significantly increased. And since the formatting of the code in CLion occurs at the moment when you print the code, hangs here can have a very negative effect on the overall impression of the IDE's speed. Responsiveness of the editor falls, hangs become noticeable, and so on.
The formatter on the lexer works quite neatly, but if you still have problems with formatting on your code, then first, be sure to tell us about it , and secondly, you can always switch to a slower, but more accurate formatter on parser - for this there is an option cidr.indent.lexer.only.cpp in the Registry.
New design models: Gradle C ++ and compilation database
Until 2018.2, there were the following ways to open a project in CLion:
Open CMake project.
Open a file or a whole folder that does not have CMake files. At the same time, many smart functions for working with the code will be disabled.
Open a project on Gradle, specifying the IDE location of the build.gradle file. Please note that CLion currently supports only the new Gradle format for C ++ projects:
Open a project from the compilation database, specifying the IDE location of the file compile_commands.json . So far, in this case, it is impossible to build and run a project from CLion, since the compilation database does not contain information about building the whole project.
But in both cases, both the Gradle and the compilation database, all the smart code functions are available! And by the way, the compilation database option is interesting because in fact now whatever project you have - Makefiles, Ninja, Qbs, any of your specific project model - you can generate a compilation database for your project and open it in CLion!
In the meantime, we continue to work on the API to add support for new design models in the CLion!
CMake Improvements
Some major improvements have been made for CMake projects. The most important thing is that if your header files located inside your project directory are used in project files and are connected via the #include directive, they no longer need to be explicitly listed in CMake scripts ! CLion will now mark them as design itself, and all smart functions like refactorings and auto-completion will be available in such files:
The second important improvement is related to setting up external tools (external tools), which can then be called either independently by command or made part of the application launch configurations. They now have macros containing all kinds of CMake variables. For example, the build directory or the name of the executable file:
Tools for dynamic code analysis
For Valgrind Memcheck, supported by CLion back in version 2017.3, it was possible to export and then import the analysis results back:
Also in this version, CLion has added support for another tool for dynamic code analysis - Google Sanitizers . To enable them, you must explicitly specify the -fsanitize special key in the CMake scripts of your project, and then, if you use Clang version at least 3.8.0 or GCC version at least 5.0.0, CLion will be able to automatically detect the use of sanitizers and show the results of their work in special window:
In it, you can view not only the list of errors found, but also the source code (and navigate it), study the information about the frame, watch the error trace. For more information about the supported sanitizers and settings in CLion, read our blog post in English.
Rebuild one single file
For the CMake and compilation database project models in CLion 2018.2, it is possible to rebuild one file without rebuilding the entire project. To do this, there is an action in the Run menu - Recompile, or you can use the Shift + Ctrl + F9 key combination on Linux / Windows, ⇧⌘F9 on macOS (in the default layouts):
This feature is a great way to quickly verify that your current file changes did not break the build of the entire project. If the details are interesting, which compilation command is called and how the assembly type is selected, you can read in detail in our blog .
Database
According to the results of our survey on Twitter , many CLion users turn to certain databases when developing a project in C / C ++. Therefore, since this release, a plug-in for working with databases and SQL code has been included in our IDE. It is a complete functional analogue of our environment for working with databases - DataGrip . So here this post here on Habré from moscas about innovations in DataGrip 2018.2 you may also be interested in reading.
And that is not all!
Briefly about other improvements:
We have a new version of the LLDB 6.0 debugger and a new version of CMake 3.12.
In addition, in the case of GDB, CLion learned how to use pretty-printers for types when displaying pointers to variables of this type.
Background processes are supported for WSL, which makes it much easier to run the entire CLion configuration with WSL.