[PATCH] D81263: [Sema][CodeComplete][ObjC] Don't include arrow/dot fixits
David Goldman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 5 08:52:30 PDT 2020
dgoldman updated this revision to Diff 268818.
dgoldman added a comment.
- Fix broken diff base (due to lint fixes maybe?)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D81263/new/
https://reviews.llvm.org/D81263
Files:
clang/lib/Sema/SemaCodeComplete.cpp
clang/test/CodeCompletion/objc-member-access.m
Index: clang/test/CodeCompletion/objc-member-access.m
===================================================================
--- /dev/null
+++ clang/test/CodeCompletion/objc-member-access.m
@@ -0,0 +1,22 @@
+// Note: the run lines follow their respective tests, since line/column
+// matter in this test.
+
+ at interface TypeWithPropertiesBackedByIvars {
+ int _bar;
+ int _foo;
+}
+ at property(nonatomic) int foo;
+ at property(nonatomic) int bar;
+ at end
+
+int getFoo(id object) {
+ TypeWithPropertiesBackedByIvars *model = (TypeWithPropertiesBackedByIvars *)object;
+ int foo = model.;
+ return foo;
+}
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:14:19 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+// CHECK-CC1-NOT: [#int#]_bar
+// CHECK-CC1-NOT: [#int#]_foo
+// CHECK-CC1: [#int#]bar
+// CHECK-CC1: [#int#]foo
Index: clang/lib/Sema/SemaCodeComplete.cpp
===================================================================
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -5150,7 +5150,7 @@
CodeCompleter->getCodeCompletionTUInfo(), CCContext,
&ResultBuilder::IsMember);
- auto DoCompletion = [&](Expr *Base, bool IsArrow,
+ auto DoCompletion = [&](Expr *Base, bool IsArrow, bool IncludeObjC,
Optional<FixItHint> AccessOpFixIt) -> bool {
if (!Base)
return false;
@@ -5196,6 +5196,9 @@
}
} else if (!IsArrow && BaseType->isObjCObjectPointerType()) {
// Objective-C property reference.
+ if (!IncludeObjC) {
+ return false;
+ }
AddedPropertiesSet AddedProperties;
if (const ObjCObjectPointerType *ObjCPtr =
@@ -5216,6 +5219,9 @@
} else if ((IsArrow && BaseType->isObjCObjectPointerType()) ||
(!IsArrow && BaseType->isObjCObjectType())) {
// Objective-C instance variable access.
+ if (!IncludeObjC) {
+ return false;
+ }
ObjCInterfaceDecl *Class = nullptr;
if (const ObjCObjectPointerType *ObjCPtr =
BaseType->getAs<ObjCObjectPointerType>())
@@ -5239,12 +5245,18 @@
Results.EnterNewScope();
- bool CompletionSucceded = DoCompletion(Base, IsArrow, None);
+ bool CompletionSucceded =
+ DoCompletion(Base, IsArrow, /*IncludeObjC=*/true, None);
+
+ // Fixits are only included for C++. We avoid this for Objective-C properties
+ // and ivars since most properties are backed by an ivar; otherwise we would
+ // recommend an ivar fixit when code-completing a property. Another possible
+ // solution would be to de-duplicate the ivar/property mixing.
if (CodeCompleter->includeFixIts()) {
const CharSourceRange OpRange =
CharSourceRange::getTokenRange(OpLoc, OpLoc);
CompletionSucceded |= DoCompletion(
- OtherOpBase, !IsArrow,
+ OtherOpBase, !IsArrow, /*IncludeObjC=*/false,
FixItHint::CreateReplacement(OpRange, IsArrow ? "." : "->"));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81263.268818.patch
Type: text/x-patch
Size: 2997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200605/67a6dfea/attachment.bin>
More information about the cfe-commits
mailing list