From: Alex Lorenz Date: Tue, 9 May 2017 16:05:04 +0000 (+0000) Subject: [CodeCompletion] Complete platform names in @available expressions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=89098a4dac7ca3aaa96f717fec66a46c432dcec5;p=clang [CodeCompletion] Complete platform names in @available expressions rdar://32074504 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@302545 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index b0cb34cf56..3a2195ba4d 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -10009,6 +10009,7 @@ public: MacroInfo *MacroInfo, unsigned Argument); void CodeCompleteNaturalLanguage(); + void CodeCompleteAvailabilityPlatformName(); void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, SmallVectorImpl &Results); diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 77316b9ad1..38c1b2676d 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -2989,6 +2989,11 @@ Optional 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; diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index cfac3f1dc1..dba916e0b9 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -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 &Results) { diff --git a/test/Index/complete-available.m b/test/Index/complete-available.m new file mode 100644 index 0000000000..8267dbdddc --- /dev/null +++ b/test/Index/complete-available.m @@ -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)