I'm working with intelliJ and my problem is when I start to import some temporary unused packages into my class file intellij delete those line within a second.
how can I turn off this not so nice feature?
Disable File | Settings | Editor | General | Auto Import | Optimize imports on the fly.
Normally you don't need to add imports manually, IDEA does it for you.
For Scala developers: you can have enabled
Settings > Editor > General > Auto Import > Optimize imports on the fly
but add exclusions into
Settings > Editor > Code Style > Scala > Imports always marked as used:
In Intellij 14 :
Settings > Editor > General > Auto Import > Optimize imports on the fly.
(Update)
For the Scala developers out there, you can have 1/2 the cake and eat the other 1/2 now: disable the auto-optimize for just scala
For me while using Go, this was caused by optimizing imports on save. IntelliJ IDEA -> Prefernces -> Tools -> Actions on Save -> Optimize imports.
The above answers are obviously the way to go. Here's another quick fix (a bad one at that) is to simply use it somewhere in your code
if (0) console.log(LibraryName.version);
This should only be a temporary measure though.
Related
how can I persist Kotlin inspection settings in file .editorconfig in IteliiJ IDEA so that I could share them with a team through git?
Exact settings name is:
Editor > Inspections > Kotlin > Style issues > Accessor call that can be replaced with property access syntax
I'd like to change it's Severity level.
I tried to follow
https://www.jetbrains.com/help/rider/Code_Analysis__Code_Inspections.html#list-of-configurable-code-inspections
and
https://www.jetbrains.com/help/idea/configuring-code-style.html#editorconfig
but with no luck.
How exactly should .editorconfig entry look like for that settings and where can I find full list of property keys?
Thanks in advance!
Inspections have nothing common with .editorconfig files.
Editorconfig
Editorconfig is about Code Style (Preferences | Editor | Code Style | Kotlin)
All the styles could be exported via this button:
There are too many options to describe them all. That is why export is easier.
General options could be found at https://editorconfig-specification.readthedocs.io/#supported-pairs
Kotlin inspections
Inspections are IDE-specific. And they can be exported/imported to an XML file via this button:
But there is no possibility to export an individual inspection. Instead, you can create a project-wide inspections profile with your team and use it across.
You can share the inspection profile along with the project. Just add this file to your project's VCS: .idea/inspectionProfiles/Project_Default.xml
If place my selection on an unresolved variable (roles in below image) and press option+return I'm supposed to get suggestions on imports that I can add to resolve the variable.
As you can see in the screenshot, I don't get the import suggestions anymore. I think this broke two updates ago, for me.
Adding imports on the fly still works. Import suggestions when I add imports by typing still works.
Any idea on what is wrong with my settings? I'm developing in Javascript using IntelliJ Ultimate.
Please make sure that Missing import statement inspection is enabled in Preferences | Editor | Inspections JavaScript | General.
Please also check the JavaScript | General | Unresolved JavaScript function and JavaScript | General | Unresolved JavaScript variable inspections
I'm using Intellij IDEA 2017.1.2 on MacOS High Sierra and the situation is when I type OPTION+ENTER it recommends me to import a class,Auto imports for all classes work well except for HashMap. For example, the class HashTable in the java.util package can auto complete.
I don't know what I had click or checked so how can I fix this problem?
See Preferences > Editor > General > Auto Import > Exclude from Import and Completion.
Here's a screenshot:
With this exclusion in place IntelliJ will not offer java.util.HashMap as an auto import option.
If you remove this exclusion IntelliJ will resume offering java.util.HashMap as an auto import option.
How can I exclude some classes from autocomplete, but not from project?
I'm trying to develop on flash with starling library. The problem is that IDE always suggest me a built-in classes, which I probably don't want to use, even if I import another class.
http://monosnap.com/image/7VRQpIhqIPRK2wgBKp41GOU9i
I'm tried to exclude in a Settings -> Editor -> Auto Import, but it takes no effect on a autocomplete.
May be I can reorder autocomplete suggest, for placing the libraries classes on top?
I'm using idea 12.0.4
Does Settings -> Editor -> Auto Import -> Exclude from Import and Completion help you?
Now in Preferences | Editor | General | Auto Import
There are instructions at https://www.jetbrains.com/help/idea/auto-completing-code.html for disabling, but they didn't work for me until invalidating caches and restarting.
Pull up autocomplete, highlight the offending item, then option-return and exclude it, either at the class or method level. Then invalidate caches and restart.
I'd like to selectively disable the IntelliJ IDEA code formatter for a portion of code just like I can in Eclipse. Does IntelliJ support this feature, and if so, how do I use it?
Since version 13 it's possible to wrap the code with
// #formatter:off
...
// #formatter:on
IntelliJ IDEA v.2018+:
File > Settings > Editor > Code Style
IntelliJ IDEA v.2016+:
Preferences > Editor > Code Style
IntelliJ IDEA v.14+:
Preferences > Editor > Code Style > Formatter Control
You can change the formatter control markers, as long as they're in comments.
Ensure formatter markers in comments are enabled, as shown in the following figure:
Note for Carlos' answer of #formatter:off and #formatter:on to work, you may need to enable the preference first:
Discovered via How to config intellij-idea not format some part of the code?
IDEA-56995 Disabled code formatting per region using comments
In xml files, use:
<!-- #formatter:off -->
<!-- #formatter:on -->
Obsolete answer from 2010:
No, it's not possible right now, I've submitted a new issue which you can track.
As a temporary solution you can use external formatter plug-in for IDEA which can utilize Eclipse code formatter (I didn't check whether this particular option is supported).
It's currently not possible to exclude entire files (like regression test data xmls) from formatting. See https://youtrack.jetbrains.com/issue/IDEA-167112