How can I fix unused imports in Rust automatically? - intellij-idea

Is there any way to fix ONLY unused imports in Rust automatically? I have seen cargo fix, which does work, but it makes a whole bunch of other fixes too. Is there any way to tell cargo fix to only fix unused imports (preferably in a specified file) and nothing else?
Side question: Is there any way to make IntelliJ do this? The usual shortcut (Cmd+Option+O) works in other languages, but for Rust, it just re-orders the imports.

According to this pull request, JetBrains' Rust plugin should be able to remove unused imports already but it is not enabled by default. According to this comment, it seems like the dev team need to wait until org.rust.macros.proc (currently an experimental feature disabled by default) to be enabled by default.

Individual lints are currently only configurable via attributes in your source code. There is no way to tell cargo check or cargo fix to ignore certain lint rules through the command line tool.
From my experience with JetBrains tools, it's unlikely that they'd use cargo fix under the hood anyway. They have built their own Rust tooling for parsing and analysing code, and that is where this feature would go.
I suggest submitting a feature request to JetBrains.

Enable Settings > Editor > Inspections > Rust > Lints > Unused Import.
Disable Enable inspection only if procedural macros are enabled in the same section.
Versions
IntelliJ IDEA Build #IU-223.7571.182
Rust Plugin 0.4.185.5086-223

Related

How can out-of-tree sources be included in a Meson project?

Some background: I am using Meson for an embedded C project. I have it working (example), but it isn't very clean.
The specific problem I would like to solve is including an out-of-tree Board Support Package (BSP) - a tree of headers and C files that act as initialization and abstraction code for a particular platform.
Previously I have been copying headers out of a vendor-provided BSP into my project on an as-needed basis, which does work, but there are disadvantages to doing this, the most important being the lack of reproducibility. Additionally, it causes duplication of code and makes it difficult to track where a particular bug came from if the bug is in the BSP.
The ways I have tried are:
Use an option in meson_options.txt to tell Meson where the BSP is on disk via meson configure. The issue with this method is that Meson throws an error during setup because options cannot be set until after setup is complete, and so it cannot find the requisite directories and refuses to continue.
Use a subproject and repeat the above - this causes the same issue.
I would ideally like the end-user to be able to set the BSP path with meson configure, instead of having to ever edit the build description (the whole point of Meson is to be user friendly!).
Is this possible? If it is not possible, why, and are there alternatives/common practice ways of doing this that I should know about?
In your question, you state that
options cannot be set until after setup is complete
That is not true. You can pass any option you want during the meson setup, using the following syntax:
$ meson <build dir> -D<option>=<value>
So I think the first way you tried to implement your option was correct, you just need to tell the user to set it directly during setup.

IntelliJ (2020.2) - How disable 'Build project automatically' for a project based on Gradle?

I am an Eclipse/STS user/developer, now trying to use IntelliJ Idea (CE)
2020.2.(1,2,3)
For a project based on Gradle, how spring-integration, when I open the IDE it happens the following
Ok, let the IDE load the project ... but
From above, that is the problem, I don't want that the IDE starts automatically to build/rebuild the project. I just need, open the project and that's all.
Observation: for example in Eclipse/STS exists the option to disable Build Automatically
I did do a research in the Web and I read the following posts and questions:
How to disable automatic gradle builds?
IntelliJ IDEA “Build project automatically” apparently not working
Intellij IDEA Java classes not auto compiling on save
Sadly the dialog options were changed but ...
Therefore:
From above, seems nothing to do.
Observation: from above observe the Build project automatically option is disabled
Even with that disabled and after to restart the IDE, I must always stop manually the build process
So what is missing? or Do I need a special extra plugin to accomplish my goal?
The images that you show indicate that you are building with Gradle, but the Compiler option that you disable is relevant for building projects with Idea not with Gradle.
For the 2020.2 version, you need to do the following:
Open the Setting > Build Tools page.
Disable the "Reload changes in build scripts" option.
This way you can manually control the reload. When you change the build script, you will see a small gradle icon in the right side of the editor.
For more info, refer to the IntelliJ IDEA help > Gradle section.
https://www.jetbrains.com/help/idea/work-with-gradle-projects.html#auto_reload
There are two different things in IntelliJ's Gradle support that sometimes confused: sync and build. Your pictures demonstrate sync process (note caption on the toolwindow). Word build is kind of misleading here.
What is sync? In gradle we use Groovy to define the build procedure. Groovy is an imperative programming language, so it's hard to predict resulting dependencies graph without actually executing the script. During the sync Idea executes configuration phase of gradle build (one that builds dependency graph), and obtains configured objects from the Gradle daemon. This information is used to setup project in the IDE: modules, libraries, dependencies, which sources are test, which are prod, etc.
Actual build is not happening during sync. You can convince yourself by adding syntax error to any source file, and observe that the sync succeeds. But build will fail if you invoke it.
In answer to the original question: you can't disable automatic build, because it is not enabled.
Is it possible to disable sync in Gradle project? Short answer - no. If you need a code browser, which is not required to understand all the cross-references in the source code, IDEA is not the best choice probably.
TL;DR;
Without sync IDE does not know which files are sources, and which are not. IDEA cannot open folders. It only can open projects. Good thing is that module can contain folder. So you can do the following: File | New | Project. Select Empty project, Next, select some random folder outside the source folder you want to open, Finish.
Then add new module:
Select Java in the left panel, everything else keep default, Next, Finish. Then in new module remove existing content root, and add folder with sources as new content root
Resulting project is mostly useless. Tons of red code (at least, unresolved symbols from external libraries), no inspections, no navigation, no sense. But it might be useful in some rare situations indeed.

Coroutines working but IntelliJ shows errors

I am working on a project using kotlinjs for nodejs and I start to learn coroutines and integrate them into my code to say goodbye to the callback hell.
I managed to get coroutines working, my code can be compiled and executed, everything seems fine.
...except: The IDE still shows me errors. It seems to be confused by the additional libraries I added in order to get coroutines running.
I am currently fiddling around with the library dependencies, sometimes some errors go away, but then some code gets red which was okay before...
This is what I see:
Case 1:
Cannot access class 'kotlinx.coroutines.experimental.CoroutineContext'. Check your module classpath for missing or conflicting dependencies
Case 2:
Unresolved reference: JsModule
Modifier 'external' is not applicable to 'class'
You see, launch is recognized when I add the stdlib, but then the IDE complains with the other two errors.
Again, please note: In both cases, actual compilation is successful!
I am using IntelliJ 2018.1 with Kotlin Plugin 1.2.41.
Thanks to Alexander Chernikov at youtrack.jetbrains I could resolve my problem.
I cite his explanation:
The issue is that JavaScript libraries should be marked with special attribute to be recognized.
When they are imported from pom.xml or build.gradle, this mark is set, so the feature works.
In your project they are not marked.
At the moment, to correct the libs manually, please open .idea/libraries/org_jetbrains_kotlin_kotlin_stdlib_js_1_2_41.xml and .idea/libraries/org_jetbrains_kotlinx_kotlinx_coroutines_core_js_0_22_5.xml.
In both files find type="repository" and replace it with type="kotlin.js".
Make sure IDEA sees the change. (You can exit IDEA, make the change and restart.)
Then you can keep only these two libs in dependencies. The editor should work.
Here is the issue link:
https://youtrack.jetbrains.com/issue/KT-24575
There I have also attached a sample project with the problem.

Intellij auto optimize imports for Go

I have Intellij ultimate version 14.1.4. How do I enable optimizing imports automatically with each save for "Go"? In Settings->Editor->General->Auto Imports, I see options for Java/python/scala but not for Go. I have the Go plugin installed already. But this unused import compile error is a noise. I want to enable automatic optimizing of imports to avoid CTRL+ALT+O combination
This functionality is not yet available for the Go plugin, that's why you don't see any options there / it doesn't work automatically.
You might want to watch this issue or maybe this PR to get notified when they will be fixed.
Meanwhile, you can use the Code -> Goimports file functionality and maybe assign it a shortcut of your own preference as it doesn't have one by default. For this to work you will need to have goimports installed and in your system's PATH.

Differenct Findbugs behavior with QAPlug-findbugs and gradle configuration

I am working on a Java project. I am using IntelliJ Idea 12.1.4 as IDE.
I verify the quality of code two ways,
I have installed QAPlug-FindBugs plugin in IntelliJ idea and I analyze the code using
a custom analysis profile. This profile has only one findbugs rule activated.
I have applied findbugs plugin in build.gradle file of the project. I
run gradlew check command.
These two approaches result into different number of findbugs warnings/errors. Actually, gradlew check results into lot more errors/warnings than QAPlug -> Analyze Code.
I understand that when I mention apply plugin : 'findbugs' the effort level is set to Default value.
I tried to figure out the relation between gradle plugin and Intellij Idea plugin. I am not able to figure out what coding rules should be activated in my custom profile (for QAPlug -> Analyze Code action) to match the behavior of 'gradle check'.
Can anybody give me a pointer as to what's going on?
Vijay,
I am not sure if you are looking for information about QAPlug or Gradle.
In case of QAPlug please check following tutorial:
Creating your own analysis profile
Regarding the Gradle, I found the following information:
"By default, all detectors which are not disabled by default are run."
Gradle FindBugsExtension
To have the same number of Findbugs warnings/errors you should do the following:
deactivate all rules in you custom QAPlug analysis profile
using search box find those "Powered by Findbugs" and activate them
I hope that it helps.