Today we are thrilled to begin the CLion 2019.1 Early Access Program! The first build is already available for download. As usual, you can download build 191.4212.38. from our site, using Toolbox App, or through a snap package (if you are using Ubuntu).
The main highlights (as you probably already got from the title) include:
- ClangFormat support
- Bundled LLDB updated to v7.0.1
- Disassembly View was improved and is now available for LLDB (it was previously only available for GDB)
- Injected languages support (for example, SQL, HTML, RegExp)
- A nice update for anyone who writes or would like to write a plugin for CLion
CLion’s own formatter works as you type and it provides you with several predefined code styles like LLVM, Google, or Qt. There are also dozens of other flexible options that you can use to configure your code to your personal preferences. However, in the C and C++ world, there is a widely used tool for formatting the code, which some call the standard. It’s called ClangFormat. And it’s now supported in CLion! Let’s take a look at how you can use it.
Open a project in CLion with .clang-format file in it
If your whole team is using ClangFormat it’s natural that you should use it as well, especially since the config file is likely already present in the project repository. Besides this, many open source projects nowadays include a .clang-format config with the project source code. In cases where ClangFormat is used, when you open the project for the first time in CLion (and open any C/C++/Objective-C file in the editor), the IDE detect it and it will suggest that you switch to ClangFormat:
Another possibility is that you manually invoke Enable ClangFormat for project from the code formatting switch at the bottom of the editor at any time:
Another option is to turn it on in Settings/Preferences | Editor | Code Style (this will affect all the projects you are working on in CLion):
Review the ClangFormat options applied to a particular file
It’s possible to have several different ClangFormat settings inside one project: for example, a library used in the project, uses one style, while a user’s code is done in a different style. If this is the case, then there can be several .clang-format configs in the project. To better understand which style affects the file, CLion provides a quick and easy way to review all the ClangFormat settings applied in particular file – simply call the “View ClangFormat options for <file name>” action from the toolbar switcher when the necessary file is opened in the editor:
Tip: If you don’t have a .clang-format configuration file yet, you still can switch to ClangFormat in CLion using the toolbar switch or the IDE settings. LLVM style will be used in this case and you can review ClangFormat settings in the IDE.
These settings are currently read-only. We’ll add the ability to change and export them later (CPP-15184).
When is ClangFormat used?
Naturally everywhere in the IDE where you have code to format:
- While typing in the editor or pasting the code
- When calling the Reformat Code action for a selected piece of code (
- When reformatting the code before a commit (pre-commit hook), if a commit is done via the Commit action (
- When calling Generate actions
- When Refactoring
- When applying quick-fixes and intention actions
- It’s not possible right now to import/export settings between CLion’s own formatter and ClangFormat (CPP-4805).
- ClangFormat only works for C, C++, and Objective-C.
- A few other issues linked to the parent ticket CPP-4809.
Debugger: Disassembly View
LLDB users will be happy to learn that bundled LLDB (on macOS and Linux platforms) was updated to 7.0.1 in this build. And more importantly, Disassembly View now works for LLDB as well!
Disassembly View was updated for both backends: GDB and LLDB, and now it shows information per function:
Please note, CLion still doesn’t provide Disassembly View on demand (CPP-9091), which means that it only works after you force the step into functions with no source code. As a workaround, feel free to use a nice 3rd party plugin known as Compiler Explorer (hopefully, it will soon be updated to work with 2019.1 EAP).
When coding in C and C++, there can sometimes be pieces of code inside string literals. Wouldn’t it be nice if an IDE could treat them as code, and not as text? For example, SQL strings, HTML code, or Regular Expressions. Well, it’s now possible in CLion! To temporarily inject a language, press
Alt+Enter and apply the intention “Inject language or reference”, select the appropriate language, and you are done!
CLion provides accurate code highlighting based on the language chosen, it also has language-specific intentions, actions, and it can edit a code fragment in the dedicated editor section functionality. For example, for regular expressions you can check if a string matches the RegExp right in the IDE:
This injection is temporary, which means it will be removed when you restart the IDE restart or reopen the project. And of course, you can un-inject manually using the
Alt+Enter context menu.
An update for plugin writers
When you are missing any functionality in CLion you may create a feature request or consider implementing a plugin using IntelliJ Platform API. In our plugin repository, there are more than 1.2K plugins for CLion (check this selection of valuable non-bundled plugins). We have simplified the process of building CLion’s plugins by publishing CLion as a Maven dependency to be used by gradle-intellij-plugin (since version 0.4.2). In simple terms, this Gradle plugin adds the specific IntelliJ-based IDE dependencies, helps with preparing plugin.xml files and preparing the proper structure for the plugin, executes the IDE instance with the plugin you are developing, and finally, it also helps with uploading the plugin to the plugin repository. And starting with 2019.1 it’s aware of the CLion SDK.
We do hope to make some help articles on the CLion specifics, which will be available here shortly, and we welcome anyone who wants to create a plugin for CLion to check it out!
Since 2018.2 CLion uses an additional Clangd-based C++ language engine for showing code errors and warnings in the editor and some navigation and search actions. In this EAP we’ve improved the errors messages and take more details from Clang:
These details, for example, might be very useful when you debug failed overload resolution in your C++ code.
This EAP brings new inspection which reports the member functions that can be marked as
If you are using compilation database project model in CLion, you’ll be interested to learn that CLion now allows you to build/clean such projects. Just configure external tools and provide them in the settings as build/clean commands:
And finally, there are also notable VCS improvements coming from the IntelliJ Platform. Thanks team!
That’s it. Full release notes are here. Download and try the EAP build right now and let us know what you think!
Your CLion Team
The Drive to Develop