Fix RemoveUnusedImports command wiring
Problem
The RemoveUnusedImports feature only considered imports at the top level of files, missing imports inside #if conditional compilation blocks. This led to:
- False negatives: Unused imports inside
#ifblocks weren't detected - Incomplete cleanup: Projects with platform-specific or feature-flagged imports wouldn't get fully cleaned up
Solution
Implement recursive syntax tree traversal to find ALL imports throughout the entire file structure, including those inside conditional compilation blocks.
Fixes: #2335
Now properly handles all imports including those inside #if blocks while keeping platform-specific imports safe.
Since this PR has been inactive for a month and has some identified regressions, I'm planning to open a new PR that specifically addresses the #if clause logic using a BuildConfiguration provider as suggested, while ensuring inactive clauses are preserved. I will link the new PR shortly.
@amanthatdoescares Let us know if you’re planning to pick this up again in the near future. If not, thanks for the PR and your effort and @DPrakashhh will take it further from here.
Thanks for checking in. I don’t plan to continue work on this PR at the moment, so please feel free to take it forward from here.
I appreciate the feedback and the time spent reviewing it. I may take a look at the follow-up PR when it’s up, but otherwise happy for you to proceed. Thanks again.