[clang-tools-extra] r337396 - [clangd] Also get scope for RK_pattern completion results.

Eric Liu via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 18 08:31:14 PDT 2018


Author: ioeric
Date: Wed Jul 18 08:31:14 2018
New Revision: 337396

URL: http://llvm.org/viewvc/llvm-project?rev=337396&view=rev
Log:
[clangd] Also get scope for RK_pattern completion results.

For exmaple, clas field candidates in constructor initializers can be
RK_Pattern, but they can still have scopes.

Modified:
    clang-tools-extra/trunk/clangd/CodeComplete.cpp
    clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=337396&r1=337395&r2=337396&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Wed Jul 18 08:31:14 2018
@@ -270,12 +270,14 @@ struct CodeCompletionBuilder {
     if (C.SemaResult) {
       Completion.Origin |= SymbolOrigin::AST;
       Completion.Name = llvm::StringRef(SemaCCS->getTypedText());
-      if (Completion.Scope.empty())
-        if (C.SemaResult->Kind == CodeCompletionResult::RK_Declaration)
+      if (Completion.Scope.empty()) {
+        if ((C.SemaResult->Kind == CodeCompletionResult::RK_Declaration) ||
+            (C.SemaResult->Kind == CodeCompletionResult::RK_Pattern))
           if (const auto *D = C.SemaResult->getDeclaration())
             if (const auto *ND = llvm::dyn_cast<NamedDecl>(D))
               Completion.Scope =
                   splitQualifiedName(printQualifiedName(*ND)).first;
+      }
       Completion.Kind =
           toCompletionItemKind(C.SemaResult->Kind, C.SemaResult->Declaration);
     }

Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=337396&r1=337395&r2=337396&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Wed Jul 18 08:31:14 2018
@@ -1309,6 +1309,18 @@ TEST(CompletionTest, IgnoreRecoveryResul
   EXPECT_THAT(Results.Completions, UnorderedElementsAre(Named("NotRecovered")));
 }
 
+TEST(CompletionTest, ScopeOfClassFieldInConstructorInitializer) {
+  auto Results = completions(
+      R"cpp(
+        namespace ns {
+          class X { public: X(); int x_; };
+          X::X() : x_^(0) {}
+        }
+      )cpp");
+  EXPECT_THAT(Results.Completions,
+              UnorderedElementsAre(AllOf(Scope("ns::X::"), Named("x_"))));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang




More information about the cfe-commits mailing list