This is an archive of the discontinued LLVM Phabricator instance.

Support framework import/include auto-completion
ClosedPublic

Authored by dgoldman on Feb 11 2019, 9:19 AM.

Details

Reviewers
sammccall
Summary

Frameworks filesystem representations:

UIKit.framework/Headers/%header%

Framework import format:

#import <UIKit/%header%>

Thus the completion code must map the input format of <UIKit/> to
the path of UIKit.framework/Headers as well as strip the
".framework" suffix when auto-completing the framework name.

Diff Detail

Event Timeline

dgoldman created this revision.Feb 11 2019, 9:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 11 2019, 9:19 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
sammccall added inline comments.Feb 11 2019, 10:33 AM
lib/Sema/SemaCodeComplete.cpp
8375

nit: IsFramework, StripFrameworkSuffix etc

8375

probably clearer just to pass in the DirectoryLookup::LookupType_t, rather than another bool.

8377–8378

I don't think keeping the stripFrameworkSuffix state is worth scattering the reader's attention here.

I'd suggest instead:

if (!NativeRelDir.empty()) {
  if (LookupType == LT_Framework) {
    // In a framework directory, Foo/Bar/ is actually Foo.framework/Headers/Bar/.
    ...
  } else {
    append(Dir, NativeRelDir);
  }
}

or even pass Dir, NativeRelDir, and LookupType to a helper function to sort it out.

Below, you can just check NativeRelDir.empty() && type == Framework again...

If you do choose to keep it, please give it a descriptive name rather than an imperative one, e.g. ListingFrameworksDir

8377–8378

this needs some explanation (mostly the why, not the how)

8387

just append(Dir, *Begin + ".framework", "Headers") ?
append takes twines I think.

8389

why is the if/else needed? the code above should cover both cases, the last append is a no-op if ++begin == end.

8407

if a framework directory contains a subdirectory that does not end in ".framework", is it actually legal to include from it? Maybe we should be omitting it.

8408
if (should strip suffix)
  Filename.consume_back(".framework")

(no need for else)

8408

one-line comment should be enough to explain the intent here: // Entries in a framework directory have a .framework suffix, this does not appear in the source code

dgoldman updated this revision to Diff 186524.Feb 12 2019, 11:29 AM
dgoldman marked 9 inline comments as done.
  • Misc fixes

Code looks good apart from one case where we encounter Foo.framework/Subdir1/Subdir2.

Can you add a test to clang/test/CodeCompletion? included-files.cpp has the existing tests, not sure if you can add them there or it needs to be an obj-c file for framework includes.

lib/Sema/SemaCodeComplete.cpp
8404

nit: no {} needed for these one-line ifs

8404

this check appears to be incorrect, it'll fire even if NativeRelDir is nonempty (i.e. a we're inside a framework already.)
I think this can be combined with the one below it, see next comment.

8407

consume_back checks for the suffix, just if (NativeRelDir.empty() && !Filename.consume_back(".framework")) break; is enough

dgoldman updated this revision to Diff 186904.Feb 14 2019, 1:11 PM
  • Add test and fix subfolder bug
dgoldman marked 3 inline comments as done.Feb 14 2019, 1:13 PM

added test

sammccall accepted this revision.Feb 15 2019, 9:06 AM

Great, thank you! Want me to land this?

(You can certainly get your own commit access at this point if you like: https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access and point at a couple of your patches)

This revision is now accepted and ready to land.Feb 15 2019, 9:06 AM

Great, thank you! Want me to land this?

(You can certainly get your own commit access at this point if you like: https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access and point at a couple of your patches)

Sure, you can land this one, I''ll try to get commit access in the meantime.