question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No way to massively remove unused imports

See original GitHub issue

Environment

  • IntelliJ Rust plugin version: 0.4.171.4656-213
  • Rust toolchain version: 1.63.0-nightly (420c970cb 2022-06-09) x86_64-pc-windows-msvc
  • IDE name and version: CLion 2021.3.4 (CL-213.7172.20)
  • Operating system: Windows 10 10.0
  • Macro expansion engine: new
  • Name resolution engine: new
  • Additional experimental features: org.rust.macros.proc

Problem description

At the active development phase that’s very frustration to have a lot of “unused import” warnings. And as I see, It’s IDE level inspection works fairly well. Why do not allow user to remove them all by one hotkey? For example by “Optimize imports”. Or this feature: image It explicitly should do what I need, but it does nothing (I mean option to fix all in file).

Ok, I’ve googled a lot of discussions that “unused imports” inspection is unreliable because has false-positives, but why do not allow this as an experimental feature? I’m ok to fix rare false-positives manually.

So I’m creating new issue as suggested here

org.rust.macros.proc toggle doesn’t make any difference.

Steps to reproduce

  1. Create fresh binary executable project with following code
use std::borrow::Borrow;
use std::ops::Div;

fn main() {
    println!("Hello, world!");
}
  1. Optimize imports with Ctrl+Alt+O (unused imports left)
  2. Try to remove them with the Alt+Enter/External linter: remove whole item - it works (for a single item)
  3. Try to apply fix to whole file with Alt+Enter/External linter: remove whole item/Fix all 'Annotator' problems in file - it does nothing

(Language & Frameworks/Rust/External Linters/External Linter is default - “Cargo Check”)

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:6
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dima74commented, Oct 25, 2022

@kkolyan this is very strange. Which version of the plugin are you using? Could you please attach your idea.log? Could you also try to disable “Enable inspection only if procedural macros are enabled” option in intention settings?

“Unused import” is reported

By the way it is reported by cargo clippy external linter, not by our builtin annotator. Import will be fully grayed out when reported by our annotator:

0reactions
peterwillicommented, Nov 17, 2022

After enabling the experimental features and disabling “Enable inspection only if procedural macros are enabled”, all works, but only in some cases.

For some reason, this doesn’t work: image

But this does: image

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to configure Eclipse's "clean" to remove unused imports?
1) right click on package then Source->Organize Imports 2)`Ctrl+Shift+O` . Here is Save Actions another way which can even avoid Ctrl+Shift+O.
Read more >
How to remove unused imports in VSCode. - LinkedIn
Press [Command + , ] to open settings. Click on that top-right icon (Open settings JSON) as shown in the below image marked...
Read more >
How to detect and remove unused imports? : r/learnjavascript
Is there a tool that will analyze a page and say which JS files are imported but not called? 1.
Read more >
What is the Shortcut to Auto Import All in Android Studio?
Note: We can import a single missing import using Alt + Enter which shown in the pop-up. To optimize imports (to remove unused...
Read more >
How to enable "remove unused imports"
Preferences->Editor->Auto Import->Optimize Imports on the Fly will automatically remove unuxed imports. 5. Avatar. Stephen Boesch · Created ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found