diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -851,19 +851,21 @@ // Returns the filtering/sorting name for Result, which must be from Results. // Returned string is owned by this recorder (or the AST). llvm::StringRef getName(const CodeCompletionResult &Result) { + CodeCompletionString *CCS = nullptr; switch (Result.Kind) { case CodeCompletionResult::RK_Declaration: if (auto *ID = Result.Declaration->getIdentifier()) return ID->getName(); + CCS = codeCompletionString(Result); break; case CodeCompletionResult::RK_Keyword: return Result.Keyword; case CodeCompletionResult::RK_Macro: return Result.Macro->getName(); case CodeCompletionResult::RK_Pattern: - return Result.Pattern->getTypedText(); + CCS = Result.Pattern; + break; } - auto *CCS = codeCompletionString(Result); const CodeCompletionString::Chunk *OnlyText = nullptr; for (auto &C : *CCS) { if (C.Kind != CodeCompletionString::CK_TypedText) diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp --- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp @@ -3131,6 +3131,26 @@ EXPECT_THAT(C, ElementsAre(signature("(char)c secondArgument:(id)object"))); } +TEST(CompletionTest, ObjectiveCMethodDeclarationFilterOnEntireSelector) { + auto Results = completions(R"objc( + @interface Foo + - (int)valueForCharacter:(char)c secondArgument:(id)object; + @end + @implementation Foo + secondArg^ + @end + )objc", + /*IndexSymbols=*/{}, + /*Opts=*/{}, "Foo.m"); + + auto C = Results.Completions; + EXPECT_THAT(C, ElementsAre(named("valueForCharacter:"))); + EXPECT_THAT(C, ElementsAre(filterText("valueForCharacter:secondArgument:"))); + EXPECT_THAT(C, ElementsAre(kind(CompletionItemKind::Method))); + EXPECT_THAT(C, ElementsAre(qualifier("- (int)"))); + EXPECT_THAT(C, ElementsAre(signature("(char)c secondArgument:(id)object"))); +} + TEST(CompletionTest, ObjectiveCMethodDeclarationPrefixTyped) { auto Results = completions(R"objc( @interface Foo