Index: lib/Format/Format.cpp =================================================================== --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -1515,6 +1515,81 @@ }; assert(std::is_sorted(std::begin(FoundationIdentifiers), std::end(FoundationIdentifiers))); + // Keep this array sorted, since we are binary searching over it. + static constexpr llvm::StringLiteral ObjCFrameworks[] = { + "ARKit", + "AVFoundation", + "Accounts", + "AddressBookUI", + "AppKit", + "AssetsLibrary", + "AudioToolbox", + "CloudKit", + "Contacts", + "ContactsUI", + "CoreAudioKit", + "CoreBluetooth", + "CoreData", + "CoreImage", + "CoreLocation", + "CoreMIDI", + "CoreML", + "CoreMotion", + "CoreNFC", + "CoreSpotlight", + "CoreTelephony", + "DeviceCheck", + "EventKit", + "ExternalAccessory", + "FileProvider", + "FileProviderUI", + "Foundation", + "GLKit", + "GameController", + "GameKit", + "GameplayKit", + "HealthKit", + "HomeKit", + "IOSurface", + "IdentityLookup", + "Intents", + "IntentsUI", + "JavaScriptCore", + "MapKit", + "MediaPlayer", + "MessageUI", + "Metal", + "MetalKit", + "MetalPerformanceShaders", + "ModelIO", + "MultipeerConnectivity", + "NetworkExtension", + "NewsstandKit", + "NotificationCenter", + "PDFKit", + "PassKit", + "Photos", + "PhotosUI", + "PushKit", + "QuartzCore", + "QuickLook", + "ReplayKit", + "SafariServices", + "SceneKit", + "Social", + "Speech", + "SpriteKit", + "StoreKit", + "UIKit", + "UserNotifications", + "VideoSubscriberAccount", + "Vision", + "WatchConnectivity", + "WatchKit", + "WebKit", + }; + assert(std::is_sorted(std::begin(ObjCFrameworks), + std::end(ObjCFrameworks))); for (auto &Line : AnnotatedLines) { for (FormatToken *FormatTok = Line->First; FormatTok; @@ -1536,6 +1611,18 @@ TT_ObjCDecl, TT_ObjCForIn, TT_ObjCMethodExpr, TT_ObjCMethodSpecifier, TT_ObjCProperty)) { return true; + } else if (Line->Type == LT_ImportStatement && + !FormatTok->getPreviousNonComment() && + // #import + FormatTok->startsSequence( + tok::hash, tok::identifier, tok::less, tok::identifier, + tok::slash, tok::identifier, tok::period, + tok::identifier, tok::greater) && + FormatTok->Next->TokenText == "import" && + std::binary_search(std::begin(ObjCFrameworks), + std::end(ObjCFrameworks), + FormatTok->Next->Next->Next->TokenText)) { + return true; } } } Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -12110,6 +12110,14 @@ EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo", "@interface Foo\n@end\n")); EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo.h", "int DoStuff(CGRect rect);\n")); + EXPECT_EQ(FormatStyle::LK_ObjC, + guessLanguage("foo.h", "#import \n")); + EXPECT_EQ(FormatStyle::LK_ObjC, + guessLanguage("foo.h", "#import \n")); + EXPECT_EQ(FormatStyle::LK_Cpp, + guessLanguage("foo.h", "#import \n")); + EXPECT_EQ(FormatStyle::LK_Cpp, + guessLanguage("foo.h", "#include \n")); EXPECT_EQ( FormatStyle::LK_ObjC, guessLanguage("foo.h",