New Code Style API in Intellij IDEA 2018.1
IntelliJ 2018.1 introduces a new API that we want to make plugin authors aware of. We’re changing the way you retrieve Code Style settings (such as formatting options) so that you can provide a PsiFile, instead of a Project. The ultimate goal is to support different code style settings per scope, rather than per project (see IDEA-69685).
As a bonus, the new API provides a shorter form for getting code style. So, for example, instead of writing CodeStyleSettings.getSettings(project).getCommonSettings(language) you can now simply write CodeStyle.getLanguageSettings(file).
For now, CodeStyle.getLanguageSettings(file) is equivalent to calling (deep breath) CodeStyleSettings.getSettings(file.getProject()).getCommonSettings(file.getLanguage()), and will return the per-project settings, but this will change in the future when the most essential parts are migrated.
The migration to the new CodeStyle API is currently ongoing, and will continue throughout the 2018.x time frame – there are a large number of changes required both in IntelliJ Platform and plug-ins.
Note that we are not deprecating CodeStyle.getSettings(project), and it is still acceptable to call this instead of CodeStyle.getSettings(file). However, this should only be used in cases when using main project settings is logically the only choice in a given context. It shouldn’t be used just because existing code doesn’t have immediate access to an instance of PsiFile, otherwise the code will not catch up with per file settings when they become available.
As a call to action for plugin authors, please check that you are not using CodeStyle.getSettings(project) in your code, and migrate to CodeStyle.getSettings(file), or helper methods like CodeStyle.getLanguageSettings(file) and CodeStyle.getCustomSettings(file, class).
Please see the CodeStyle class for more information on methods.
Subscribe to Blog updates
Thanks, we've got you!
Wayland Support for IntelliJ-based IDEs
For Linux users of IntelliJ-based IDEs, an exciting advancement is on the horizon – the upcoming support of the Wayland display server protocol. This update is set to bring a host of benefits, including solving the age-old fractional scaling problem and elevating desktop integration when working wit…
Language Server Protocol for Plugin Developers
With the 2023.2 release cycle, IntelliJ-based IDEs now support the Language Server Protocol (LSP). Discover how this may improve the assistance for custom language-specific features and learn how to begin integrating LSP into a plugin for your IDE.
Busy Plugin Developers Newsletter – Summer 2022
Read this Newsletter to learn about the latest JetBrains Marketplace news and plugin development tooling updates.
IntelliJ Project Migrates to Java 17
The source code of the IntelliJ project was recently migrated to Java 17. We still have some modules compiled to be compatible with older Java versions so we can support running users’ projects under these versions. However, most of the platform and plugin modules now use Java 17, and the upcoming 2…