From: Kadir Cetinkaya Date: Wed, 24 Oct 2018 15:24:29 +0000 (+0000) Subject: [clangd] Do not query index for new name completions. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b915790385a988f941038aa09a5c604770dab981;p=platform%2Fupstream%2Fllvm.git [clangd] Do not query index for new name completions. Reviewers: sammccall Reviewed By: sammccall Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D53192 llvm-svn: 345153 --- diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp index 819cd6b..27f57f2 100644 --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -625,13 +625,12 @@ bool contextAllowsIndex(enum CodeCompletionContext::Kind K) { case CodeCompletionContext::CCC_ObjCProtocolName: case CodeCompletionContext::CCC_Namespace: case CodeCompletionContext::CCC_Type: - case CodeCompletionContext::CCC_Name: // FIXME: why does ns::^ give this? - case CodeCompletionContext::CCC_PotentiallyQualifiedName: case CodeCompletionContext::CCC_ParenthesizedExpression: case CodeCompletionContext::CCC_ObjCInterfaceName: case CodeCompletionContext::CCC_ObjCCategoryName: + case CodeCompletionContext::CCC_Symbol: + case CodeCompletionContext::CCC_SymbolOrNewName: return true; - case CodeCompletionContext::CCC_Other: // Be conservative. case CodeCompletionContext::CCC_OtherWithMacros: case CodeCompletionContext::CCC_DotMemberAccess: case CodeCompletionContext::CCC_ArrowMemberAccess: @@ -640,13 +639,16 @@ bool contextAllowsIndex(enum CodeCompletionContext::Kind K) { case CodeCompletionContext::CCC_MacroNameUse: case CodeCompletionContext::CCC_PreprocessorExpression: case CodeCompletionContext::CCC_PreprocessorDirective: - case CodeCompletionContext::CCC_NaturalLanguage: case CodeCompletionContext::CCC_SelectorName: case CodeCompletionContext::CCC_TypeQualifiers: case CodeCompletionContext::CCC_ObjCInstanceMessage: case CodeCompletionContext::CCC_ObjCClassMessage: case CodeCompletionContext::CCC_IncludedFile: + // FIXME: Provide identifier based completions for the following contexts: + case CodeCompletionContext::CCC_Other: // Be conservative. + case CodeCompletionContext::CCC_NaturalLanguage: case CodeCompletionContext::CCC_Recovery: + case CodeCompletionContext::CCC_NewName: return false; } llvm_unreachable("unknown code completion context"); diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp index 8fd0083..c0784a4 100644 --- a/clang-tools-extra/clangd/index/SymbolCollector.cpp +++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -551,7 +551,7 @@ const Symbol *SymbolCollector::addDeclaration(const NamedDecl &ND, // We use the primary template, as clang does during code completion. CodeCompletionResult SymbolCompletion(&getTemplateOrThis(ND), 0); const auto *CCS = SymbolCompletion.CreateCodeCompletionString( - *ASTCtx, *PP, CodeCompletionContext::CCC_Name, *CompletionAllocator, + *ASTCtx, *PP, CodeCompletionContext::CCC_Symbol, *CompletionAllocator, *CompletionTUInfo, /*IncludeBriefComments*/ false); std::string Signature; diff --git a/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp b/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp index 7e93d8c..3e60b62 100644 --- a/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp +++ b/clang-tools-extra/unittests/clangd/CodeCompleteTests.cpp @@ -2178,6 +2178,15 @@ TEST(CompletionTest, NoQualifierIfShadowed) { AllOf(Qualifier("nx::"), Named("Clangd2")))); } +TEST(CompletionTest, NoCompletionsForNewNames) { + clangd::CodeCompleteOptions Opts; + Opts.AllScopes = true; + auto Results = completions(R"cpp( + void f() { int n^ } + )cpp", + {cls("naber"), cls("nx::naber")}, Opts); + EXPECT_THAT(Results.Completions, UnorderedElementsAre()); +} } // namespace } // namespace clangd } // namespace clang