[PATCH] D128821: [clangd][ObjC] Fix ObjC method definition completion
David Goldman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 29 07:06:55 PDT 2022
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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128821.440996.patch
Type: text/x-patch
Size: 2447 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220629/14c79111/attachment.bin>
More information about the cfe-commits
mailing list