@@ -8404,10 +8404,23 @@ void Sema::CodeCompleteIncludedFile(llvm::StringRef Dir, bool Angled) {
8404
8404
};
8405
8405
8406
8406
// Helper: scans IncludeDir for nice files, and adds results for each.
8407
- auto AddFilesFromIncludeDir = [&](StringRef IncludeDir, bool IsSystem) {
8407
+ auto AddFilesFromIncludeDir = [&](StringRef IncludeDir,
8408
+ bool IsSystem,
8409
+ DirectoryLookup::LookupType_t LookupType) {
8408
8410
llvm::SmallString<128 > Dir = IncludeDir;
8409
- if (!NativeRelDir.empty ())
8410
- llvm::sys::path::append (Dir, NativeRelDir);
8411
+ if (!NativeRelDir.empty ()) {
8412
+ if (LookupType == DirectoryLookup::LT_Framework) {
8413
+ // For a framework dir, #include <Foo/Bar/> actually maps to
8414
+ // a path of Foo.framework/Headers/Bar/.
8415
+ auto Begin = llvm::sys::path::begin (NativeRelDir);
8416
+ auto End = llvm::sys::path::end (NativeRelDir);
8417
+
8418
+ llvm::sys::path::append (Dir, *Begin + " .framework" , " Headers" );
8419
+ llvm::sys::path::append (Dir, ++Begin, End);
8420
+ } else {
8421
+ llvm::sys::path::append (Dir, NativeRelDir);
8422
+ }
8423
+ }
8411
8424
8412
8425
std::error_code EC;
8413
8426
unsigned Count = 0 ;
@@ -8418,6 +8431,12 @@ void Sema::CodeCompleteIncludedFile(llvm::StringRef Dir, bool Angled) {
8418
8431
StringRef Filename = llvm::sys::path::filename (It->path ());
8419
8432
switch (It->type ()) {
8420
8433
case llvm::sys::fs::file_type::directory_file:
8434
+ // All entries in a framework directory must have a ".framework" suffix,
8435
+ // but the suffix does not appear in the source code's include/import.
8436
+ if (LookupType == DirectoryLookup::LT_Framework &&
8437
+ NativeRelDir.empty () && !Filename.consume_back (" .framework" ))
8438
+ break ;
8439
+
8421
8440
AddCompletion (Filename, /* IsDirectory=*/ true );
8422
8441
break ;
8423
8442
case llvm::sys::fs::file_type::regular_file:
@@ -8446,10 +8465,12 @@ void Sema::CodeCompleteIncludedFile(llvm::StringRef Dir, bool Angled) {
8446
8465
// header maps are not (currently) enumerable.
8447
8466
break ;
8448
8467
case DirectoryLookup::LT_NormalDir:
8449
- AddFilesFromIncludeDir (IncludeDir.getDir ()->getName (), IsSystem);
8468
+ AddFilesFromIncludeDir (IncludeDir.getDir ()->getName (), IsSystem,
8469
+ DirectoryLookup::LT_NormalDir);
8450
8470
break ;
8451
8471
case DirectoryLookup::LT_Framework:
8452
- AddFilesFromIncludeDir (IncludeDir.getFrameworkDir ()->getName (), IsSystem);
8472
+ AddFilesFromIncludeDir (IncludeDir.getFrameworkDir ()->getName (), IsSystem,
8473
+ DirectoryLookup::LT_Framework);
8453
8474
break ;
8454
8475
}
8455
8476
};
@@ -8463,7 +8484,8 @@ void Sema::CodeCompleteIncludedFile(llvm::StringRef Dir, bool Angled) {
8463
8484
// The current directory is on the include path for "quoted" includes.
8464
8485
auto *CurFile = PP.getCurrentFileLexer ()->getFileEntry ();
8465
8486
if (CurFile && CurFile->getDir ())
8466
- AddFilesFromIncludeDir (CurFile->getDir ()->getName (), false );
8487
+ AddFilesFromIncludeDir (CurFile->getDir ()->getName (), false ,
8488
+ DirectoryLookup::LT_NormalDir);
8467
8489
for (const auto &D : make_range (S.quoted_dir_begin (), S.quoted_dir_end ()))
8468
8490
AddFilesFromDirLookup (D, false );
8469
8491
}
0 commit comments