[CodeCompletion] Complete platform names in @available expressions

rdar://32074504

llvm-svn: 302545
This commit is contained in:
Alex Lorenz 2017-05-09 16:05:04 +00:00
parent 3a363fff7e
commit f7f6f823a4
4 changed files with 43 additions and 0 deletions

View File

@ -10009,6 +10009,7 @@ public:
MacroInfo *MacroInfo,
unsigned Argument);
void CodeCompleteNaturalLanguage();
void CodeCompleteAvailabilityPlatformName();
void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator,
CodeCompletionTUInfo &CCTUInfo,
SmallVectorImpl<CodeCompletionResult> &Results);

View File

@ -2989,6 +2989,11 @@ Optional<AvailabilitySpec> Parser::ParseAvailabilitySpec() {
return AvailabilitySpec(ConsumeToken());
} else {
// Parse the platform name.
if (Tok.is(tok::code_completion)) {
Actions.CodeCompleteAvailabilityPlatformName();
cutOffParsing();
return None;
}
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_avail_query_expected_platform_name);
return None;

View File

@ -7811,6 +7811,23 @@ void Sema::CodeCompleteNaturalLanguage() {
nullptr, 0);
}
void Sema::CodeCompleteAvailabilityPlatformName() {
ResultBuilder Results(*this, CodeCompleter->getAllocator(),
CodeCompleter->getCodeCompletionTUInfo(),
CodeCompletionContext::CCC_Other);
Results.EnterNewScope();
static const char *Platforms[] = {"macOS", "iOS", "watchOS", "tvOS"};
for (const char *Platform : llvm::makeArrayRef(Platforms)) {
Results.AddResult(CodeCompletionResult(Platform));
Results.AddResult(CodeCompletionResult(Results.getAllocator().CopyString(
Twine(Platform) + "ApplicationExtension")));
}
Results.ExitScope();
HandleCodeCompleteResults(this, CodeCompleter,
CodeCompletionContext::CCC_Other, Results.data(),
Results.size());
}
void Sema::GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator,
CodeCompletionTUInfo &CCTUInfo,
SmallVectorImpl<CodeCompletionResult> &Results) {

View File

@ -0,0 +1,20 @@
/* The run lines are below, because this test is line- and
column-number sensitive. */
void atAvailable() {
if (@available(macOS 10.10, *)) {
}
if (__builtin_available(iOS 8, *)) {
}
}
// RUN: c-index-test -code-completion-at=%s:4:18 %s | FileCheck -check-prefix=CHECK %s
// RUN: c-index-test -code-completion-at=%s:7:27 %s | FileCheck -check-prefix=CHECK %s
// CHECK: {TypedText iOS} (40)
// CHECK: {TypedText iOSApplicationExtension} (40)
// CHECK: {TypedText macOS} (40)
// CHECK: {TypedText macOSApplicationExtension} (40)
// CHECK: {TypedText tvOS} (40)
// CHECK: {TypedText tvOSApplicationExtension} (40)
// CHECK: {TypedText watchOS} (40)
// CHECK: {TypedText watchOSApplicationExtension} (40)