// Fill in Result.IdentifierInfo and update the token kind,
// looking up the identifier in the identifier table.
IdentifierInfo *II = PP->LookUpIdentifierInfo(Result);
+ // Note that we have to call PP->LookUpIdentifierInfo() even for code
+ // completion, it writes IdentifierInfo into Result, and callers rely on it.
- // Finally, now that we know we have an identifier, pass this off to the
- // preprocessor, which may macro expand it or something.
- if (II->isHandleIdentifierCase())
- return PP->HandleIdentifier(Result);
-
- if (II->getTokenID() == tok::identifier && isCodeCompletionPoint(CurPtr)
- && II->getPPKeywordID() == tok::pp_not_keyword
- && II->getObjCKeywordID() == tok::objc_not_keyword) {
+ // If the completion point is at the end of an identifier, we want to treat
+ // the identifier as incomplete even if it resolves to a macro or a keyword.
+ // This allows e.g. 'class^' to complete to 'classifier'.
+ if (isCodeCompletionPoint(CurPtr)) {
// Return the code-completion token.
Result.setKind(tok::code_completion);
cutOffLexing();
return true;
}
+
+ // Finally, now that we know we have an identifier, pass this off to the
+ // preprocessor, which may macro expand it or something.
+ if (II->isHandleIdentifierCase())
+ return PP->HandleIdentifier(Result);
+
return true;
}
--- /dev/null
+#define FUNC(X) X
+#define FUNCTOR
+using FUNCTION = int();
+// We should get all three completions when the cursor is at the beginning,
+// middle, or end.
+FUNC(int) a = 10;
+// ^FUNC(int)
+// RUN: %clang_cc1 -code-completion-at=%s:6:1 -code-completion-macros %s | FileCheck %s
+// FU^NC(int)
+// RUN: %clang_cc1 -code-completion-at=%s:6:3 -code-completion-macros %s | FileCheck %s
+// FUNC^(int)
+// RUN: %clang_cc1 -code-completion-at=%s:6:5 -code-completion-macros %s | FileCheck %s
+
+// CHECK: COMPLETION: FUNC : FUNC(<#X#>)
+// CHECK: COMPLETION: FUNCTION : FUNCTION
+// CHECK: COMPLETION: FUNCTOR : FUNCTOR
\ No newline at end of file
--- /dev/null
+class classifier {};
+// We should get all three completions when the cursor is at the beginning,
+// middle, or end.
+class cls
+// ^class cls
+// RUN: %clang_cc1 -code-completion-at=%s:4:1 %s | FileCheck --check-prefix=CHECK-CLS %s
+// cl^ass cls
+// RUN: %clang_cc1 -code-completion-at=%s:4:3 %s | FileCheck --check-prefix=CHECK-CLS %s
+// class^ cls
+// RUN: %clang_cc1 -code-completion-at=%s:4:6 %s | FileCheck --check-prefix=CHECK-CLS %s
+
+// CHECK-CLS: COMPLETION: class{{$}}
+// CHECK-CLS: COMPLETION: classifier : classifier
+
+// class ^cls
+// RUN: %clang_cc1 -code-completion-at=%s:4:7 %s | FileCheck --check-prefix=CHECK-NO-CLS %s
+// class c^ls
+// RUN: %clang_cc1 -code-completion-at=%s:4:8 %s | FileCheck --check-prefix=CHECK-NO-CLS %s
+// CHECK-NO-CLS-NOT: COMPLETION: class{{$}}
+// CHECK-NO-CLS: COMPLETION: classifier : classifier
void test(struct Point *p) {
// RUN: %clang_cc1 -include %S/Inputs/macros.h -fsyntax-only -code-completion-macros -code-completion-at=%s:12:14 %s -o - | FileCheck -check-prefix=CC1 %s
switch (p->IDENTITY(color)) {
- // RUN: %clang_cc1 -include %S/Inputs/macros.h -fsyntax-only -code-completion-macros -code-completion-at=%s:14:9 %s -o - | FileCheck -check-prefix=CC2 %s
+ // RUN: %clang_cc1 -include %S/Inputs/macros.h -fsyntax-only -code-completion-macros -code-completion-at=%s:14:10 %s -o - | FileCheck -check-prefix=CC2 %s
case
}
- // RUN: %clang_cc1 -include %S/Inputs/macros.h -fsyntax-only -code-completion-macros -code-completion-at=%s:17:7 %s -o - | FileCheck -check-prefix=CC3 %s
+ // RUN: %clang_cc1 -include %S/Inputs/macros.h -fsyntax-only -code-completion-macros -code-completion-at=%s:17:8 %s -o - | FileCheck -check-prefix=CC3 %s
#ifdef Q
#endif
// Run the same tests, this time with macros loaded from the PCH file.
// RUN: %clang_cc1 -emit-pch -o %t %S/Inputs/macros.h
// RUN: %clang_cc1 -include-pch %t -fsyntax-only -code-completion-macros -code-completion-at=%s:12:14 %s -o - | FileCheck -check-prefix=CC1 %s
- // RUN: %clang_cc1 -include-pch %t -fsyntax-only -code-completion-macros -code-completion-at=%s:14:9 %s -o - | FileCheck -check-prefix=CC2 %s
- // RUN: %clang_cc1 -include-pch %t -fsyntax-only -code-completion-macros -code-completion-at=%s:17:7 %s -o - | FileCheck -check-prefix=CC3 %s
+ // RUN: %clang_cc1 -include-pch %t -fsyntax-only -code-completion-macros -code-completion-at=%s:14:10 %s -o - | FileCheck -check-prefix=CC2 %s
+ // RUN: %clang_cc1 -include-pch %t -fsyntax-only -code-completion-macros -code-completion-at=%s:17:8 %s -o - | FileCheck -check-prefix=CC3 %s
// CC1: color
// CC1: x
namespace I5 { }
namespace I1 { }
- namespace
- // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:12 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+ namespace
+ // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:13 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
// CHECK-CC1: I1
// CHECK-CC1-NEXT: I5
void f() {
typedef float Float;
- operator
- // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:11 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+ operator
+ // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:12 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
// CHECK-CC1: +
// CHECK-CC1: Float
// CHECK-CC1: Integer
void test() {
enum X { x };
- enum
- // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:9:7 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+ enum
+ // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:9:8 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
// CHECK-CC1: X
// CHECK-CC1: Y
class Y;
void test() {
- class
- // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:17:10 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+ class
+ // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:17:11 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
// FIXME: the redundant Y is really annoying... it needs qualification to
// actually be useful. Here, it just looks redundant :(
// CHECK-CC1: A
namespace I1 { }
void foo() {
- using namespace
- // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:14:20 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+ using namespace
+ // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:14:21 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
// CHECK-CC1: I1
// CHECK-CC1: I4
// CHECK-CC1: I5
void foo() {
int N3;
- using
- // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:16:10 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+ using
+ // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:16:11 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
// CHECK-CC1: I1
// CHECK-CC1: I4
// CHECK-CC1: I5
(type)f;
}
-// RUN: c-index-test -code-completion-at=%s:7:9 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s
-// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:7:9 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s
+// RUN: c-index-test -code-completion-at=%s:7:10 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s
+// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:7:10 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s
// CHECK-CC1: NotImplemented:{TypedText __PRETTY_FUNCTION__} (65)
// CHECK-CC1: macro definition:{TypedText __VERSION__} (70)
// CHECK-CC1: FunctionDecl:{ResultType int}{TypedText f}{LeftParen (}{Placeholder int}{RightParen )} (12) (unavailable)
// CHECK-CC1-NOT: NotImplemented:{TypedText float} (65)
// CHECK-CC1: ParmDecl:{ResultType int}{TypedText j} (8)
// CHECK-CC1: NotImplemented:{ResultType size_t}{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )} (40)
-// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:7:9 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s
+// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:7:10 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC1 %s
// RUN: c-index-test -code-completion-at=%s:7:14 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC3 %s
// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:7:14 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC3 %s
// CHECK-CC3: macro definition:{TypedText __VERSION__} (70)
FOO(in,t) value;
-// RUN: c-index-test -code-completion-at=%s:4:2 %s | FileCheck -check-prefix=CHECK-CC1 %s
+// RUN: c-index-test -code-completion-at=%s:4:3 %s | FileCheck -check-prefix=CHECK-CC1 %s
// CHECK-CC1: NotImplemented:{TypedText define}{HorizontalSpace }{Placeholder macro} (40)
// CHECK-CC1-NEXT: NotImplemented:{TypedText define}{HorizontalSpace }{Placeholder macro}{LeftParen (}{Placeholder args}{RightParen )} (40)
// CHECK-CC1-NEXT: NotImplemented:{TypedText error}{HorizontalSpace }{Placeholder message} (40)
// RUN: c-index-test -code-completion-at=%s:9:8 %s | FileCheck -check-prefix=CHECK-CC3 %s
// CHECK-CC3: macro definition:{TypedText BAR} (40)
// CHECK-CC3: macro definition:{TypedText FOO} (40)
-// RUN: c-index-test -code-completion-at=%s:11:12 %s | FileCheck -check-prefix=CHECK-CC3 %s
// RUN: c-index-test -code-completion-at=%s:11:13 %s | FileCheck -check-prefix=CHECK-CC3 %s
+// RUN: c-index-test -code-completion-at=%s:11:14 %s | FileCheck -check-prefix=CHECK-CC3 %s
// RUN: c-index-test -code-completion-at=%s:11:5 %s | FileCheck -check-prefix=CHECK-CC4 %s
// CHECK-CC4: macro definition:{TypedText BAR} (70)
// CHECK-CC4: macro definition:{TypedText FOO}{LeftParen (}{Placeholder a}{Comma , }{Placeholder b}{RightParen )} (70)