Handles unused imports
Fixes #2335
1-Integrated SwiftIfConfig: Added and linked the library in Package.swift and CMakeLists.txt to enable conditional compilation evaluation.
2-New Build Configuration: Implemented SourceKitLSPBuildConfiguration to provide the necessary compiler arguments and target triple for #if evaluation.
3-Platform-Aware Visitor: Refactored ImportCollectorVisitor to use activeClause(in:), ensuring only active code blocks are scanned for unused imports.
4-Verified Logic: Added unit tests confirming correct behavior for both active and inactive branches, passing all 71 tests in the suite.
Thanks for the feedback! I implemented the previous version following the earlier suggestion to use a configuration evaluator, but I completely agree that relying on sourcekitd for activeRegions is a much more robust and cleaner architectural path.
I’ll refactor the implementation to use the activeRegions request to identify live source ranges instead. I'll update the PR as soon as it's ready.
Hi, I've refactored the implementation to use sourcekitd’s active_regions API, removing the manual flag-parsing logic and ensuring all CodeActionTests (including canImport cases) now pass correctly.
I’ve refactored the implementation to address all feedback:
1-Simplified Architecture: the visitor now uses parent lookup to gate #if imports against activeRegions.
2-Swifty Refinements: Adopted compactMap for parsing and zip(entries, entries.dropFirst()) for index-free range building.
3-Cleanup: Removed all superfluous debug logging, updated doc comments, and swapped to native Range<AbsolutePosition>.
4-Explicit Tests: Added detailed assertions to verify the specific imports targeted for removal.
Ready for final review!
I will continue reviewing this PR after your PR to indexstore-db is ready to be merged.