Index: clangd/CodeComplete.cpp =================================================================== --- clangd/CodeComplete.cpp +++ clangd/CodeComplete.cpp @@ -625,13 +625,12 @@ 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_ExistingName: + case CodeCompletionContext::CCC_PotentiallyQualifiedExistingName: return true; - case CodeCompletionContext::CCC_Other: // Be conservative. case CodeCompletionContext::CCC_OtherWithMacros: case CodeCompletionContext::CCC_DotMemberAccess: case CodeCompletionContext::CCC_ArrowMemberAccess: @@ -640,13 +639,17 @@ 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: + case CodeCompletionContext::CCC_PotentiallyQualifiedNewName: return false; } llvm_unreachable("unknown code completion context"); Index: clangd/index/SymbolCollector.cpp =================================================================== --- clangd/index/SymbolCollector.cpp +++ clangd/index/SymbolCollector.cpp @@ -551,8 +551,8 @@ // 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, - *CompletionTUInfo, + *ASTCtx, *PP, CodeCompletionContext::CCC_ExistingName, + *CompletionAllocator, *CompletionTUInfo, /*IncludeBriefComments*/ false); std::string Signature; std::string SnippetSuffix; Index: unittests/clangd/CodeCompleteTests.cpp =================================================================== --- unittests/clangd/CodeCompleteTests.cpp +++ unittests/clangd/CodeCompleteTests.cpp @@ -2175,6 +2175,15 @@ 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::foo")}, Opts); + EXPECT_THAT(Results.Completions, UnorderedElementsAre()); +} } // namespace } // namespace clangd } // namespace clang