dgoldman created this revision. dgoldman added a reviewer: sammccall. Herald added subscribers: usaxena95, kadircet, arphaman. Herald added a project: All. dgoldman requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang-tools-extra.
D124637 <https://reviews.llvm.org/D124637> improved filtering of method expressions, but not method definitions. With this change, clangd will now filter ObjC method definition completions based on their entire selector instead of only the first selector fragment. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D128821 Files: clang-tools-extra/clangd/CodeComplete.cpp clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ 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 Index: clang-tools-extra/clangd/CodeComplete.cpp =================================================================== --- clang-tools-extra/clangd/CodeComplete.cpp +++ 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)
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp +++ 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 Index: clang-tools-extra/clangd/CodeComplete.cpp =================================================================== --- clang-tools-extra/clangd/CodeComplete.cpp +++ 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)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits