]> granicus.if.org Git - clang/commitdiff
[CodeCompletion] Complete platform names in @available expressions
authorAlex Lorenz <arphaman@gmail.com>
Tue, 9 May 2017 16:05:04 +0000 (16:05 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Tue, 9 May 2017 16:05:04 +0000 (16:05 +0000)
rdar://32074504

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@302545 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/Sema.h
lib/Parse/ParseExpr.cpp
lib/Sema/SemaCodeComplete.cpp
test/Index/complete-available.m [new file with mode: 0644]

index b0cb34cf5653c762209ed678e06fd11e22846186..3a2195ba4d12c24a2c92eb13bd6807ff11e4c14e 100644 (file)
@@ -10009,6 +10009,7 @@ public:
                                              MacroInfo *MacroInfo,
                                              unsigned Argument);
   void CodeCompleteNaturalLanguage();
+  void CodeCompleteAvailabilityPlatformName();
   void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator,
                                    CodeCompletionTUInfo &CCTUInfo,
                   SmallVectorImpl<CodeCompletionResult> &Results);
index 77316b9ad125be69d91f77f97aa72ab0bd8db42f..38c1b2676dfd91cb4002c265dfef6f3e9f2e4d3d 100644 (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;
index cfac3f1dc1de9f1949f3a34ac0399e0fee968546..dba916e0b9917f081bb0c565f4ea04c63e695e91 100644 (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) {
diff --git a/test/Index/complete-available.m b/test/Index/complete-available.m
new file mode 100644 (file)
index 0000000..8267dbd
--- /dev/null
@@ -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)