sourcekit-lsp icon indicating copy to clipboard operation
sourcekit-lsp copied to clipboard

Fix RemoveUnusedImports command wiring

Open amanmaurya92 opened this issue 11 months ago • 3 comments

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 #if blocks 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.

amanmaurya92 avatar Dec 20 '25 09:12 amanmaurya92

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.

DPrakashhh avatar Jan 16 '26 04:01 DPrakashhh

@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.

ahoppen avatar Jan 16 '26 07:01 ahoppen

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.

amanmaurya92 avatar Jan 16 '26 07:01 amanmaurya92